tracks deduplicator

This commit is contained in:
localhost_frssoft 2023-08-12 04:12:50 +03:00
parent a6bdeab60c
commit a5c5984880
2 changed files with 13 additions and 1 deletions

View File

@ -1,10 +1,11 @@
import src.fw_api
from src.utils import download_track, print_there, track_info_output
from src.utils import download_track, print_there, track_info_output, indices
from src.settings import get_config
from loguru import logger
from pyfzf.pyfzf import FzfPrompt
from shutil import get_terminal_size
from shlex import quote
from contextlib import suppress
import mpv
import time
import re
@ -145,6 +146,12 @@ def soft_volume_reduce():
@logger.catch
def player_menu(header='', storage={}):
for i in player.playlist_filenames:
count_same_tracks = indices(player.playlist_filenames, i)
while len(count_same_tracks) > 1:
with suppress(SystemError):
player.playlist_remove(count_same_tracks[-1])
count_same_tracks = indices(player.playlist_filenames, i)
player_fw_storage.storage.update(storage)
player.volume = get_config("mpv_volume")
global shuffle

View File

@ -78,3 +78,8 @@ def track_info_output(track):
output.append('Failed get related')
output = '\n'.join(output)
os.system(f'less <<EOF\n{output}\nEOF')
def indices(lst, item):
'''https://ao.phreedom.club/questions/5419204/index-of-duplicates-items-in-a-python-list'''
return [i for i, x in enumerate(lst) if x == item]