Compare commits
5 Commits
90355661bf
...
e0ceb3a968
Author | SHA1 | Date |
---|---|---|
![]() |
e0ceb3a968 | |
![]() |
5326d6d2f7 | |
![]() |
664392fe0e | |
![]() |
175a2a9b0c | |
![]() |
a9bbe2e9f6 |
33
main.py
33
main.py
|
@ -1,3 +1,4 @@
|
||||||
|
import itertools
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
@ -31,6 +32,13 @@ SERVICES = {
|
||||||
'soundcloud.com': MusicSource.SOUNDCLOUD
|
'soundcloud.com': MusicSource.SOUNDCLOUD
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _split_seq(iterable, size):
|
||||||
|
it = iter(iterable)
|
||||||
|
item = list(itertools.islice(it, size))
|
||||||
|
while item:
|
||||||
|
yield item
|
||||||
|
item = list(itertools.islice(it, size))
|
||||||
|
|
||||||
def echo(link):
|
def echo(link):
|
||||||
o = urlparse(link)
|
o = urlparse(link)
|
||||||
|
|
||||||
|
@ -69,18 +77,29 @@ def update_spotify_from_export():
|
||||||
else:
|
else:
|
||||||
other_links.append(i['link'])
|
other_links.append(i['link'])
|
||||||
|
|
||||||
print(spotify_links)
|
#print(spotify_links)
|
||||||
print(yt_links)
|
#print(yt_links)
|
||||||
print(soundcloud_links)
|
#print(soundcloud_links)
|
||||||
print(bandcamp)
|
#print(bandcamp)
|
||||||
print(other_links)
|
#print(other_links)
|
||||||
|
|
||||||
|
print(f'Spotify tracks: {len(spotify_links)}')
|
||||||
|
|
||||||
scope = "playlist-modify-private"
|
scope = "playlist-modify-private"
|
||||||
os.environ['SPOTIPY_REDIRECT_URI'] = 'https://example.com/callback'
|
os.environ['SPOTIPY_REDIRECT_URI'] = 'http://127.0.0.1:9090'
|
||||||
|
|
||||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||||
sp.playlist(SPOTIFY_PLAYLIST_ID)
|
sp.playlist(SPOTIFY_PLAYLIST_ID)
|
||||||
print(sp.playlist_replace_items(SPOTIFY_PLAYLIST_ID, spotify_links))
|
|
||||||
|
# clean playlist itself from spotify links
|
||||||
|
spotify_links = [s for s in spotify_links if not s.startswith('https://open.spotify.com/playlist/')]
|
||||||
|
|
||||||
|
# paginated update of spotify playlist
|
||||||
|
for i, sublist in enumerate(_split_seq(spotify_links, 100)):
|
||||||
|
if i==0:
|
||||||
|
sp.playlist_replace_items(SPOTIFY_PLAYLIST_ID, sublist)
|
||||||
|
else:
|
||||||
|
sp.playlist_add_items(SPOTIFY_PLAYLIST_ID, sublist)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue