pandora_client_eightfiftyeight/mosireen.py

92 lines
3.2 KiB
Python
Raw Normal View History

2013-04-24 19:42:47 +02:00
'''
mosireen.py - pandora_client plugin
custom parse_path for pandora_client to parse musereen archive paths in the form
2017-06-05 12:10:29 +02:00
YYYY/MM_YYYY/DD_MM_YYYY/Location 1/Location 2/Event/Cinematographer/Topic 2(optional)/MVI_2036.MOV
2013-04-24 19:42:47 +02:00
'''
import re
2013-04-25 00:53:53 +02:00
import ox
2016-11-05 15:55:06 +01:00
import os
2013-04-24 19:42:47 +02:00
2017-06-05 12:10:29 +02:00
sync_extensions = ['.nef', '.cr2', '.pef']
2013-04-24 19:42:47 +02:00
def example_path(client):
2017-06-05 12:10:29 +02:00
return '\t' + 'YYYY/MM_YYYY/DD_MM_YYYY/Location 1/Location 2/Event/Shooter/Topic 2(optional)/MVI_2036.MOV'
2013-04-24 19:42:47 +02:00
2016-11-05 15:55:06 +01:00
def parse_path(client, path, context):
2013-04-24 19:42:47 +02:00
'''
args:
client - Client instance
path - path without volume prefix
return:
return None if file is ignored, dict with parsed item information otherwise
'''
2016-11-05 15:55:06 +01:00
m = re.compile('^(\d{4})/(\d{2}|NA)_(\d{4})/(?P<day>\d+|NA)_(?P<month>\d+|NA)_(?P<year>\d{4})((-(?P<tilday>\d+|NA)_(?P<tilmonth>\d+|NA)_(?P<tilyear>\d{4}))?)/(?P<location1>.+?)/(?P<location2>.+?)/(?P<subject1>.+?)/(?P<shooter>.+?)/((?P<subject2>.+?)/|).*').match(path)
2013-04-24 19:42:47 +02:00
if not m:
return None
2013-04-25 00:53:53 +02:00
info = m.groupdict()
date = '%s-%s-%s' % (info['year'], info['month'], info['day'])
2016-11-05 15:55:06 +01:00
if info['tilday']:
2017-06-05 12:10:29 +02:00
date = '%s-%s-%s - %s-%s-%s' % (info['year'], info['month'], info['day'], info['tilyear'], info['tilmonth'], info['tilday'])
2013-04-25 00:53:53 +02:00
for key in info:
if info[key]:
info[key] = info[key].replace('_', ' ')
2016-11-05 15:55:06 +01:00
topic = info['subject1'].split(",")
2013-04-25 00:53:53 +02:00
if info['subject2']:
2017-06-05 12:10:29 +02:00
topic += info['subject2'].split(",")
2013-04-25 00:53:53 +02:00
title = "%s, %s (%s)" % (info['subject1'], info['subject2'], date)
else:
title = "%s (%s)" % (info['subject1'], date)
2017-06-05 12:10:29 +02:00
while date.endswith('-NA'):
date = date[:-3]
title = "%s %s at %s, %s" % (title, info['shooter'], info['location2'], info['location1'])
title = title.replace(' ', ' ').strip()
title = title.replace(' ', ' ').strip()
topic = [t.strip() for t in topic]
shooter = [s.strip() for s in info['shooter'].split(',')]
location = '%s, %s' % (info['location2'], info['location1'])
location = location.strip()
2013-04-25 00:53:53 +02:00
r = {
2017-06-05 12:10:29 +02:00
'cinematographer': shooter,
2013-04-24 19:42:47 +02:00
'date': date,
2017-06-05 12:10:29 +02:00
'location': location,
2013-04-25 00:53:53 +02:00
'title': title,
'topic': topic
2013-04-24 19:42:47 +02:00
}
2013-04-25 00:53:53 +02:00
_info = ox.movie.parse_path(path)
for key in ('extension', 'type'):
r[key] = _info[key]
return r
2013-04-24 19:42:47 +02:00
2016-11-05 15:55:06 +01:00
def ignore_file(client, path):
'''
return True if file should not even be considered.
i.e. to filter out .DS_Store, empty files
'''
filename = os.path.basename(path)
if filename.startswith('._') \
2017-06-05 12:10:29 +02:00
or filename in (
'.DS_Store', 'Thumbs.db',
'CINDEX.TMP', 'THUMB.TDT', 'THUMB.TID'
) \
2016-11-05 15:55:06 +01:00
or filename.endswith('~') \
2017-06-05 12:10:29 +02:00
or 'Autosave Vault' in path \
or 'CLIPINF/' in path \
or 'Final Cut Pro Thumbnail Data' in path \
or os.path.splitext(filename.lower())[-1] in (
'.thm', '.rtf', '.sfk', '.fcp', '.xmp', '.prproj',
'.ctg', '.cpi', '.bdm', '.mpl', '.html', '.txt',
'.doc', '.xml', '.psd', '.pds',
) \
2016-11-05 15:55:06 +01:00
or not os.path.exists(path) \
or os.stat(path).st_size == 0:
return True
return False