diff --git a/add_playlist_yt_titles.py b/add_playlist_yt_titles.py index a7fcdc1..87865a2 100755 --- a/add_playlist_yt_titles.py +++ b/add_playlist_yt_titles.py @@ -208,23 +208,26 @@ if __name__ == '__main__': 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') + logging.debug('Searching playlist for current video to see if it should replace a later entry') def get_property(name: str): sock.sendall(f'{{ "command": ["get_property", "{name}"] }}\n'.encode()) - response = sock.recv(4096) + response = sock.recv(2**30) 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') + full_playlist = get_property('playlist') + 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 + for i, entry in enumerate(full_playlist[1:], 1): + if entry['filename'] == current_filename: + 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: - 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 logging.info('mpv playlist reloaded!') except BaseException as e: