import time
from telemeta.util.xmltodict2 import *
import json
+from collections import defaultdict
+import pprint
def parse_timecode(value, fps):
"""
def video_entries(self):
entries = []
for attr in self.session['children']:
- if 'playlist' in attr['name'] and 'children' in attr and not 'main' in attr['attributes']['id']:
- for att in attr['children']:
+ if 'playlist' in attr['name'] and 'children' in attr:
+ plid = attr['attributes'].get('id', '')
+ if 'main_bin' in plid:
+ continue
+ for att in attr['children']:
if 'entry' in att['name'] and att['attributes']['producer'] != 'black' \
and not 'audio' in att['attributes']['producer']:
entries.append(att['attributes'])
except:
return text
+ def get_producer_altids(self):
+ """
+ Get the alternate ids of producers if any
+ """
+ by_names = defaultdict(list)
+ for attr in self.session['children']:
+ if 'producer' in attr['name'] and 'children' in attr:
+ if "id" in attr['attributes']:
+ entry_id = attr['attributes']['id']
+ for att in attr['children']:
+ name = att['attributes']['name']
+ if 'resource' in name and 'cdata' in att:
+ by_names[att['cdata']].append(entry_id)
+
+ alt_ids = {}
+ for vals in by_names.values():
+ if len(vals) > 1:
+ vals = set(vals)
+ for val in vals:
+ alt_ids[val] = vals
+
+ return alt_ids
+
+
def markers(self, offset=0, from_first_marker=False):
""" by default return a dict of markers with timecodes relative to an origin
"""
markers = []
entries = self.entries_video_seconds()
+ #print("=> Video entries")
+ #pprint.pprint(entries)
title = ''
fps = self.get_fps()
+ alternate_ids = self.get_producer_altids()
+ #print("=> Alternate ids")
+ #pprint.pprint(alternate_ids)
def add_marker(rel_time, comment):
"""
marker['comment'] = comment
markers.append(marker)
- def get_reltime(entry_id, marker_time):
+ def get_reltime(entry_id, marker_time, alt_ids = []):
"""
Get the relative time of a marker linked to an entry
"""
rel_time = 0
for entry in entries:
- if entry['in'] <= marker_time <= entry['out'] and entry_id == entry['id']:
+ if entry['in'] <= marker_time <= entry['out'] and (entry_id == entry['id'] or entry['id'] in alt_ids):
rel_time = entry['t'] + (marker_time - entry['in']) + offset
return rel_time
rel_time = get_reltime(entry_id, marker_time)
if rel_time is not None:
add_marker(rel_time, comment)
- elif 'producer' in attr['name'] and 'children' in attr:
+ elif 'producer' in attr['name'] and 'children' in attr:
# New v 6.24 file format, markers in producers
if "id" in attr['attributes']:
entry_id = attr['attributes']['id']
+ alt_ids = alternate_ids.get(entry_id, [])
for att in attr['children']:
name = att['attributes']['name']
if 'markers' in name:
items = json.loads(self.fix_text(att['cdata']))
+ #print("=> Marker items")
+ #pprint.pprint(items)
for marker in items:
marker_time = float(marker['pos'] / fps)
- rel_time = get_reltime(entry_id, marker_time)
+ rel_time = get_reltime(entry_id, marker_time,
+ alt_ids)
if rel_time is not None:
add_marker(rel_time, marker['comment'])
+ #print("=> Markers")
+ #pprint.pprint(markers)
+
if markers and from_first_marker:
delta = min([ marker['time'] for marker in markers ])
for marker in markers: