Меньше багов
This commit is contained in:
parent
2f2603606c
commit
8c0d5c2b5d
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
spotlistr-exported-playlist.csv
|
||||
urls.txt
|
||||
urls.txt
|
||||
venv
|
||||
@ -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`, а сепаратором служит знак `;`.
|
||||
Программа использует информацию из файла, полученного на [spotlistr](https://www.spotlistr.com/). Нужно выбрать раздел [export playlist](https://www.spotlistr.com/export/spotify-playlist). Файл должен содержать поля: `Arist(s) Name`, `Track Name`, `Album Name`.
|
||||
13
main.py
13
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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user