Skip to content
Snippets Groups Projects
Commit 9662b8c6 authored by Frederic Aust's avatar Frederic Aust
Browse files

New module: Spotify - you can add songs to a Spotify playlist with .addsong

parent 93dd06b9
No related branches found
No related tags found
No related merge requests found
...@@ -94,7 +94,17 @@ ...@@ -94,7 +94,17 @@
"Description": "Syntax: .deepl <Language>, <String>. Translate a word, sentence or even small texts with DeepL translator. Type: .deepl ES, Where is the library?", "Description": "Syntax: .deepl <Language>, <String>. Translate a word, sentence or even small texts with DeepL translator. Type: .deepl ES, Where is the library?",
"_Func": "get_deepl_translation", "_Func": "get_deepl_translation",
"allowedGroups":[] "allowedGroups":[]
},
{
"Names": [
".addsong"
],
"Description": "Syntax: .addsong <Message>. Just add .addsong to your normal Spotify Song Msg. The bot will do the rest.",
"_Func": "add_song_to_playlist",
"allowedGroups":["Testung", "ntp.ReleaseRadar"]
} }
], ],
"Crawlers": [ "Crawlers": [
{ {
......
# ntp.ReleaseRadar
# https://open.spotify.com/playlist/3Px6Qe12qrEltV1r6AKvec?si=d740d824248a4f9a
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import re
class ModuleSpotify:
# track_uri = "https://open.spotify.com/intl-de/track/1Hig7RNxPMrYZ9aN5lZtAd?si=a9a85b60cd444f2b"
def __init__(self, send, client_id, client_secret, redirect_uri, log):
self.tag = "%20s - " % "mSpotify"
self.log = log
self.send = send
scope = "playlist-modify-public"
self.playlist_id = "1KpS9GIl23CPmTxJrBh6iD"
username = "usatas"
self.sp = spotipy.Spotify(
auth_manager=SpotifyOAuth(
client_id=client_id,
client_secret=client_secret,
redirect_uri=redirect_uri,
scope=scope,
username=username,
)
)
self.log.debug(f"{self.tag}Modul Spotify geladen")
# https://open.spotify.com/intl-de/track/1Hig7RNxPMrYZ9aN5lZtAd?si=f084120527084c1b
def add_song_to_playlist(self, song_msg):
song_uri = "spotify:track:"
match = re.search(r"\/([a-zA-Z0-9]+)\?", song_msg)
if not match:
return "Nope - invalid song URL!"
song_uri += match.group(1)
self.sp.playlist_add_items(
playlist_id=self.playlist_id, items=[song_uri]
) # TODO Abfragen ob der song schon drin ist
return "song added to https://open.spotify.com/playlist/1KpS9GIl23CPmTxJrBh6iD?si=6b384ff854574269"
# http://localhost:8080/?code=AQCWMXelx3cI0aH5O0s0XtG-NY1ogpwC2sQbb6nN4mwStY1irihYEYBRC13g0WBNLN8fxg5eBiS0B2jl_c9X5XHVoGs6nAAUV4A1le0jFx7FcCGqBBHndOZMnbrmQ6LFsY4TicHnvm0SgIr-gjOmcwxt0kXsCu8L9w&state=playlist-modify-public
...@@ -9,3 +9,4 @@ beautifulsoup4 ...@@ -9,3 +9,4 @@ beautifulsoup4
python-dateutil python-dateutil
sympy sympy
deepl deepl
spotipy
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment