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-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)
|
2020-07-01 11:03:43 +01:00
|
|
|
except SpotifyNetworkException:
|
|
|
|
logger.exception(f'error ocurred {user.username} / {name}')
|
2020-05-08 15:19:27 +01:00
|
|
|
return
|