sorted music

This commit is contained in:
2026-03-31 14:56:37 +03:00
parent 003b40ffcf
commit d15bfc80c4
4 changed files with 359 additions and 60 deletions

82
main.py
View File

@@ -1,10 +1,19 @@
from asyncio.windows_events import NULL
import os
import subprocess
from rich import console
from rich.console import Console
from rich.panel import Panel
from rich.table import Table
from rich.progress import track
from selenium import webdriver
from selenium.webdriver import Chrome
import selenium.webdriver
import selenium.webdriver.chrome
import selenium.webdriver.chrome.options
from selenium.webdriver.common.by import By
import selenium
import time
import re
@@ -38,37 +47,50 @@ def normalize(text):
words.sort()
return words
def start():
console = Console()
console.print(Panel("Запуск программы"))
options = selenium.webdriver.chrome.options.Options()
options.add_argument("--headless")
driver = Chrome(options=options)
driver = webdriver.Chrome()
driver.get("https://muzpab.xn--41a.ws/")
file = open("music.txt", "r", encoding="utf-8")
new_file = open("new_music.txt", "w", encoding="utf-8")
console = Console()
table = Table(title="Музыка для поиска")
table.add_column("Номер трека", justify="center", style="cyan", no_wrap=True)
table.add_column("Название трека", justify="center")
table.add_column("Найденный трек", justify="center")
i = 1
for line in file:
sound_name = line.split(".")[1].strip()
sound_name_normalized = normalize(sound_name)
console.print(f"Ищем трек: {sound_name}")
search = driver.find_element(By.NAME, "q")
search.send_keys(sound_name)
search.submit()
track = driver.find_elements(By.CLASS_NAME, "artist_name")
track_normalized = normalize(track[0].text)
if track_normalized == sound_name_normalized:
console.print(f"Найден трек: [green]{track[0].text}[/green]")
table.add_row(str(i), sound_name, f"[green]{track[0].text}[/green]")
else:
console.print(f"Найден трек: [red]{track[0].text}[/red]")
table.add_row(str(i), sound_name, f"[red]{track[0].text}[/red]")
driver.get("https://muzpab.xn--41a.ws/")
console.print(driver.title, style="bold green")
file = open("music.txt", "r", encoding="utf-8")
new_file = open("new_music.txt", "w", encoding="utf-8")
bad_music = open("bad_music.txt", "w", encoding="utf-8")
new_file.write(track[0].text + "\n")
i += 1
console.clear()
console.print(table)
table = Table(title="Музыка для поиска")
table.add_column("Номер трека", justify="center", style="cyan", no_wrap=True)
table.add_column("Название трека", justify="center")
table.add_column("Найденный трек", justify="center")
i = 1
for line in file:
sound_name = re.sub(r'^\d+\.\s*', '', line.strip())
sound_name_normalized = normalize(sound_name)
console.print(f"Ищем трек: {sound_name}")
search = driver.find_element(By.NAME, "q")
search.send_keys(sound_name)
search.submit()
track = driver.find_elements(By.CLASS_NAME, "artist_name")
track_normalized = normalize(track[0].text)
if track_normalized == sound_name_normalized:
console.print(f"Найден трек: [green]{track[0].text}[/green]")
table.add_row(str(i), sound_name, f"[green]{track[0].text}[/green]")
new_file.write(track[0].text + "\n")
else:
console.print(f"Найден трек: [red]{track[0].text}[/red]")
table.add_row(str(i), sound_name, f"[red]{track[0].text}[/red]")
bad_music.write(sound_name + " // " + track[0].text + "\n")
new_file.close()
i += 1
subprocess.run("cls", shell=True)
console.print(table)
new_file.close()
bad_music.close()
if __name__ == "__main__":
start()