Instead of deduping head, search entire playlist and move playing video appropriately
This commit is contained in:
parent
9cb7244315
commit
60960b8f34
|
@ -208,23 +208,26 @@ if __name__ == '__main__':
|
||||||
sock.connect(mpv_socket)
|
sock.connect(mpv_socket)
|
||||||
sock.sendall(f'playlist-clear; loadlist "{playlist_filename}" append\n'.encode())
|
sock.sendall(f'playlist-clear; loadlist "{playlist_filename}" append\n'.encode())
|
||||||
try:
|
try:
|
||||||
logging.debug('Checking current video to see if it should be removed from start of playlist')
|
logging.debug('Searching playlist for current video to see if it should replace a later entry')
|
||||||
def get_property(name: str):
|
def get_property(name: str):
|
||||||
sock.sendall(f'{{ "command": ["get_property", "{name}"] }}\n'.encode())
|
sock.sendall(f'{{ "command": ["get_property", "{name}"] }}\n'.encode())
|
||||||
response = sock.recv(4096)
|
response = sock.recv(2**30)
|
||||||
response_json = json.loads(response)
|
response_json = json.loads(response)
|
||||||
logging.debug(response_json)
|
logging.debug(response_json)
|
||||||
if response_json['error'] == 'success':
|
if response_json['error'] == 'success':
|
||||||
return response_json['data']
|
return response_json['data']
|
||||||
else:
|
else:
|
||||||
raise ValueError(f'Response for get_property {name} was {response_json['error']}')
|
raise ValueError(f'Response for get_property {name} was {response_json['error']}')
|
||||||
current_filename = get_property('playlist/0/filename') # 'path' also works
|
full_playlist = get_property('playlist')
|
||||||
next_filename = get_property('playlist/1/filename')
|
current_filename = full_playlist[0]['filename'] # Should check each one for "current":true in other circumstances, but we cleared playlist ahead of time so we know we are on index 0
|
||||||
if current_filename == next_filename:
|
for i, entry in enumerate(full_playlist[1:], 1):
|
||||||
logging.info('Next video is same as this one, deduplicating')
|
if entry['filename'] == current_filename:
|
||||||
sock.sendall(b'playlist-remove 1\n')
|
logging.debug(f'Found matching filename at playlist index {i}')
|
||||||
|
sock.sendall(f'playlist-remove {i}; playlist-move 0 {i}\n'.encode())
|
||||||
|
break
|
||||||
|
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
logging.error('Error deduping head of playlist: {}'.format(e))
|
logging.error('Error searching playlist: {}'.format(e))
|
||||||
sock.sendall(b'show-text ${playlist}\n') # Shows playlist OSD for visual feedback
|
sock.sendall(b'show-text ${playlist}\n') # Shows playlist OSD for visual feedback
|
||||||
logging.info('mpv playlist reloaded!')
|
logging.info('mpv playlist reloaded!')
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
|
|
Loading…
Reference in New Issue