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
|
|
|
|
|
2013-04-24 22:53:53 +00:00
|
|
|
YYYY/MM_YYYY/DD_MM_YYYY/Location 1/Location 2/Subject 1/Cinematographer/Subject 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
|
|
|
|
|
|
|
def example_path(client):
|
2013-04-24 22:53:53 +00:00
|
|
|
return '\t' + 'YYYY/MM_YYYY/DD_MM_YYYY/Location 1/Location 2/Subject 1/Shooter/Subject 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
|
|
|
|
'''
|
2016-11-05 14:55:06 +00: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 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']:
|
|
|
|
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('_', ' ')
|
|
|
|
|
2016-11-05 14:55:06 +00:00
|
|
|
topic = info['subject1'].split(",")
|
2013-04-24 22:53:53 +00:00
|
|
|
if info['subject2']:
|
2016-11-05 14:55:06 +00:00
|
|
|
topic+=info['subject2'].split(",")
|
2013-04-24 22:53:53 +00:00
|
|
|
title = "%s, %s (%s)" % (info['subject1'], info['subject2'], date)
|
|
|
|
else:
|
|
|
|
title = "%s (%s)" % (info['subject1'], date)
|
2013-12-02 17:26:38 +00:00
|
|
|
title = "%s %s at %s, %s" % (title,
|
|
|
|
info['shooter'],info['location2'],info['location1'])
|
2013-04-24 22:53:53 +00:00
|
|
|
|
|
|
|
r = {
|
|
|
|
'cinematographer': [info['shooter']],
|
2013-04-24 17:42:47 +00:00
|
|
|
'date': date,
|
2013-04-24 22:53:53 +00:00
|
|
|
'location': '%s, %s' % (info['location2'], info['location1']),
|
|
|
|
'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('._') \
|
|
|
|
or filename in ('.DS_Store',) \
|
|
|
|
or filename.endswith('~') \
|
|
|
|
or not os.path.exists(path) \
|
|
|
|
or os.stat(path).st_size == 0:
|
|
|
|
return True
|
|
|
|
return False
|