Skip to content

Commit

Permalink
v3
Browse files Browse the repository at this point in the history
  • Loading branch information
L2501 committed Apr 27, 2019
1 parent 64533a8 commit a80f20a
Show file tree
Hide file tree
Showing 3 changed files with 354 additions and 280 deletions.
4 changes: 2 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.audio.m3sr2019" name="MP3 Streams Reloaded" version="2" provider-name="MP3 Streams">
<addon id="plugin.audio.m3sr2019" name="MP3 Streams Reloaded" version="3" 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.requests" />
<import addon="script.module.requests-cache" />
<import addon="script.module.routing" />
</requires>
<extension point="xbmc.python.pluginsource" library="default.py">
<provides>audio</provides>
</extension>
<extension point="xbmc.addon.metadata">
<reuselanguageinvoker>true</reuselanguageinvoker>
<platform>all</platform>
<license>GPL-2.0</license>
<summary>A music streaming collection</summary>
Expand Down
126 changes: 95 additions & 31 deletions default.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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 resources.lib.musicmp3 import musicMp3
from resources.lib.musicmp3 import musicMp3, gnr_ids


try:
Expand All @@ -29,7 +30,9 @@ def unquote(s):
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")
MEDIA_DIR = os.path.join(
xbmc.translatePath(xbmcaddon.Addon().getAddonInfo("path")).decode("utf-8"), "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 @@ -39,8 +42,6 @@ def unquote(s):
albums_view_mode = addon.getSetting("albums_view_mode")
songs_view_mode = addon.getSetting("songs_view_mode")

musicmp3_api = musicMp3(MUSICMP3_DIR)


@plugin.route("/")
def index():
Expand All @@ -64,16 +65,27 @@ def index():

@plugin.route("/musicmp3/albums_main/<sort>")
def musicmp3_albums_main(sort):
for i, gnr in enumerate(musicmp3_api.gnr_ids):
_directory_items = []
for i, gnr in enumerate(gnr_ids):
li = ListItem("{0} {1} Albums".format(sort.title(), gnr[0]))
li.setArt({"fanart": FANART, "icon": os.path.join(MEDIA_DIR, "genre", "{0}.jpg".format(gnr[0].lower().replace(" ", "").replace("&", "_")))})
addDirectoryItem(plugin.handle, plugin.url_for(musicmp3_albums_gnr, sort, i), li, True)
li.setArt(
{
"fanart": FANART,
"icon": os.path.join(
MEDIA_DIR, "genre", "{0}.jpg".format(gnr[0].lower().replace(" ", "").replace("&", "_"))
),
}
)
_directory_items.append((plugin.url_for(musicmp3_albums_gnr, sort, i), li, True))

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


@plugin.route("/musicmp3/albums_gnr/<sort>/<gnr>")
def musicmp3_albums_gnr(sort, gnr):
for sub_gnr in musicmp3_api.gnr_ids[int(gnr)][1]:
_directory_items = []
for sub_gnr in gnr_ids[int(gnr)][1]:
if sub_gnr[0] == "Compilations":
section = "compilations"
elif sub_gnr[0] == "Soundtracks":
Expand All @@ -86,43 +98,61 @@ def musicmp3_albums_gnr(sort, gnr):
{
"fanart": FANART,
"icon": os.path.join(
MEDIA_DIR, "genre", musicmp3_api.gnr_ids[int(gnr)][0].lower(), "{0}.jpg".format(sub_gnr[0].lower().replace(" ", "").replace("&", "_"))
MEDIA_DIR,
"genre",
gnr_ids[int(gnr)][0].lower(),
"{0}.jpg".format(sub_gnr[0].lower().replace(" ", "").replace("&", "_")),
),
}
)
addDirectoryItem(plugin.handle, plugin.url_for(musicmp3_main_albums, section, sub_gnr[1], sort, "0"), li, True)
_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)


@plugin.route("/musicmp3/search/<cat>")
def musicmp3_search(cat):
musicmp3_api = musicMp3(MUSICMP3_DIR)
keyboard = xbmc.Keyboard("", "Search")
keyboard.doModal()
if keyboard.isConfirmed():
keyboardinput = keyboard.getText()
if keyboardinput:
_directory_items = []
if cat == "artists":
artists = musicmp3_api.search(keyboardinput, cat)
for a in artists:
li = ListItem(a.get("artist"))
li.setInfo("music", {"title": a.get("artist"), "artist": a.get("artist")})
addDirectoryItem(plugin.handle, plugin.url_for(artists_albums, quote(a.get("link"))), li, True)
_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.setArt({"thumb": a.get("image"), "icon": a.get("image")})
li.setInfo("music", {"title": a.get("title"), "artist": a.get("artist"), "album": a.get("title"), "year": a.get("date")})
li.setInfo(
"music",
{
"title": a.get("title"),
"artist": a.get("artist"),
"album": a.get("title"),
"year": a.get("date"),
},
)
li.setProperty("Album_Description", a.get("details"))
addDirectoryItem(plugin.handle, plugin.url_for(musicmp3_album, quote(a.get("link"))), li, True)
_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")
if fixed_view_mode:
executebuiltin("Container.SetViewMode({0})".format(albums_view_mode))
endOfDirectory(plugin.handle)


@plugin.route("/musicmp3/main_albums/<section>/<gnr_id>/<sort>/<index>")
@plugin.route("/musicmp3/main_albums/<section>/<gnr_id>/<sort>/<index>/")
def musicmp3_main_albums(section, gnr_id, sort, index):
musicmp3_api = musicMp3(MUSICMP3_DIR)
dir_items = 40
index = int(index)
if section == "main":
Expand All @@ -132,45 +162,62 @@ def musicmp3_main_albums(section, gnr_id, sort, index):
albums = musicmp3_api.main_albums(_section, gnr_id, sort, index, dir_items)

context_menu = []
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))
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))
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.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")})
addDirectoryItem(plugin.handle, plugin.url_for(musicmp3_album, quote(a.get("link"))), li, True)
li.setInfo(
"music",
{"title": a.get("title"), "artist": a.get("artist"), "album": a.get("title"), "year": a.get("date")},
)
_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")
if fixed_view_mode:
executebuiltin("Container.SetViewMode({0})".format(albums_view_mode))
endOfDirectory(plugin.handle)


@plugin.route("/musicmp3/main_artists/<index>")
@plugin.route("/musicmp3/main_artists/<index>/")
def musicmp3_main_artists(index):
musicmp3_api = musicMp3(MUSICMP3_DIR)
dir_items = 40
index = int(index)
artists = musicmp3_api.main_artists(index, dir_items)

context_menu = []
next_index = str(index + dir_items)
next_page = "ActivateWindow(Music,{0})".format(plugin.url_for(musicmp3_main_artists, next_index))
context_menu.append(("Next {0}+".format(next_index), next_page))
if len(artists) >= dir_items:
next_index = str(index + dir_items)
next_page = "ActivateWindow(Music,{0})".format(plugin.url_for(musicmp3_main_artists, 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, previous_index))
context_menu.append(("Previous {0}+".format(previous_index), previous_page))

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

addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
setContent(plugin.handle, "albums")
if fixed_view_mode:
executebuiltin("Container.SetViewMode({0})".format(albums_view_mode))
Expand All @@ -179,14 +226,22 @@ def musicmp3_main_artists(index):

@plugin.route("/musicmp3/artists_albums/<link>")
def artists_albums(link):
musicmp3_api = musicMp3(MUSICMP3_DIR)
url = unquote(link)
albums = musicmp3_api.artist_albums(url)

_directory_items = []
for a in albums:
li = 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", {"title": a.get("title"), "artist": a.get("artist"), "album": a.get("title"), "year": a.get("date")})
li.setInfo(
"music",
{"title": a.get("title"), "artist": a.get("artist"), "album": a.get("title"), "year": a.get("date")},
)
li.setProperty("Album_Description", a.get("details"))
addDirectoryItem(plugin.handle, plugin.url_for(musicmp3_album, quote(a.get("link"))), li, True)
_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")
if fixed_view_mode:
executebuiltin("Container.SetViewMode({0})".format(albums_view_mode))
Expand All @@ -195,18 +250,26 @@ def artists_albums(link):

@plugin.route("/musicmp3/album/<link>")
def musicmp3_album(link):
musicmp3_api = musicMp3(MUSICMP3_DIR)
url = unquote(link)
tracks = musicmp3_api.album_tracks(url)
_directory_items = []
for t in tracks:
_infolabels = {"title": t.get("title"), "artist": t.get("artist"), "album": t.get("album"), "duration": t.get("duration")}
_infolabels = {
"title": t.get("title"),
"artist": t.get("artist"),
"album": t.get("album"),
"duration": t.get("duration"),
}
li = 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))
_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)
addDirectoryItems(plugin.handle, _directory_items, len(_directory_items))
setContent(plugin.handle, "songs")
if fixed_view_mode:
executebuiltin("Container.SetViewMode({0})".format(songs_view_mode))
Expand All @@ -215,6 +278,7 @@ def musicmp3_album(link):

@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))
Expand All @@ -226,4 +290,4 @@ def musicmp3_play(track_id, rel):


if __name__ == "__main__":
plugin.run()
plugin.run(sys.argv)
Loading

0 comments on commit a80f20a

Please sign in to comment.