pdf plugin

This commit is contained in:
randogoth 2023-06-09 13:01:47 +03:00
parent 90f3198dac
commit 473094bda9
5 changed files with 32 additions and 3 deletions

View file

@ -2,5 +2,4 @@
tags:
- frrr
---
+ plugin for xattr
+ plugin for pdf
+ plugin for xattr

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, hashdoubleslash, id3, office
from plugins import frontmatter, hashdoubleslash, id3, office, pdf
def mktable(query: str, index: dict, filter=None):
console = Console()
@ -98,6 +98,7 @@ def main():
hashdoubleslash.reader(o)
id3.reader(o)
office.reader(o)
pdf.reader(o)
orvani.PLUGINS = args.no_plugins

View file

@ -112,6 +112,7 @@ class OrvaniTag:
if self.CTX[context_key] != None:
context.update( { context_key : []})
for arg in argv:
arg.replace(',', '')
for context_key in self.CTX.keys():
if str(arg)[0] in self.CTX.values():
# Schema with prefix

28
orvani/plugins/pdf.py Normal file
View file

@ -0,0 +1,28 @@
import re
import shutil
from pathlib import Path
from pdfrw import PdfReader, PdfWriter
NAME = 'pdf'
TYPES = ['.pdf']
REGEX = r'\s*([@+]\w+|#\w+)'
def reader(o):
if 'plugins' in o.config:
if NAME not in o.config['plugins']:
return
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:
pdf = PdfReader(o.path)
if pdf.Info.Keywords:
tags = re.findall(REGEX, pdf.Info.Keywords.strip())
note = re.sub(REGEX, '', pdf.Info.Keywords.strip()).replace('(', '').replace(',', '').replace(')', '').strip()
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)