Commit eac0f17f authored by Jean-Francois Dockes's avatar Jean-Francois Dockes
Browse files

mediaserver/deezer: fleshed out the deezer module

parent 35354065
......@@ -89,7 +89,7 @@ def urls_from_id(view_func, items):
for item in items if str(item.id).find('http') != 0]
def view(data_items, urls, end=True):
def view(data_items, urls):
for item, url in zip(data_items, urls):
title = item.name
try:
......@@ -118,28 +118,68 @@ def track_list(tracks):
def root():
if not maybelogin():
return []
add_directory('Favourites', my_music)
@plugin.route('/my_music')
def my_music():
add_directory('Albums', favourite_albums)
add_directory('Playlists', favourite_playlists)
xbmcplugin.endOfDirectory(plugin.handle)
add_directory('My Favourites Albums', my_favourite_albums)
add_directory('My Favourites Playlists', my_favourite_playlists)
add_directory('My Favourites Tracks', my_favourite_tracks)
add_directory('My Favourites Artists', my_favourite_artists)
add_directory('My Favourites Playlists', my_favourite_playlists)
add_directory('Family', my_family)
@plugin.route('/my_family')
def my_family():
items = sess.get_followings()
view(items, urls_from_id(user_view, items))
@plugin.route('/my_favourite_albums')
def my_favourite_albums():
items = sess.get_favourite_albums()
view(items, urls_from_id(album_view, items))
@plugin.route('/favourite_playlists')
def favourite_playlists():
@plugin.route('/my_favourite_playlists')
def my_favourite_playlists():
items = sess.get_favourite_playlists()
view(items, urls_from_id(userplaylist_view, items))
view(items, urls_from_id(playlist_view, items))
@plugin.route('/favourite_albums')
def favourite_albums():
items = sess.get_favourite_albums()
@plugin.route('/my_favourite_artists')
def my_favourite_artists():
items = sess.get_favourite_artists()
view(items, urls_from_id(artist_view, items))
@plugin.route('/my_favourite_tracks')
def my_favourite_tracks():
track_list(sess.get_favourite_tracks())
@plugin.route('/favourite_albums/<id>')
def favourite_albums(id):
items = sess.get_favourite_albums(id)
view(items, urls_from_id(album_view, items))
@plugin.route('/favourite_playlists/<id>')
def favourite_playlists(id):
items = sess.get_favourite_playlists(id)
view(items, urls_from_id(playlist_view, items))
@plugin.route('/favourite_artists/<id>')
def favourite_artists(id):
items = sess.get_favourite_artists(id)
view(items, urls_from_id(artist_view, items))
@plugin.route('/favourite_tracks/<id>')
def favourite_tracks(id):
track_list(sess.get_favourite_tracks(id))
@plugin.route('/userplaylist/<id>')
def userplaylist_view(id):
def playlist_view(id):
track_list(sess.get_user_playlist(id))
@plugin.route('/user/<id>')
def user_view(id):
add_directory('Albums', plugin.url_for(favourite_albums, id))
add_directory('Playlists', plugin.url_for(favourite_playlists, id))
add_directory('Tracks', plugin.url_for(favourite_tracks, id))
add_directory('Artists', plugin.url_for(favourite_artists, id))
@plugin.route('/artist/<artist_id>')
def artist_view(artist_id):
albums = sess.get_artist_albums(artist_id)
......@@ -207,10 +247,10 @@ def search(a):
if (not objkind or objkind == 'artist') and searchresults.artists:
view(searchresults.artists,
urls_from_id(artist_view, searchresults.artists), end=False)
urls_from_id(artist_view, searchresults.artists))
if (not objkind or objkind == 'album') and searchresults.albums:
view(searchresults.albums,
urls_from_id(album_view, searchresults.albums), end=False)
urls_from_id(album_view, searchresults.albums))
if (not objkind or objkind == 'track') and searchresults.tracks:
track_list(searchresults.tracks)
......
......@@ -22,7 +22,6 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# Deezer low level interface and session management. We return barely
# prepared json objects
......@@ -181,16 +180,41 @@ class DeezerAPI(object):
return False
def getUserPlaylists(self, **ka):
def getUserFollowings(self):
if not self.isloggedin():
return {}
return self._api_request('user', self.user_id, 'followings')
def getUserPlaylists(self, id='me'):
if not self.isloggedin():
return {}
if id == 'me':
id = self.user_id
data = self._api_request('user', id, 'playlists')
return data
def getUserAlbums(self, id='me'):
if not self.isloggedin():
return {}
if id == 'me':
id = self.user_id
data = self._api_request('user', id, 'albums')
return data
def getUserArtists(self, id='me'):
if not self.isloggedin():
return {}
data = self._api_request('user', self.user_id, 'playlists')
if id == 'me':
id = self.user_id
data = self._api_request('user', id, 'artists')
return data
def getUserAlbums(self, **ka):
def getUserTracks(self, id='me'):
if not self.isloggedin():
return {}
data = self._api_request('user', self.user_id, 'albums')
if id == 'me':
id = self.user_id
data = self._api_request('user', id, 'tracks')
return data
def getArtistAlbums(self, artid):
......
# defined to emulate the session object from the tidal module, which is
# defined in the tidalapi part (we want to keep the qobuz api/ dir as
# much alone as possible.
#
# Copyright (C) 2021 Jean-Francois Dockes
#
# A lot of code strongly inspired or copied from the Kodi Deezer API,
# the copyright of which is not too clear (but it's GPL):
# Copyright (C) 2016 Jakub Gawron
# Copyright (C) 2020 Valentin271 (Github.com)
#
# 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 2 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, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Performs some massaging of the data out from the lower level api
# interface and creates objects defined in the upmplgmodels.py module.
#
from __future__ import print_function
import sys
import json
from upmplgmodels import Artist, Album, Track, Playlist, SearchResult, \
Category, Genre, Model
Category, Genre, Model, User
from upmplgutils import *
import deezerapi
import urllib
import datetime
import traceback
import base64
class Session(object):
def __init__(self):
......@@ -25,23 +46,34 @@ class Session(object):
else:
return False
def isloggedin(self):
return self.api.isloggedin()
def get_media_url(self, trackid):
return self.api.request_stream(id=trackid)
def get_favourite_playlists(self):
data = self.api.getUserPlaylists()
def get_followings(self):
data = self.api.getUserFollowings()
return [_parse_user(p) for p in data['data']]
def get_favourite_playlists(self, id='me'):
data = self.api.getUserPlaylists(id=id)
if not data:
return []
return [_parse_playlist(p) for p in data['data']]
def get_favourite_albums(self):
data = self.api.getUserAlbums()
def get_favourite_albums(self, id='me'):
data = self.api.getUserAlbums(id=id)
return [_parse_album(p) for p in data['data']]
def get_favourite_artists(self, id='me'):
data = self.api.getUserArtists(id=id)
return [_parse_artist(p) for p in data['data']]
def get_favourite_tracks(self, id='me'):
data = self.api.getUserTracks(id=id)
return [_parse_track(p) for p in data['data']]
def get_artist_albums(self, artid):
data = self.api.getArtistAlbums(artid)
return [_parse_album(p) for p in data['data']]
......@@ -134,11 +166,11 @@ def _parse_playlist(data, artist=None, artists=None):
def _parse_artist(data):
return Artist(id=data['id'], name=data['name'])
def _parse_user(data):
return User(id=data['id'], name=data['name'], image=data['picture'])
def _parse_album(data):
#uplog(data)
#uplog("-_"*30)
def _parse_album(data):
kwargs = {
'id': data['id'],
'name': data['title']
......@@ -181,4 +213,3 @@ def _parse_track(data, albumarg = None):
kwargs['image'] = data['picture_big']
return Track(**kwargs)
......@@ -30,7 +30,11 @@ class Model(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
class User(Model):
upnpclass = "object.container"
name = "Unknown"
image = None
class Album(Model):
upnpclass = "object.container.album.musicAlbum"
name = "Unknown"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment