使用Spotipy检测歌曲的结尾

2024-09-24 16:28:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用SpotipyLyricsGenius从终端在web浏览器上打开歌词

我可以打开一首歌的url,但每次都必须运行脚本才能连续运行。使用Spotipy检测歌曲结尾的方法有哪些

import spotipy
import webbrowser
import lyricsgenius as lg

...

# Create our spotifyObject
spotifyObject = spotipy.Spotify(auth=token)

# Create out geniusObject
geniusObject = lg.Genius(access_token)

...

while True:

    currently_playing = spotifyObject.currently_playing()
    artist = currently_playing['item']['artists'][0]['name']
    title = currently_playing['item']['name']
    search_query = artist + " " + title

    # if (currently_playing has changed):
        song = geniusObject.search_songs(search_query)
        song_url = song['hits'][0]['result']['url']
        webbrowser.open(song_url)

    webbrowser.open(song_url)

我正在阅读相关的线程,如thisthis,并通读了文档,但如果Spotipy能够处理这个问题,我找不到答案。如果您有任何建议,我将不胜感激,谢谢


Tags: importtokenurlsearchsongartistcreatewebbrowser