103 lines
3.5 KiB
Python
103 lines
3.5 KiB
Python
'''
|
|
mosireen.py - pandora_client plugin
|
|
|
|
custom parse_path for pandora_client to parse musereen archive paths in the form
|
|
|
|
YYYY/MM_YYYY/DD_MM_YYYY/Location 1/Location 2/Event/Shooter/Topic 2(optional)/MVI_2036.MOV
|
|
|
|
'''
|
|
import re
|
|
import ox
|
|
import os
|
|
|
|
sync_extensions = ['.nef', '.cr2', '.pef']
|
|
|
|
def example_path(client):
|
|
return '\t' + 'YYYY/MM_YYYY/DD_MM_YYYY/Location 1/Location 2/Event/Shooter/Topic 2(optional)/MVI_2036.MOV'
|
|
|
|
def parse_path(client, path, context):
|
|
'''
|
|
args:
|
|
client - Client instance
|
|
path - path without volume prefix
|
|
return:
|
|
return None if file is ignored, dict with parsed item information otherwise
|
|
'''
|
|
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)
|
|
if not m:
|
|
return None
|
|
info = m.groupdict()
|
|
date = '%s-%s-%s' % (info['year'], info['month'], info['day'])
|
|
if info['tilday']:
|
|
date = '%s-%s-%s - %s-%s-%s' % (info['year'], info['month'], info['day'], info['tilyear'], info['tilmonth'], info['tilday'])
|
|
for key in info:
|
|
if info[key]:
|
|
info[key] = info[key].replace('_', ' ')
|
|
|
|
while date.endswith('-NA'):
|
|
date = date[:-3]
|
|
if date == 'NA':
|
|
date = ''
|
|
|
|
title_date = ' (%s)' % date if date else ''
|
|
|
|
topic = info['subject1'].split(",")
|
|
if info['subject2']:
|
|
topic += info['subject2'].split(",")
|
|
title = "%s, %s%s" % (info['subject1'], info['subject2'], title_date)
|
|
else:
|
|
title = "%s%s" % (info['subject1'], title_date)
|
|
|
|
'''
|
|
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
|
|
title = title.replace(' ', ' ').strip()
|
|
title = title.replace(' ', ' ').strip()
|
|
|
|
topic = [t.strip() for t in topic if t.strip() != 'NA']
|
|
shooter = [s.strip() for s in info['shooter'].split(',') if s.strip() != 'NA']
|
|
|
|
r = {
|
|
'shooter': shooter,
|
|
'date': date,
|
|
'location': location,
|
|
'title': title,
|
|
'topic': topic
|
|
}
|
|
_info = ox.movie.parse_path(path)
|
|
for key in ('extension', 'type'):
|
|
r[key] = _info[key]
|
|
return r
|
|
|
|
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('._') \
|
|
or filename in (
|
|
'.DS_Store', 'Thumbs.db',
|
|
'CINDEX.TMP', 'THUMB.TDT', 'THUMB.TID',
|
|
'S_INDEX.DAT',
|
|
) \
|
|
or filename.endswith('~') \
|
|
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', '.qtindex', '.lnk',
|
|
) \
|
|
or not os.path.exists(path) \
|
|
or os.stat(path).st_size == 0:
|
|
return True
|
|
return False
|