id3 plugin & configs

This commit is contained in:
randogoth 2023-06-08 14:34:56 +03:00
parent 51dd5e5337
commit fc7a00ca66
7 changed files with 70 additions and 4 deletions

View file

@ -5,7 +5,7 @@ from pathlib import Path
from rich.console import Console
from rich.table import Table
from orvani import OrvaniTag, CONTEXT_FILE, CACHE_FILE, CONTEXTS
from plugins import frontmatter, hashslashslash
from plugins import frontmatter, hashdoubleslash, id3
def mktable(query: str, index: dict):
console = Console()
@ -86,7 +86,8 @@ def main():
@orvani.metareader
def reader(o):
frontmatter.reader(o)
hashslashslash.reader(o)
hashdoubleslash.reader(o)
id3.reader(o)
# orvani.metadata()

View file

@ -393,6 +393,7 @@ class OrvaniTag:
def metadata(self, filename: str):
obj = {
'path' : filename,
'config' : self.CONFIG,
'index' : self.INDEX,
'schema' : self.CTX,
'update' : self.__updateindex,

View file

@ -1,9 +1,16 @@
import frontmatter
from pathlib import Path
NAME = 'frontmatter'
TYPES = ['.md', '.txt', '.markdown', '.rst']
def reader(o):
file = Path(o.path)
if file.suffix in ['.md', '.txt', '.markdown', '.rst']:
suffixes = TYPES
if NAME in o.config:
if 'types' in o.config[NAME]:
suffixes = o.config[NAME]['types']
if file.suffix in suffixes:
with open(file, 'r') as data:
y = frontmatter.load(data)
if y.metadata:

View file

@ -4,11 +4,17 @@
import re
from pathlib import Path
NAME = 'hash//'
TYPES = ['.md', '.txt', '.markdown', '.rst']
REGEX = r'\s*([@+]\w+|#\w+(?<!#//))'
def reader(o):
file = Path(o.path)
if file.suffix in ['.md', '.txt', '.py']:
suffixes = TYPES
if NAME in o.config:
if 'types' in o.config[NAME]:
suffixes = o.config[NAME]['types']
if file.suffix in suffixes:
with file.open() as data:
for line_num, line in enumerate(data, start=1):
if line_num > 5:

40
orvani/plugins/id3.py Normal file
View file

@ -0,0 +1,40 @@
import re
from pathlib import Path
import taglib
NAME = 'id3'
TYPES = ['.mp3', '.wav', '.flac', '.ogg']
REGEX = r'\s*([@+]\w+|#\w+)'
def reader(o):
file = Path(o.path)
suffixes = TYPES
if NAME in o.config:
if 'types' in o.config[NAME]:
suffixes = o.config[NAME]['types']
if file.suffix in suffixes:
with taglib.File(o.path, save_on_exit=False) as song:
metadata = song.tags
id3map = {}
if 'id3' in o.config:
if 'map' in o.config['id3']:
id3map = o.config['id3']['map'].copy()
for context_key in id3map:
if context_key not in o.schema.keys():
del id3map[context_key]
else:
ctag = str(id3map[context_key]).upper()
if ctag in metadata:
id3map[context_key] = metadata[ctag]
if id3map.keys():
for context_key in id3map.keys():
o.update(o.path, id3map, context_key)
if 'COMMENT' in metadata:
comment = metadata['COMMENT']
tags = re.findall(REGEX, comment[0].strip())
note = re.sub(REGEX, '', comment[0].strip()).lstrip()
argv = ' '.join(tags).split(' ') + [note]
argv = [x for x in argv if x != '']
context = o.context(argv)
for context_key in context.keys():
o.update(o.path, context, context_key)