Skip to content

Commit

Permalink
Convert the add-on to audio-only.
Browse files Browse the repository at this point in the history
Making it play video doesn't seem to work anymore with modern versions of Kodi and converting it to an audio plugin may make it play well with other audio plugins (mainly, the Scrobbler plugin), although this was not tested yet.
  • Loading branch information
chusopr committed May 9, 2020
1 parent 01e469b commit e3dc83f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
24 changes: 19 additions & 5 deletions addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main_menu():
services not working after Last.fm rolled out their beta and
everything is broken until it comes back "soon"? """
for station in ["library", "mix", "recommended"]:
li = xbmcgui.ListItem('Last.fm %s %s' % (lastfm_user, station), iconImage='DefaultMusicVideos.png')
li = xbmcgui.ListItem('Last.fm %s %s' % (lastfm_user, station), iconImage='DefaultMusicPlaylists.png')
li.setProperty('IsPlayable', 'true')
xbmcplugin.addDirectoryItem(handle=addon_handle, url="%s?station=user/%s/%s" % (base_url, lastfm_user, station), listitem=li)
xbmcplugin.endOfDirectory(addon_handle)
Expand Down Expand Up @@ -174,10 +174,10 @@ def get_next_track(station):
li = xbmcgui.ListItem(" - ".join([artists, next_track["name"]]))
li.setInfo("music", {'artist': artists, 'title': next_track["name"]})
li.setProperty('IsPlayable', 'true')
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist.add(url="%s?track=%s&station=%s" % (base_url, next_track["url"].replace("&", "%26"), station_arg), listitem=li, index=playlist.getposition()+1)
playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
playlist.add(url="%s?track=%s&station=%s" % (base_url, next_track["url"].replace("&", "%26"), station_arg), listitem=li, index=playlist.size())

""" Now, here we go with the stuff we were requested: to resolve
""" Now, here we go with the stuff we were requested: resolving
to a playable URL """

""" TODO: for now, we are discarding YouTube links provided by
Expand All @@ -190,7 +190,7 @@ def get_next_track(station):

try:
ydl_opts = {
'format': 'best',
'format': 'bestaudio',
'no_color': True
}
ydl = YoutubeDL(ydl_opts)
Expand All @@ -210,10 +210,24 @@ def get_next_track(station):
track = get_next_track(args["station"][0])

if track:
# We first remove all other items from the playlist so we can do our magic
playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
# but we save a reference to our starting list item to add it later
current_li = playlist[playlist.getposition()]
playlist.clear()

artists = artists_str(track["artists"])
li = xbmcgui.ListItem(path="%s?track=%s&station=%s" % (base_url, track["url"], args["station"][0]))
li.setInfo("music", {'artist': artists, 'title': track["name"]})
li.setProperty('IsPlayable', 'true')

"""We need to add back to the playlist our starting item with a reference to the station
(well, it doesn't really matter what the first item is) and also the first song from the
station we are going to play now.
Without this, it would stop playing after the first song."""
playlist.add(url="%s?%s" % (base_url, sys.argv[2][1:]), listitem=current_li, index=0)
playlist.add(url="%s?track=%s&station=%s" % (base_url, track["url"], args["station"][0]), listitem=li, index=1)

xbmcplugin.setResolvedUrl(addon_handle, True, li)

else:
Expand Down
6 changes: 3 additions & 3 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.lastfm" name="Last.fm" version="1.1.0" provider-name="chuso">
<addon id="plugin.audio.lastfm" name="Last.fm" version="1.1.1" provider-name="chuso">
<requires>
<!-- May work with previous versions, but it was only tested with these -->
<import addon="xbmc.python" version="2.20.0"/>
<import addon="xbmc.python" version="2.26.0"/>
</requires>
<extension point="xbmc.python.pluginsource" library="addon.py">
<provides>video</provides>
<provides>audio</provides>
</extension>
<extension point="xbmc.addon.metadata">
<summary lang="en">Last.fm radio stations</summary>
Expand Down

0 comments on commit e3dc83f

Please sign in to comment.