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