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 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 src.settings import get_config
from loguru import logger from loguru import logger
from pyfzf.pyfzf import FzfPrompt from pyfzf.pyfzf import FzfPrompt
from shutil import get_terminal_size from shutil import get_terminal_size
from shlex import quote from shlex import quote
from contextlib import suppress
import mpv import mpv
import time import time
import re import re
@ -145,6 +146,12 @@ def soft_volume_reduce():
@logger.catch @logger.catch
def player_menu(header='', storage={}): 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_fw_storage.storage.update(storage)
player.volume = get_config("mpv_volume") player.volume = get_config("mpv_volume")
global shuffle global shuffle

View file

@ -78,3 +78,8 @@ def track_info_output(track):
output.append('Failed get related') output.append('Failed get related')
output = '\n'.join(output) output = '\n'.join(output)
os.system(f'less <<EOF\n{output}\nEOF') 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]