Compare commits

...

2 commits

Author SHA1 Message Date
j
841a654254 more advanced fragment parsing 2023-11-08 11:01:20 +01:00
j
3252392eb5 reset player if stuck 2023-11-08 11:01:02 +01:00
2 changed files with 37 additions and 6 deletions

View file

@ -35,6 +35,7 @@ class Sync(Thread):
destination = "255.255.255.255"
reload_check = None
_pos = None
_tick = 0
def __init__(self, *args, **kwargs):
self.is_main = kwargs.get('mode', 'main') == 'main'
@ -66,7 +67,6 @@ class Sync(Thread):
self.sync_to_main()
self.ready = True
Thread.__init__(self)
self.daemon = True
self.start()
def run(self):
@ -77,6 +77,13 @@ class Sync(Thread):
self.read_position_main()
#self.adjust_position()
self.reload_playlist()
if self._tick and abs(time.time() - self._tick) > 10:
logger.error("player is stuck")
self._tick = 0
self.mpv.loadlist(self.playlist)
self.mpv.playlist_play_index(0)
self.mpv.pause = False
self.mpv.wait_until_playing()
def q_binding(self, *args):
self.stop()
@ -89,6 +96,7 @@ class Sync(Thread):
self.sock = None
def time_pos_cb(self, pos, *args, **kwargs):
self._tick = time.time()
if self.is_main:
self.send_position_local()
elif self.ready:

View file

@ -282,7 +282,7 @@ def render(root, scene, prefix=''):
files.append(path)
return files
def get_fragments(clips, voice_over):
def get_fragments(clips, voice_over, prefix):
import itemlist.models
import item.models
from collections import defaultdict
@ -293,14 +293,37 @@ def get_fragments(clips, voice_over):
if l.name.split(' ')[0].isdigit():
fragment = {
'name': l.name,
'tags': [t['value'] for t in l.query['conditions'][1]['conditions'] if t['operator'] == '=='],
'anti-tags': [t['value'] for t in l.query['conditions'][1]['conditions'] if t['operator'] == '!='],
'tags': [],
'anti-tags': [],
'description': l.description
}
for con in l.query['conditions']:
if "conditions" in con:
for sub in con["conditions"]:
if sub['key'] == "tags" and sub['operator'] == '==':
fragment['tags'].append(sub['value'])
elif sub['key'] == "tags" and sub['operator'] == '!=':
fragment['tags'].append(sub['value'])
else:
print('unknown sub condition', sub)
elif con.get('key') == "tags" and con['operator'] == '==':
fragment['tags'].append(con['value'])
elif con.get('key') == "tags" and con['operator'] == '!=':
fragment['anti-tags'].append(con['value'])
fragment["id"] = int(fragment['name'].split(' ')[0])
originals = []
for i in l.get_items(l.user):
orig = i.files.filter(selected=True).first()
if orig:
ext = os.path.splitext(orig.data.path)[1]
type_ = i.data['type'][0].lower()
target = os.path.join(prefix, type_, i.data['title'] + ext)
originals.append(target)
fragment['clips'] = []
for clip in clips:
if set(clip['tags']) & set(fragment['tags']) and not set(clip['tags']) & set(fragment['anti-tags']):
#if set(clip['tags']) & set(fragment['tags']) and not set(clip['tags']) & set(fragment['anti-tags']):
if clip['original'] in originals:
fragment['clips'].append(clip)
fragment["voice_over"] = voice_over.get(str(fragment["id"]), {})
fragments.append(fragment)
@ -322,7 +345,7 @@ def render_all(options):
clips = json.load(fd)
with open(os.path.join(prefix, "voice_over.json")) as fd:
voice_over = json.load(fd)
fragments = get_fragments(clips, voice_over)
fragments = get_fragments(clips, voice_over, prefix)
with open(os.path.join(prefix, "fragments.json"), "w") as fd:
json.dump(fragments, fd, indent=2, ensure_ascii=False)
position = target_position = 0