diff --git a/add_playlist_yt_titles.py b/add_playlist_yt_titles.py index 6b5924b..380bd3b 100755 --- a/add_playlist_yt_titles.py +++ b/add_playlist_yt_titles.py @@ -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))