2019-08-02 12:54:18 +01:00
|
|
|
from google.cloud import firestore
|
|
|
|
|
2019-08-17 18:30:13 +01:00
|
|
|
import logging
|
|
|
|
|
2019-10-19 17:14:11 +01:00
|
|
|
import music.db.database as database
|
2020-06-22 20:21:54 +01:00
|
|
|
from spotframework.net.network import SpotifyNetworkException
|
2019-08-10 17:53:50 +01:00
|
|
|
|
2019-08-02 12:54:18 +01:00
|
|
|
db = firestore.Client()
|
|
|
|
|
2019-08-17 18:30:13 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2019-08-02 12:54:18 +01:00
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
def create_playlist(user, name):
|
2019-08-17 18:30:13 +01:00
|
|
|
|
2020-05-08 15:19:27 +01:00
|
|
|
if user is None:
|
2020-06-21 15:30:51 +01:00
|
|
|
logger.error(f'username not provided')
|
2020-05-08 15:19:27 +01:00
|
|
|
return
|
2019-08-02 12:54:18 +01:00
|
|
|
|
2020-06-21 15:30:51 +01:00
|
|
|
logger.info(f'creating spotify playlist for {user.username} / {name}')
|
2020-05-08 15:19:27 +01:00
|
|
|
net = database.get_authed_spotify_network(user)
|
2019-08-14 22:57:58 +01:00
|
|
|
|
2020-06-22 20:21:54 +01:00
|
|
|
try:
|
|
|
|
return net.create_playlist(net.user.user.display_name, name)
|
|
|
|
except SpotifyNetworkException as e:
|
|
|
|
logger.error(f'error ocurred {user.username} / {name} - {e}')
|
2020-05-08 15:19:27 +01:00
|
|
|
return
|