Compare commits
No commits in common. "e0ceb3a968bf10e56e23ced8c55429d5682764ac" and "90355661bf21475515180f75c337b940e455b766" have entirely different histories.
e0ceb3a968
...
90355661bf
33
main.py
33
main.py
|
@ -1,4 +1,3 @@
|
||||||
import itertools
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
@ -32,13 +31,6 @@ 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)
|
||||||
|
|
||||||
|
@ -77,29 +69,18 @@ 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'] = 'http://127.0.0.1:9090'
|
os.environ['SPOTIPY_REDIRECT_URI'] = 'https://example.com/callback'
|
||||||
|
|
||||||
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