From 766a34a8db2c9b2a6ea3a85a8061f65ae5a1726c Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sun, 23 Aug 2015 09:29:26 +0200 Subject: [PATCH] fix flac mime types in rclaudio + small changes for experimenting with embedding an interpreter in recollindex --- src/filters/rclaudio | 18 ++++++++++++++---- src/filters/rclexecm.py | 21 +++++++++++++++++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/filters/rclaudio b/src/filters/rclaudio index 51d3b12d..d717adc1 100755 --- a/src/filters/rclaudio +++ b/src/filters/rclaudio @@ -52,7 +52,9 @@ class AudioTagExtractor: tags = MP3(filename, ID3=EasyID3) elif mimetype == "application/ogg": tags = OggVorbis(filename) - elif mimetype == "application/x-flac": + elif mimetype == "application/x-flac" or \ + mimetype == "audio/x-flac" or \ + mimetype == "audio/flac": tags = FLAC(filename) else: raise Exception, "Bad mime type %s" % mimetype @@ -98,6 +100,14 @@ class AudioTagExtractor: self.currentindex += 1 return ret -proto = rclexecm.RclExecM() -extract = AudioTagExtractor(proto) -rclexecm.main(proto, extract) +def makeObject(): + print("makeObject"); + proto = rclexecm.RclExecM() + print("makeObject: rclexecm ok"); + extract = AudioTagExtractor(proto) + return 17 + +if __name__ == '__main__': + proto = rclexecm.RclExecM() + extract = AudioTagExtractor(proto) + rclexecm.main(proto, extract) diff --git a/src/filters/rclexecm.py b/src/filters/rclexecm.py index eadf19cd..24316f7f 100644 --- a/src/filters/rclexecm.py +++ b/src/filters/rclexecm.py @@ -15,7 +15,10 @@ class RclExecM: fileerror = 2 def __init__(self): - self.myname = os.path.basename(sys.argv[0]) + try: + self.myname = os.path.basename(sys.argv[0]) + except: + self.myname = "???" self.mimetype = "" if os.environ.get("RECOLL_FILTER_MAXMEMBERKB"): @@ -165,6 +168,7 @@ class RclExecM: self.processmessage(processor, params) + # Common main routine for all python execm filters: either run the # normal protocol engine or a local loop to test without recollindex def main(proto, extract): @@ -173,7 +177,20 @@ def main(proto, extract): else: # Got a file name parameter: TESTING without an execm parent # Loop on all entries or get specific ipath - params = {'filename:':sys.argv[1]} + def mimetype_with_file(f): + cmd = 'file -i "' + f + '"' + fileout = os.popen(cmd).read() + lst = fileout.split(':') + mimetype = lst[len(lst)-1].strip() + lst = mimetype.split(';') + return lst[0].strip() + def mimetype_with_xdg(f): + cmd = 'xdg-mime query filetype "' + f + '"' + return os.popen(cmd).read().strip() + params = {'filename:': sys.argv[1]} + # Some filters (e.g. rclaudio) need/get a MIME type from the indexer + mimetype = mimetype_with_xdg(sys.argv[1]) + params['mimetype:'] = mimetype if not extract.openfile(params): print "Open error" sys.exit(1)