mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
* Refactoring and addition of logzero (#172) * Refactored convert.py and added logging. * Added logging and refactored. * Added logzero to requirements.txt * Added logging to metadata.py * Created a log in misc.py. Updated slugify import. * Some general improvement * Improve message layout * Improve test mechanism * Implement debug level logging * Fix some minor mistakes * Make pytest happy * Remove unimplemented --verbose option * Update ISSUE_TEMPLATE.md * Rename LICENSE * Remove obvious from log.debug() * Show track URL when writing to file (debug)
57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
# -*- coding: UTF-8 -*-
|
|
|
|
import spotdl
|
|
|
|
username = 'alex'
|
|
|
|
|
|
def test_user():
|
|
expect_playlists = 7
|
|
playlists = spotdl.spotify.user_playlists(username)
|
|
playlists = len(playlists['items'])
|
|
assert playlists == expect_playlists
|
|
|
|
|
|
def test_playlist():
|
|
expect_tracks = 14
|
|
playlist = spotdl.spotify.user_playlists(username)['items'][0]
|
|
tracks = playlist['tracks']['total']
|
|
assert tracks == expect_tracks
|
|
|
|
|
|
def test_tracks():
|
|
playlist = spotdl.spotify.user_playlists(username)['items'][0]
|
|
expect_lines = playlist['tracks']['total']
|
|
result = spotdl.spotify.user_playlist(
|
|
playlist['owner']['id'], playlist['id'], fields='tracks,next')
|
|
tracks = result['tracks']
|
|
|
|
with open('list.txt', 'w') as fout:
|
|
while True:
|
|
for item in tracks['items']:
|
|
track = item['track']
|
|
try:
|
|
fout.write(track['external_urls']['spotify'] + '\n')
|
|
except KeyError:
|
|
pass
|
|
# 1 page = 50 results
|
|
# check if there are more pages
|
|
if tracks['next']:
|
|
tracks = spotify.next(tracks)
|
|
else:
|
|
break
|
|
|
|
with open('list.txt', 'r') as listed:
|
|
expect_song = (listed.read()).splitlines()[0]
|
|
|
|
spotdl.internals.trim_song('list.txt')
|
|
with open('list.txt', 'a') as myfile:
|
|
myfile.write(expect_song)
|
|
|
|
with open('list.txt', 'r') as listed:
|
|
songs = (listed.read()).splitlines()
|
|
|
|
lines = len(songs)
|
|
song = songs[-1]
|
|
assert (expect_lines == lines and expect_song == song)
|