如何解决使用Spotipy检测歌曲的结尾
我正在使用Spotipy和LyricsGenius在终端上通过网络浏览器打开歌词。
我可以打开一首歌的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)
我正在阅读this,this之类的相关线程,并通读了文档,但是如果Spotipy可以解决这个问题,我找不到答案。任何建议,我将不胜感激。
解决方法
我使用time.sleep(length)并将参数“ length”表示当前曲目的剩余持续时间。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。