Skip to content

Commit

Permalink
v5
Browse files Browse the repository at this point in the history
  • Loading branch information
L2501 committed Sep 24, 2019
1 parent cabeee0 commit 8ed0095
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 115 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
MP3 Streams Reloaded

### Notes
* Pagination is in context menu where needed
* Force fixed viewmode in settings if needed (default ids for Confluence, other skins will be different)
* Seeking is not possible (server side)
* Try not to queue everything at once, one album/artist at a time should be fine.
Expand Down
6 changes: 4 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.audio.m3sr2019" name="MP3 Streams Reloaded" version="4" provider-name="MP3 Streams">
<addon id="plugin.audio.m3sr2019" name="MP3 Streams Reloaded" version="5" provider-name="MP3 Streams">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
<import addon="script.module.beautifulsoup4" />
<import addon="script.module.six" />
<import addon="script.module.kodi-six" />
<import addon="script.module.future" />
<import addon="script.module.requests" />
<import addon="script.module.routing" />
</requires>
Expand All @@ -13,7 +15,7 @@
<extension point="xbmc.addon.metadata">
<reuselanguageinvoker>true</reuselanguageinvoker>
<platform>all</platform>
<license>GPL-2.0</license>
<license>GPL-3.0</license>
<summary>A music streaming collection</summary>
<description>Browse, stream or download your favourite songs and albums</description>
<assets>
Expand Down
176 changes: 78 additions & 98 deletions default.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 L2501
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals

import os
import sys
import routing
import xbmcaddon
import xbmc
from xbmc import executebuiltin
from xbmcgui import ListItem
from xbmcplugin import addDirectoryItems, addDirectoryItem, endOfDirectory, setResolvedUrl, setContent
from routing import Plugin
from kodi_six import xbmc, xbmcgui, xbmcaddon, xbmcplugin
from resources.lib.musicmp3 import musicMp3, gnr_ids


try:
from urllib.parse import quote as orig_quote
from urllib.parse import unquote as orig_unquote
except ImportError:
from urllib import quote as orig_quote
from urllib import unquote as orig_unquote
from future.backports.urllib.parse import quote_from_bytes as orig_quote
from future.backports.urllib.parse import unquote_to_bytes as orig_unquote


def quote(s, safe=""):
Expand All @@ -26,13 +34,11 @@ def unquote(s):


addon = xbmcaddon.Addon()
plugin = routing.Plugin()
plugin = Plugin()
plugin.name = addon.getAddonInfo("name")

USER_DATA_DIR = xbmc.translatePath(addon.getAddonInfo("profile")).decode("utf-8") # !!
MEDIA_DIR = os.path.join(
xbmc.translatePath(xbmcaddon.Addon().getAddonInfo("path")).decode("utf-8"), "resources", "media"
)
USER_DATA_DIR = xbmc.translatePath(addon.getAddonInfo("profile"))
MEDIA_DIR = os.path.join(xbmc.translatePath(xbmcaddon.Addon().getAddonInfo("path")), "resources", "media")
FANART = os.path.join(MEDIA_DIR, "fanart.jpg")
MUSICMP3_DIR = os.path.join(USER_DATA_DIR, "musicmp3")
if not os.path.exists(MUSICMP3_DIR):
Expand All @@ -45,29 +51,29 @@ def unquote(s):

@plugin.route("/")
def index():
_all_artists = ListItem("Artists")
_all_artists = xbmcgui.ListItem("Artists")
_all_artists.setArt({"fanart": FANART, "icon": os.path.join(MEDIA_DIR, "artists.jpg")})
addDirectoryItem(plugin.handle, plugin.url_for(musicmp3_artist_main), _all_artists, True)
_top_albums = ListItem("Top Albums")
xbmcplugin.addDirectoryItem(plugin.handle, plugin.url_for(musicmp3_artist_main), _all_artists, True)
_top_albums = xbmcgui.ListItem("Top Albums")
_top_albums.setArt({"fanart": FANART, "icon": os.path.join(MEDIA_DIR, "topalbums.jpg")})
addDirectoryItem(plugin.handle, plugin.url_for(musicmp3_albums_main, "top"), _top_albums, True)
_new_albums = ListItem("New Albums")
xbmcplugin.addDirectoryItem(plugin.handle, plugin.url_for(musicmp3_albums_main, "top"), _top_albums, True)
_new_albums = xbmcgui.ListItem("New Albums")
_new_albums.setArt({"fanart": FANART, "icon": os.path.join(MEDIA_DIR, "newalbums.jpg")})
addDirectoryItem(plugin.handle, plugin.url_for(musicmp3_albums_main, "new"), _new_albums, True)
_search_artists = ListItem("Search Artists")
xbmcplugin.addDirectoryItem(plugin.handle, plugin.url_for(musicmp3_albums_main, "new"), _new_albums, True)
_search_artists = xbmcgui.ListItem("Search Artists")
_search_artists.setArt({"fanart": FANART, "icon": os.path.join(MEDIA_DIR, "searchartists.jpg")})
addDirectoryItem(plugin.handle, plugin.url_for(musicmp3_search, "artists"), _search_artists, True)
_search_albums = ListItem("Search Albums")
xbmcplugin.addDirectoryItem(plugin.handle, plugin.url_for(musicmp3_search, "artists"), _search_artists, True)
_search_albums = xbmcgui.ListItem("Search Albums")
_search_albums.setArt({"fanart": FANART, "icon": os.path.join(MEDIA_DIR, "searchalbums.jpg")})
addDirectoryItem(plugin.handle, plugin.url_for(musicmp3_search, "albums"), _search_albums, True)
endOfDirectory(plugin.handle)
xbmcplugin.addDirectoryItem(plugin.handle, plugin.url_for(musicmp3_search, "albums"), _search_albums, True)
xbmcplugin.endOfDirectory(plugin.handle)


@plugin.route("/musicmp3/albums_main/<sort>")
def musicmp3_albums_main(sort):
_directory_items = []
for i, gnr in enumerate(gnr_ids):
li = ListItem("{0} {1} Albums".format(sort.title(), gnr[0]))
li = xbmcgui.ListItem("{0} {1} Albums".format(sort.title(), gnr[0]))
li.setArt(
{
"fanart": FANART,
Expand All @@ -78,8 +84,8 @@ def musicmp3_albums_main(sort):
)
_directory_items.append((plugin.url_for(musicmp3_albums_gnr, sort, i), li, True))

addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
endOfDirectory(plugin.handle)
xbmcplugin.addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
xbmcplugin.endOfDirectory(plugin.handle)


@plugin.route("/musicmp3/albums_gnr/<sort>/<gnr>")
Expand All @@ -93,7 +99,7 @@ def musicmp3_albums_gnr(sort, gnr):
else:
section = "main"

li = ListItem("{0} {1} Albums".format(sort.title(), sub_gnr[0]))
li = xbmcgui.ListItem("{0} {1} Albums".format(sort.title(), sub_gnr[0]))
li.setArt(
{
"fanart": FANART,
Expand All @@ -107,15 +113,15 @@ def musicmp3_albums_gnr(sort, gnr):
)
_directory_items.append((plugin.url_for(musicmp3_main_albums, section, sub_gnr[1], sort, "0"), li, True))

addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
endOfDirectory(plugin.handle)
xbmcplugin.addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
xbmcplugin.endOfDirectory(plugin.handle)


@plugin.route("/musicmp3/artists_main")
def musicmp3_artist_main():
_directory_items = []
for i, gnr in enumerate(gnr_ids):
li = ListItem("{0} Artists".format(gnr[0]))
li = xbmcgui.ListItem("{0} Artists".format(gnr[0]))
li.setArt(
{
"fanart": FANART,
Expand All @@ -126,8 +132,8 @@ def musicmp3_artist_main():
)
_directory_items.append((plugin.url_for(musicmp3_artists_gnr, i), li, True))

addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
endOfDirectory(plugin.handle)
xbmcplugin.addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
xbmcplugin.endOfDirectory(plugin.handle)


@plugin.route("/musicmp3/artists_gnr/<gnr>")
Expand All @@ -139,7 +145,7 @@ def musicmp3_artists_gnr(gnr):
elif sub_gnr[0] == "Soundtracks":
continue

li = ListItem("{0} Artists".format(sub_gnr[0]))
li = xbmcgui.ListItem("{0} Artists".format(sub_gnr[0]))
li.setArt(
{
"fanart": FANART,
Expand All @@ -153,8 +159,8 @@ def musicmp3_artists_gnr(gnr):
)
_directory_items.append((plugin.url_for(musicmp3_main_artists, sub_gnr[1], "0"), li, True))

addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
endOfDirectory(plugin.handle)
xbmcplugin.addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
xbmcplugin.endOfDirectory(plugin.handle)


@plugin.route("/musicmp3/search/<cat>")
Expand All @@ -169,13 +175,13 @@ def musicmp3_search(cat):
if cat == "artists":
artists = musicmp3_api.search(keyboardinput, cat)
for a in artists:
li = ListItem(a.get("artist"))
li = xbmcgui.ListItem(a.get("artist"))
li.setInfo("music", {"title": a.get("artist"), "artist": a.get("artist")})
_directory_items.append((plugin.url_for(artists_albums, quote(a.get("link"))), li, True))
elif cat == "albums":
albums = musicmp3_api.search(keyboardinput, cat)
for a in albums:
li = ListItem("{0}[CR][COLOR=darkmagenta]{1}[/COLOR]".format(a.get("title"), a.get("artist")))
li = xbmcgui.ListItem("{0}[CR][COLOR=darkmagenta]{1}[/COLOR]".format(a.get("title"), a.get("artist")))
li.setArt({"thumb": a.get("image"), "icon": a.get("image")})
li.setInfo(
"music",
Expand All @@ -189,11 +195,11 @@ def musicmp3_search(cat):
li.setProperty("Album_Description", a.get("details"))
_directory_items.append((plugin.url_for(musicmp3_album, quote(a.get("link"))), li, True))

addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
setContent(plugin.handle, "albums")
xbmcplugin.addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
xbmcplugin.setContent(plugin.handle, "albums")
if fixed_view_mode:
executebuiltin("Container.SetViewMode({0})".format(albums_view_mode))
endOfDirectory(plugin.handle)
xbmc.executebuiltin("Container.SetViewMode({0})".format(albums_view_mode))
xbmcplugin.endOfDirectory(plugin.handle)


@plugin.route("/musicmp3/main_albums/<section>/<gnr_id>/<sort>/<index>/dir")
Expand All @@ -207,25 +213,10 @@ def musicmp3_main_albums(section, gnr_id, sort, index):
_section = section
albums = musicmp3_api.main_albums(_section, gnr_id, sort, index, dir_items)

#context_menu = []
#if len(albums) >= dir_items:
#next_index = str(index + dir_items)
#next_page = "ActivateWindow(Music,{0})".format(
#plugin.url_for(musicmp3_main_albums, section, gnr_id, sort, next_index)
#)
#context_menu.append(("Next {0}+".format(next_index), next_page))
#previous_index = str(index - dir_items)
#if int(previous_index) >= 0:
#previous_page = "ActivateWindow(Music,{0})".format(
#plugin.url_for(musicmp3_main_albums, section, gnr_id, sort, previous_index)
#)
#context_menu.append(("Previous {0}+".format(previous_index), previous_page))

_directory_items = []
for a in albums:
li = ListItem("{0}[CR][COLOR=darkmagenta]{1}[/COLOR]".format(a.get("title"), a.get("artist")))
li = xbmcgui.ListItem("{0}[CR][COLOR=darkmagenta]{1}[/COLOR]".format(a.get("title"), a.get("artist")))
li.setArt({"thumb": a.get("image"), "icon": a.get("image")})
#li.addContextMenuItems(context_menu)
li.setInfo(
"music",
{"title": a.get("title"), "artist": a.get("artist"), "album": a.get("title"), "year": a.get("date")},
Expand All @@ -235,15 +226,15 @@ def musicmp3_main_albums(section, gnr_id, sort, index):
""" Next Page """
if len(albums) >= dir_items:
next_index = str(index + dir_items)
li = ListItem("More {0}+".format(next_index))
li = xbmcgui.ListItem("More {0}+".format(next_index))
l = plugin.url_for(musicmp3_main_albums, section, gnr_id, sort, next_index)
_directory_items.append((l, li, True))

addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
setContent(plugin.handle, "albums")
xbmcplugin.addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
xbmcplugin.setContent(plugin.handle, "albums")
if fixed_view_mode:
executebuiltin("Container.SetViewMode({0})".format(albums_view_mode))
endOfDirectory(plugin.handle)
xbmc.executebuiltin("Container.SetViewMode({0})".format(albums_view_mode))
xbmcplugin.endOfDirectory(plugin.handle)


@plugin.route("/musicmp3/main_artists/<gnr_id>/<index>/dir")
Expand All @@ -253,36 +244,25 @@ def musicmp3_main_artists(gnr_id, index):
index = int(index)
artists = musicmp3_api.main_artists(gnr_id, index, dir_items)

#context_menu = []
#if len(artists) >= dir_items:
#next_index = str(index + dir_items)
#next_page = "ActivateWindow(Music,{0})".format(plugin.url_for(musicmp3_main_artists, gnr_id, next_index))
#context_menu.append(("Next {0}+".format(next_index), next_page))
#previous_index = str(index - dir_items)
#if int(previous_index) >= 0:
#previous_page = "ActivateWindow(Music,{0})".format(plugin.url_for(musicmp3_main_artists, gnr_id, previous_index))
#context_menu.append(("Previous {0}+".format(previous_index), previous_page))

_directory_items = []
for a in artists:
li = ListItem(a.get("artist"))
li = xbmcgui.ListItem(a.get("artist"))
li.setInfo("music", {"title": a.get("artist"), "artist": a.get("artist")})
li.setProperty("Album_Artist", a.get("artist"))
#li.addContextMenuItems(context_menu)
_directory_items.append((plugin.url_for(artists_albums, quote(a.get("link"))), li, True))

""" Next Page """
if len(artists) >= dir_items:
next_index = str(index + dir_items)
li = ListItem("More {0}+".format(next_index))
li = xbmcgui.ListItem("More {0}+".format(next_index))
l = plugin.url_for(musicmp3_main_artists, gnr_id, next_index)
_directory_items.append((l, li, True))

addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
setContent(plugin.handle, "albums")
xbmcplugin.addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
xbmcplugin.setContent(plugin.handle, "albums")
if fixed_view_mode:
executebuiltin("Container.SetViewMode({0})".format(albums_view_mode))
endOfDirectory(plugin.handle)
xbmc.executebuiltin("Container.SetViewMode({0})".format(albums_view_mode))
xbmcplugin.endOfDirectory(plugin.handle)


@plugin.route("/musicmp3/artists_albums/<link>")
Expand All @@ -293,7 +273,7 @@ def artists_albums(link):

_directory_items = []
for a in albums:
li = ListItem("{0}[CR][COLOR=darkmagenta]{1}[/COLOR]".format(a.get("title"), a.get("artist")))
li = xbmcgui.ListItem("{0}[CR][COLOR=darkmagenta]{1}[/COLOR]".format(a.get("title"), a.get("artist")))
li.setArt({"thumb": a.get("image"), "icon": a.get("image")})
li.setInfo(
"music",
Expand All @@ -302,11 +282,11 @@ def artists_albums(link):
li.setProperty("Album_Description", a.get("details"))
_directory_items.append((plugin.url_for(musicmp3_album, quote(a.get("link"))), li, True))

addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
setContent(plugin.handle, "albums")
xbmcplugin.addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
xbmcplugin.setContent(plugin.handle, "albums")
if fixed_view_mode:
executebuiltin("Container.SetViewMode({0})".format(albums_view_mode))
endOfDirectory(plugin.handle)
xbmc.executebuiltin("Container.SetViewMode({0})".format(albums_view_mode))
xbmcplugin.endOfDirectory(plugin.handle)


@plugin.route("/musicmp3/album/<link>")
Expand All @@ -322,32 +302,32 @@ def musicmp3_album(link):
"album": t.get("album"),
"duration": t.get("duration"),
}
li = ListItem(t.get("title"))
li = xbmcgui.ListItem(t.get("title"))
li.setProperty("IsPlayable", "true")
li.setArt({"thumb": t.get("image"), "icon": t.get("image")})
li.setInfo("music", _infolabels)
_directory_items.append(
(plugin.url_for(musicmp3_play, track_id=t.get("track_id"), rel=t.get("rel")), li, False)
)

addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
setContent(plugin.handle, "songs")
xbmcplugin.addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
xbmcplugin.setContent(plugin.handle, "songs")
if fixed_view_mode:
executebuiltin("Container.SetViewMode({0})".format(songs_view_mode))
endOfDirectory(plugin.handle)
xbmc.executebuiltin("Container.SetViewMode({0})".format(songs_view_mode))
xbmcplugin.endOfDirectory(plugin.handle)


@plugin.route("/musicmp3/play/<track_id>/<rel>")
def musicmp3_play(track_id, rel):
musicmp3_api = musicMp3(MUSICMP3_DIR)
_track = musicmp3_api.get_track(rel)
_infolabels = {"title": _track.title, "artist": _track.artist, "album": _track.album, "duration": _track.duration}
li = ListItem(_track.title, path=musicmp3_api.play_url(track_id, rel))
li = xbmcgui.ListItem(_track.title, path=musicmp3_api.play_url(track_id, rel))
li.setInfo("music", _infolabels)
li.setArt({"thumb": _track.image, "icon": _track.image})
li.setMimeType("audio/mpeg")
li.setContentLookup(False)
setResolvedUrl(plugin.handle, True, li)
xbmcplugin.setResolvedUrl(plugin.handle, True, li)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 8ed0095

Please sign in to comment.