From 8c0d5c2b5d30fc50f78e5cd12144bb0335299898 Mon Sep 17 00:00:00 2001 From: Ivan Zinchenko Date: Sat, 5 Aug 2023 14:52:31 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=BD=D1=8C=D1=88=D0=B5=20=D0=B1?= =?UTF-8?q?=D0=B0=D0=B3=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- README.md | 2 +- main.py | 13 +++++-------- requirements.txt | 2 ++ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 55787bd..11cb8f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ spotlistr-exported-playlist.csv -urls.txt \ No newline at end of file +urls.txt +venv \ No newline at end of file diff --git a/README.md b/README.md index 7b04ada..c5a2365 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ Программа ищет на YTMusic музыку из csv файла, а затем формирует список ссылок на эту музыку. -Программа использует информацию из файла, полученного на [spotlistr](https://www.spotlistr.com/). Нужно выбрать раздел [export playlist](https://www.spotlistr.com/export/spotify-playlist). Файл должен содержать поля: `Arist(s) Name`, `Track Name`, `Album Name`, а сепаратором служит знак `;`. \ No newline at end of file +Программа использует информацию из файла, полученного на [spotlistr](https://www.spotlistr.com/). Нужно выбрать раздел [export playlist](https://www.spotlistr.com/export/spotify-playlist). Файл должен содержать поля: `Arist(s) Name`, `Track Name`, `Album Name`. \ No newline at end of file diff --git a/main.py b/main.py index 2c7c2e4..c908478 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import argparse import csv import sys +from tqdm import tqdm from ytmusicapi import YTMusic as YTM def createArgParser() -> argparse.ArgumentParser: @@ -34,23 +35,19 @@ def parseCSV(file: str = 'spotlistr-exported-playlist.csv') -> list: with open(file, newline='') as csvfile: songsList = csv.reader(csvfile) for row in songsList: - songs.append(Song(row[0], row[1], row[2])) + try: + songs.append(Song(row[0], row[1], row[2])) + except: pass return songs def searchSongs(songs: list) -> list: YTMusic = YTM() urls = [] urlBase = 'https://music.youtube.com/watch?v=' - for i in range(len(songs)): - song = songs[i] + for song in tqdm(songs): searched = YTMusic.search(query=song.getArtist() + ' ' + song.getTrack(), filter='songs', limit=1) try: urls.append(urlBase + searched[0]['videoId']) - - # Log - sys.stdout.write('\x1b[2K') - print(f"Song {i + 1}/{len(songs)}: {searched[0]['artists'][0]['name']} - {searched[0]['title']}") - print("\033[A\033[A") except IndexError: print('\n' + song.getArtist() + ' ' + song.getTrack() + ' - NOT FOUND') return urls diff --git a/requirements.txt b/requirements.txt index b3fd9b2..5dc3a60 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,8 @@ certifi==2022.6.15 charset-normalizer==2.1.0 +colorama==0.4.6 idna==3.3 requests==2.28.1 +tqdm==4.65.0 urllib3==1.26.11 ytmusicapi==0.22.0