cleanup, refactor sources into enum
This commit is contained in:
parent
36c4cb204c
commit
90355661bf
51
main.py
51
main.py
|
@ -1,43 +1,43 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import pandas as pd
|
from enum import Enum
|
||||||
|
from pprint import pprint
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
import spotipy
|
import spotipy
|
||||||
#from spotipy.oauth2 import SpotifyClientCredentials
|
|
||||||
from spotipy.oauth2 import SpotifyOAuth
|
from spotipy.oauth2 import SpotifyOAuth
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
from config import *
|
from config import *
|
||||||
|
|
||||||
SRC_SPOTIFY = 'spotify'
|
class MusicSource(Enum):
|
||||||
SRC_YOUTUBE = 'youtube'
|
SPOTIFY = 'spotify'
|
||||||
SRC_SOUNDCLOUD = 'soundcloud'
|
YOUTUBE = 'youtube'
|
||||||
SRC_BANDCAMP = 'bandcamp'
|
SOUNDCLOUD = 'soundcloud'
|
||||||
SRC_OTHER = 'other'
|
BANDCAMP = 'bandcamp'
|
||||||
|
OTHER = 'other'
|
||||||
|
|
||||||
os.environ['SPOTIPY_CLIENT_ID'] = SPOTIPY_CLIENT_ID
|
os.environ['SPOTIPY_CLIENT_ID'] = SPOTIPY_CLIENT_ID
|
||||||
os.environ['SPOTIPY_CLIENT_SECRET'] = SPOTIPY_CLIENT_SECRET
|
os.environ['SPOTIPY_CLIENT_SECRET'] = SPOTIPY_CLIENT_SECRET
|
||||||
|
|
||||||
SERVICES = {
|
SERVICES = {
|
||||||
'open.spotify.com': SRC_SPOTIFY,
|
'open.spotify.com': MusicSource.SPOTIFY,
|
||||||
'youtu.be': SRC_YOUTUBE,
|
'youtu.be': MusicSource.YOUTUBE,
|
||||||
'www.youtube.com': SRC_YOUTUBE,
|
'www.youtube.com': MusicSource.YOUTUBE,
|
||||||
'soundcloud.app.goo.gl': SRC_SOUNDCLOUD,
|
'soundcloud.app.goo.gl': MusicSource.SOUNDCLOUD,
|
||||||
'on.soundcloud.com': SRC_SOUNDCLOUD,
|
'on.soundcloud.com': MusicSource.SOUNDCLOUD,
|
||||||
'm.soundcloud.com': SRC_SOUNDCLOUD,
|
'm.soundcloud.com': MusicSource.SOUNDCLOUD,
|
||||||
'soundcloud.com': SRC_SOUNDCLOUD
|
'soundcloud.com': MusicSource.SOUNDCLOUD
|
||||||
}
|
}
|
||||||
|
|
||||||
def echo(link):
|
def echo(link):
|
||||||
o = urlparse(link)
|
o = urlparse(link)
|
||||||
#print(o.hostname)
|
|
||||||
|
|
||||||
if re.match(r'([A-Za-z0-9\-]*\.)?bandcamp.com', o.hostname):
|
if re.match(r'([A-Za-z0-9\-]*\.)?bandcamp.com', o.hostname):
|
||||||
return {'source': SRC_BANDCAMP, 'link': link}
|
return {'source': MusicSource.BANDCAMP, 'link': link}
|
||||||
|
|
||||||
return {'source': SERVICES.get(o.hostname, SRC_OTHER), 'link': link}
|
return {'source': SERVICES.get(o.hostname, MusicSource.OTHER), 'link': link}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,13 +58,13 @@ def update_spotify_from_export():
|
||||||
other_links = []
|
other_links = []
|
||||||
|
|
||||||
for i in links_w_source:
|
for i in links_w_source:
|
||||||
if i['source'] == 'spotify':
|
if i['source'] == MusicSource.SPOTIFY:
|
||||||
spotify_links.append(i['link'])
|
spotify_links.append(i['link'])
|
||||||
elif i['source'] == 'youtube':
|
elif i['source'] == MusicSource.YOUTUBE:
|
||||||
yt_links.append(i['link'])
|
yt_links.append(i['link'])
|
||||||
elif i['source'] == 'soundcloud':
|
elif i['source'] == MusicSource.SOUNDCLOUD:
|
||||||
soundcloud_links.append(i['link'])
|
soundcloud_links.append(i['link'])
|
||||||
elif i['source'] == 'bandcamp':
|
elif i['source'] == MusicSource.BANDCAMP:
|
||||||
bandcamp.append(i['link'])
|
bandcamp.append(i['link'])
|
||||||
else:
|
else:
|
||||||
other_links.append(i['link'])
|
other_links.append(i['link'])
|
||||||
|
@ -75,11 +75,6 @@ def update_spotify_from_export():
|
||||||
print(bandcamp)
|
print(bandcamp)
|
||||||
print(other_links)
|
print(other_links)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#birdy_uri = 'spotify:artist:2WX2uTcsvV5OnS0inACecP'
|
|
||||||
#spotify = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())
|
|
||||||
|
|
||||||
scope = "playlist-modify-private"
|
scope = "playlist-modify-private"
|
||||||
os.environ['SPOTIPY_REDIRECT_URI'] = 'https://example.com/callback'
|
os.environ['SPOTIPY_REDIRECT_URI'] = 'https://example.com/callback'
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
#python-telegram-bot
|
#python-telegram-bot
|
||||||
spotipy
|
spotipy
|
||||||
|
pandas
|
||||||
|
|
Loading…
Reference in New Issue