Deduplicate head of playlist for common situation where current video is at top of playlist
This commit is contained in:
parent
91983b446e
commit
1e486d8ec6
|
@ -207,6 +207,25 @@ if __name__ == '__main__':
|
|||
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(mpv_socket)
|
||||
sock.sendall(f'playlist-clear; loadlist "{playlist_filename}" append\n'.encode())
|
||||
try:
|
||||
logging.debug('Checking current video to see if it should be removed from start of playlist')
|
||||
def get_property(name: str):
|
||||
sock.sendall(f'{{ "command": ["get_property", "{name}"] }}\n'.encode())
|
||||
response = sock.recv(4096)
|
||||
response_json = json.loads(response)
|
||||
logging.debug(response_json)
|
||||
if response_json['error'] == 'success':
|
||||
return response_json['data']
|
||||
else:
|
||||
raise ValueError(f'Response for get_property {name} was {response_json['error']}')
|
||||
current_filename = get_property('playlist/0/filename') # 'path' also works
|
||||
next_filename = get_property('playlist/1/filename')
|
||||
if current_filename == next_filename:
|
||||
logging.info('Next video is same as this one, deduplicating')
|
||||
sock.sendall(b'playlist-remove 1\n')
|
||||
sock.sendall(b'show-text ${playlist}\n')
|
||||
except BaseException as e:
|
||||
logging.error('Error deduping head of playlist: {}'.format(e))
|
||||
logging.info('mpv playlist reloaded!')
|
||||
except BaseException as e:
|
||||
logging.error('Error reloading playlist: {}'.format(e))
|
||||
|
|
Loading…
Reference in New Issue