2013-04-24 17:42:47 +00:00
|
|
|
'''
|
|
|
|
mosireen.py - pandora_client plugin
|
|
|
|
|
|
|
|
custom parse_path for pandora_client to parse musereen archive paths in the form
|
|
|
|
|
2017-06-08 11:58:03 +00:00
|
|
|
YYYY/MM_YYYY/DD_MM_YYYY/Location 1/Location 2/Event/Shooter/Topic 2(optional)/MVI_2036.MOV
|
2013-04-24 17:42:47 +00:00
|
|
|
|
|
|
|
'''
|
|
|
|
import re
|
2013-04-24 22:53:53 +00:00
|
|
|
import ox
|
2016-11-05 14:55:06 +00:00
|
|
|
import os
|
2013-04-24 17:42:47 +00:00
|
|
|
|
2017-06-05 10:10:29 +00:00
|
|
|
sync_extensions = ['.nef', '.cr2', '.pef']
|
|
|
|
|
2013-04-24 17:42:47 +00:00
|
|
|
def example_path(client):
|
2017-06-05 10:10:29 +00:00
|
|
|
return '\t' + 'YYYY/MM_YYYY/DD_MM_YYYY/Location 1/Location 2/Event/Shooter/Topic 2(optional)/MVI_2036.MOV'
|
2013-04-24 17:42:47 +00:00
|
|
|
|
2016-11-05 14:55:06 +00:00
|
|
|
def parse_path(client, path, context):
|
2013-04-24 17:42:47 +00:00
|
|
|
'''
|
|
|
|
args:
|
|
|
|
client - Client instance
|
|
|
|
path - path without volume prefix
|
|
|
|
return:
|
|
|
|
return None if file is ignored, dict with parsed item information otherwise
|
|
|
|
'''
|
2017-06-08 11:58:03 +00:00
|
|
|
m = re.compile('^(\d{4}|NA)/(\d{2}|NA)_(\d{4}|NA)/(?P<day>\d+|NA)_(?P<month>\d+|NA)_(?P<year>\d{4}|NA)((-(?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 17:42:47 +00:00
|
|
|
if not m:
|
|
|
|
return None
|
2013-04-24 22:53:53 +00:00
|
|
|
info = m.groupdict()
|
|
|
|
date = '%s-%s-%s' % (info['year'], info['month'], info['day'])
|
2016-11-05 14:55:06 +00:00
|
|
|
if info['tilday']:
|
2017-06-05 10:10:29 +00:00
|
|
|
date = '%s-%s-%s - %s-%s-%s' % (info['year'], info['month'], info['day'], info['tilyear'], info['tilmonth'], info['tilday'])
|
2013-04-24 22:53:53 +00:00
|
|
|
for key in info:
|
|
|
|
if info[key]:
|
|
|
|
info[key] = info[key].replace('_', ' ')
|
|
|
|
|
2017-06-08 11:58:03 +00:00
|
|
|
while date.endswith('-NA'):
|
|
|
|
date = date[:-3]
|
|
|
|
if date == 'NA':
|
|
|
|
date = ''
|
|
|
|
|
|
|
|
title_date = ' (%s)' % date if date else ''
|
|
|
|
|
2016-11-05 14:55:06 +00:00
|
|
|
topic = info['subject1'].split(",")
|
2013-04-24 22:53:53 +00:00
|
|
|
if info['subject2']:
|
2017-06-05 10:10:29 +00:00
|
|
|
topic += info['subject2'].split(",")
|
2017-06-08 11:58:03 +00:00
|
|
|
title = "%s, %s%s" % (info['subject1'], info['subject2'], title_date)
|
2013-04-24 22:53:53 +00:00
|
|
|
else:
|
2017-06-08 11:58:03 +00:00
|
|
|
title = "%s%s" % (info['subject1'], title_date)
|
2017-06-05 10:10:29 +00:00
|
|
|
|
2017-06-08 11:58:03 +00:00
|
|
|
'''
|
|
|
|
if info['shooter'] != 'NA':
|
|
|
|
title = "%s %s" % (title, info['shooter'])
|
|
|
|
'''
|
|
|
|
location = [info['location2'], info['location1']]
|
|
|
|
location = ', '.join([l.strip() for l in location if l.strip() != 'NA'])
|
|
|
|
location = location.strip()
|
|
|
|
|
|
|
|
if location:
|
|
|
|
title += ' at ' + location
|
2017-06-05 10:10:29 +00:00
|
|
|
title = title.replace(' ', ' ').strip()
|
|
|
|
title = title.replace(' ', ' ').strip()
|
|
|
|
|
2017-06-08 11:58:03 +00:00
|
|
|
topic = [t.strip() for t in topic if t.strip() != 'NA']
|
|
|
|
shooter = [s.strip() for s in info['shooter'].split(',') if s.strip() != 'NA']
|
2013-04-24 22:53:53 +00:00
|
|
|
|
|
|
|
r = {
|
2017-06-08 11:58:03 +00:00
|
|
|
'shooter': shooter,
|
2013-04-24 17:42:47 +00:00
|
|
|
'date': date,
|
2017-06-05 10:10:29 +00:00
|
|
|
'location': location,
|
2013-04-24 22:53:53 +00:00
|
|
|
'title': title,
|
|
|
|
'topic': topic
|
2013-04-24 17:42:47 +00:00
|
|
|
}
|
2013-04-24 22:53:53 +00:00
|
|
|
_info = ox.movie.parse_path(path)
|
|
|
|
for key in ('extension', 'type'):
|
|
|
|
r[key] = _info[key]
|
|
|
|
return r
|
2013-04-24 17:42:47 +00:00
|
|
|
|
2016-11-05 14:55:06 +00: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 10:10:29 +00:00
|
|
|
or filename in (
|
|
|
|
'.DS_Store', 'Thumbs.db',
|
2017-06-08 11:58:03 +00:00
|
|
|
'CINDEX.TMP', 'THUMB.TDT', 'THUMB.TID',
|
|
|
|
'S_INDEX.DAT',
|
2017-06-05 10:10:29 +00:00
|
|
|
) \
|
2016-11-05 14:55:06 +00:00
|
|
|
or filename.endswith('~') \
|
2017-06-05 10:10:29 +00: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',
|
2017-06-08 11:58:03 +00:00
|
|
|
'.doc', '.xml', '.psd', '.pds', '.qtindex', '.lnk',
|
2017-06-05 10:10:29 +00:00
|
|
|
) \
|
2016-11-05 14:55:06 +00:00
|
|
|
or not os.path.exists(path) \
|
|
|
|
or os.stat(path).st_size == 0:
|
|
|
|
return True
|
|
|
|
return False
|