Example #1
0
 def remove(self):
     name = self.get_parameter('query')
     if name == 'qobuz.com':
         return False
     if not name:
         return False
     user = self.get_user_data()
     if not user:
         return False
     friends = user['player_settings']
     if not 'friends' in friends:
         notifyH('Qobuz', "You don't have friend", 'icon-error-256')
         warn(self, "No friends in user/player_settings")
         return False
     friends = friends['friends']
     if not name in friends:
         notifyH('Qobuz', "You're not friend with %s" % (name),
                 'icon-error-256')
         warn(self, "Friend " + repr(name) + " not in friends data")
         return False
     del friends[friends.index(name)]
     newdata = {'friends': friends}
     if not api.user_update(player_settings=json.dumps(newdata)):
         notifyH('Qobuz', 'Friend %s added' % (name))
         notifyH('Qobuz', "Cannot updata friend's list...",
                 'icon-error-256')
         return False
     notifyH('Qobuz', 'Friend %s removed' % (name))
     self.delete_cache()
     executeBuiltin(containerRefresh())
     return True
Example #2
0
 def _add_tracks(self, playlist_id, nodes):
     if len(nodes) < 1:
         warn(self, 'Empty list...')
         return False
     step = 50
     start = 0
     numtracks = len(nodes)
     if numtracks > 1000:
         notifyH('Qobuz', 'Max tracks per playlist reached (1000)'
                 '\nSkipping %s tracks' % (numtracks - 1000),
                 'icon-error-256')
         numtracks = 1000
     while start < numtracks:
         if (start + step) > numtracks:
             step = numtracks - start
         str_tracks = ''
         info(self, "Adding tracks start: %s, end: %s" %
              (start, start + step))
         for i in range(start, start + step):
             node = nodes[i]
             if node.nt != Flag.TRACK:
                 warn(self, "Not a Node_track node")
                 continue
             str_tracks += '%s,' % (str(node.nid))
         if not api.playlist_addTracks(
                             playlist_id=playlist_id, track_ids=str_tracks):
             return False
         start += step
     return True
Example #3
0
 def subscribe(self):
     if api.playlist_subscribe(playlist_id=self.nid):
         notifyH(lang(42001), lang(42005))
         self.delete_cache(self.nid)
         return True
     else:
         return False
Example #4
0
 def _add_tracks(self, playlist_id, nodes):
     if len(nodes) < 1:
         warn(self, 'Empty list...')
         return False
     step = 50
     start = 0
     numtracks = len(nodes)
     if numtracks > 1000:
         notifyH(
             'Qobuz', 'Max tracks per playlist reached (1000)'
             '\nSkipping %s tracks' % (numtracks - 1000), 'icon-error-256')
         numtracks = 1000
     while start < numtracks:
         if (start + step) > numtracks:
             step = numtracks - start
         str_tracks = ''
         info(self,
              "Adding tracks start: %s, end: %s" % (start, start + step))
         for i in range(start, start + step):
             node = nodes[i]
             if node.nt != Flag.TRACK:
                 warn(self, "Not a Node_track node")
                 continue
             str_tracks += '%s,' % (str(node.nid))
         if not api.playlist_addTracks(playlist_id=playlist_id,
                                       track_ids=str_tracks):
             return False
         start += step
     return True
Example #5
0
    def scan(self):
        import sys
        from node.flag import Flag

        """Building tree when using Xbmc library scanning 
        feature
        """
        from gui.directory import Directory

        if not self.set_root_node():
            warn(self, "Cannot set root node ('%s')" % (str(self.node_type)))
            return False
        handle = qobuz.boot.handle
        Dir = Directory(self.root, self.nodes, withProgress=False)
        Dir.handle = int(sys.argv[1])
        Dir.asList = False
        Dir.asLocalURL = True
        if self.root.nt & Flag.TRACK:
            self.root.fetch(None, None, Flag.TRACK, Flag.NONE)
            Dir.add_node(self.root)
        else:
            self.root.populating(Dir, self.depth, self.whiteFlag, self.blackFlag)
        Dir.set_content(self.root.content_type)
        Dir.end_of_directory()
        notifyH("Scanning results", str(Dir.total_put) + " items where scanned", 3000)
        return True
Example #6
0
 def scan(self):
     import sys
     from node.flag import Flag
     """Building tree when using Xbmc library scanning 
     feature
     """
     from gui.directory import Directory
     if not self.set_root_node():
         warn(self, "Cannot set root node ('%s')" % (str(self.node_type)))
         return False
     handle = qobuz.boot.handle
     Dir = Directory(self.root, self.nodes, withProgress=False)
     Dir.handle = int(sys.argv[1])
     Dir.asList = False
     Dir.asLocalURL = True
     if self.root.nt & Flag.TRACK:
         self.root.fetch(None, None, Flag.TRACK, Flag.NONE)
         Dir.add_node(self.root)
     else:
         self.root.populating(Dir, self.depth, self.whiteFlag,
                              self.blackFlag)
     Dir.set_content(self.root.content_type)
     Dir.end_of_directory()
     notifyH('Scanning results',
             str(Dir.total_put) + ' items where scanned', 3000)
     return True
Example #7
0
 def gui_add_to_current(self):
     cid = self.get_current_playlist()
     qnt = int(self.get_parameter('qnt'))
     qid = self.get_parameter('qid')
     nodes = []
     if qnt & Flag.SEARCH:
         self.del_parameter('query')
     if qnt & Flag.TRACK == Flag.TRACK:
         node = getNode(qnt, {'nid': qid})
         node.fetch(None, None, None, Flag.NONE)
         nodes.append(node)
     else:
         render = renderer(qnt, self.parameters)
         render.depth = -1
         render.whiteFlag = Flag.TRACK
         render.asList = True
         render.run()
         nodes = render.nodes
     ret = xbmcgui.Dialog().select('Add to current playlist', [
        node.get_label() for node in nodes                              
     ])
     if ret == -1:
         return False
     ret = self._add_tracks(cid, nodes)
     if not ret:
         notifyH('Qobuz', 
             'Failed to add tracks') 
         return False
     self.delete_cache(cid)
     notifyH('Qobuz / Tracks added', 
             '%s added' % (len(nodes))) 
     return True
Example #8
0
 def remove(self):
     name = self.get_parameter("query")
     if name == "qobuz.com":
         return False
     if not name:
         return False
     user = self.get_user_data()
     if not user:
         return False
     friends = user["player_settings"]
     if not "friends" in friends:
         notifyH("Qobuz", "You don't have friend", "icon-error-256")
         warn(self, "No friends in user/player_settings")
         return False
     friends = friends["friends"]
     if not name in friends:
         notifyH("Qobuz", "You're not friend with %s" % (name), "icon-error-256")
         warn(self, "Friend " + repr(name) + " not in friends data")
         return False
     del friends[friends.index(name)]
     newdata = {"friends": friends}
     if not api.user_update(player_settings=json.dumps(newdata)):
         notifyH("Qobuz", "Friend %s added" % (name))
         notifyH("Qobuz", "Cannot updata friend's list...", "icon-error-256")
         return False
     notifyH("Qobuz", "Friend %s removed" % (name))
     self.delete_cache()
     executeBuiltin(containerRefresh())
     return True
Example #9
0
 def gui_rename(self, playlist_id = None):
     if not playlist_id:
         playlist_id = self.nid
     if not playlist_id:
         warn(self, "Can't rename playlist without id")
         return False
     from gui.util import Keyboard
     data = api.get('/playlist/get', playlist_id=playlist_id)
     if not data:
         warn(self, "Something went wrong while renaming playlist")
         return False
     self.data = data
     currentname = self.get_name()
     k = Keyboard(currentname, lang(30078))
     k.doModal()
     if not k.isConfirmed():
         return False
     newname = k.getText()
     newname = newname.strip()
     if not newname:
         notifyH(dialogHeading, "Don't u call ure child something?", 
                 'icon-error-256')
         return False
     if newname == currentname:
         return True
     res = api.playlist_update(playlist_id=playlist_id, name=newname)
     if not res:
         warn(self, "Cannot rename playlist with name %s" % (newname) )
         return False
     self.delete_cache(playlist_id)
     notifyH(lang(30078), (u"%s: %s") % (lang(39009), currentname))
     executeBuiltin(containerRefresh())
     return True
Example #10
0
 def gui_remove_track(self):
     qid = self.get_parameter('qid')
     print "Removing track %s from playlist %s" % (qid, self.nid)
     if not self.remove_tracks(qid):
         notifyH(dialogHeading, 'Cannot remove track!', 'icon-error-256')
         return False
     self.delete_cache(self.nid)
     print "Error API: %s (%s)" % (api.error, api.status_code)
     notifyH(dialogHeading, 'Track removed from playlist')
     executeBuiltin(containerRefresh())
     return True
Example #11
0
 def cache_remove(self):
     '''GUI/Removing all cached data
     '''
     from gui.util import yesno, notifyH, getImage
     from debug import log
     if not yesno(lang(30121), lang(30122)):
         log(self, "Deleting cached data aborted")
         return False
     if clean_all(cache):
         notifyH(lang(30119), lang(30123))
     else:
         notifyH(lang(30119), lang(30120),
                 getImage('icon-error-256'))
     return True
Example #12
0
 def gui_create(self):
     name = self.get_parameter('query')
     if not name:
         from gui.util import Keyboard
         kb = Keyboard('', str(lang(41102)))
         kb.doModal()
         name = ''
         if not kb.isConfirmed():
             return False
         name = kb.getText().strip()
     if not name:
         return False
     if not self.create(name):
         notifyH('Qobuz', 'Cannot add friend %s' % (name))
         return False
     notifyH('Qobuz', 'Friend %s added' % (name))
     return True
Example #13
0
    def gui_create(self):
        name = self.get_parameter("query")
        if not name:
            from gui.util import Keyboard

            kb = Keyboard("", str(lang(41102)))
            kb.doModal()
            name = ""
            if not kb.isConfirmed():
                return False
            name = kb.getText().strip()
        if not name:
            return False
        if not self.create(name):
            notifyH("Qobuz", "Cannot add friend %s" % (name))
            return False
        notifyH("Qobuz", "Friend %s added" % (name))
        return True
Example #14
0
    def play(self, track_id):
        track = getNode(Flag.TRACK, {'nid': track_id})
        if not track.fetch(None, 1, Flag.TRACK, Flag.NONE):
            warn(self, "Cannot get track data")
#            label = "Maybe an invalid track id"
#            item = xbmcgui.ListItem("No track information", label, '', 
#                                    getImage('icon-error-256'), '')
            return False
        if not track.is_playable():
            warn(self, "Cannot get streaming URL")
            return False
        item = track.makeListItem()
        track.item_add_playing_property(item)
        '''Some tracks are not authorized for stream and a 60s sample is
        returned, in that case we overwrite the song duration
        '''
        if track.is_sample():
            item.setInfo(
                'music', infoLabels={
                'duration': 60,
            })
            '''Don't warn for free account (all songs except purchases are 60s
            limited)
            '''
            if not isFreeAccount():
                notifyH("Qobuz", "Sample returned")
        xbmcgui.Window(10000).setProperty(keyTrackId, track_id) 
        """
            Notify
        """
        if getSetting('notification_playingsong', isBool=True):
            notifyH(lang(34000), track.get_label(), track.get_image())
        """
            We are called from playlist...
        """
        if qobuz.boot.handle == -1:
            super(QobuzPlayer, self).play(track.get_streaming_url(), 
                                          item, False)
        else:
            setResolvedUrl(handle=qobuz.boot.handle,
                succeeded=True,
                listitem=item)
        return True
Example #15
0
 def play(self, track_id):
     track = getNode(Flag.TRACK, {'nid': track_id})
     if not track.fetch(None, 1, Flag.TRACK, Flag.NONE):
         warn(self, "Cannot get track data")
         #            label = "Maybe an invalid track id"
         #            item = xbmcgui.ListItem("No track information", label, '',
         #                                    getImage('icon-error-256'), '')
         return False
     if not track.is_playable():
         warn(self, "Cannot get streaming URL")
         return False
     item = track.makeListItem()
     track.item_add_playing_property(item)
     '''Some tracks are not authorized for stream and a 60s sample is
     returned, in that case we overwrite the song duration
     '''
     if track.is_sample():
         item.setInfo('music', infoLabels={
             'duration': 60,
         })
         '''Don't warn for free account (all songs except purchases are 60s
         limited)
         '''
         if not isFreeAccount():
             notifyH("Qobuz", "Sample returned")
     xbmcgui.Window(10000).setProperty(keyTrackId, track_id)
     """
         Notify
     """
     if getSetting('notification_playingsong', isBool=True):
         notifyH(lang(34000), track.get_label(), track.get_image())
     """
         We are called from playlist...
     """
     if qobuz.boot.handle == -1:
         super(QobuzPlayer, self).play(track.get_streaming_url(), item,
                                       False)
     else:
         setResolvedUrl(handle=qobuz.boot.handle,
                        succeeded=True,
                        listitem=item)
     return True
Example #16
0
 def gui_remove(self):
     qnt, qid = int(self.get_parameter('qnt')), self.get_parameter('qid')
     node = getNode(qnt, {'nid': qid})
     ret = None
     if qnt & Flag.TRACK == Flag.TRACK:
         ret = self.del_track(node.nid)
     elif qnt & Flag.ALBUM == Flag.ALBUM:
         ret = self.del_album(node.nid)
     elif qnt & Flag.ARTIST == Flag.ARTIST:
         ret = self.del_artist(node.nid)
     else:
         raise Qerror(who=self, what='invalid_node_type',
                      additional=self.nt)
     if not ret:
         notifyH(dialogHeading,
                 'Cannot remove item: %s' % (node.get_label()))
         return False
     notifyH(dialogHeading,
                 'Item successfully removed: %s' % (node.get_label()))
     url = self.make_url(nt=self.nt, nid='', nm='')
     executeBuiltin(containerUpdate(url, True))
     return True
Example #17
0
 def gui_add_albums(self):
     qnt, qid = int(self.get_parameter('qnt')), self.get_parameter('qid')
     nodes = self.list_albums(qnt, qid)
     if len(nodes) == 0:
         notifyH(dialogHeading, lang(36004))
         return False
     ret = xbmcgui.Dialog().select(lang(36005), [
        node.get_label() for node in nodes                              
     ])
     if ret == -1:
         return False
     album_ids = ','.join([node.nid for node in nodes])
     if not self.add_albums(album_ids):
         notifyH(dialogHeading, 'Cannot add album(s) to favorite')
         return False
     notifyH(dialogHeading, 'Album(s) added to favorite')
     return True
Example #18
0
 def gui_add_tracks(self):
     qnt, qid = int(self.get_parameter('qnt')), self.get_parameter('qid')
     nodes = self.list_tracks(qnt, qid)
     if len(nodes) == 0:
         notifyH(dialogHeading, lang(3600))
         return False
     ret = xbmcgui.Dialog().select(lang(36006), [
        node.get_label() for node in nodes                              
     ])
     if ret == -1:
         return False
     track_ids = ','.join([str(node.nid) for node in nodes])
     if not self.add_tracks(track_ids):
         notifyH(dialogHeading, 'Cannot add track(s) to favorite')
         return False
     notifyH(dialogHeading, 'Track(s) added to favorite')
     return True
Example #19
0
 def gui_add_artists(self):
     qnt, qid = int(self.get_parameter('qnt')), self.get_parameter('qid')
     nodes = self.list_artists(qnt, qid)
     if len(nodes) == 0:
         notifyH(dialogHeading, lang(30143))
         return False
     ret = xbmcgui.Dialog().select(lang(30146), [
        node.get_label() for node in nodes
     ])
     if ret == -1:
         return False
     artist_ids = ','.join([str(node.nid) for node in nodes])
     if not self.add_artists(artist_ids):
         notifyH(dialogHeading, 'Cannot add artist(s) to favorite')
         return False
     self._delete_cache()
     notifyH(dialogHeading, 'Artist(s) added to favorite')
     return True
Example #20
0
    def gui_remove(self, playlist_id=None):
        if not playlist_id:
            playlist_id = self.nid
        if not playlist_id:
            notifyH(dialogHeading, 'Invalid playlist %s' % (str(playlist_id)))
            return False
#         import xbmcgui  # @UnresolvedImport
#         import xbmc  # @UnresolvedImport
#         cid = self.get_current_playlist()
        login = getSetting('username')
        offset = 0
        limit = getSetting('pagination_limit')
        data = api.get('/playlist/get',
                       playlist_id=playlist_id,
                       limit=limit,
                       offset=offset)
        name = ''
        if 'name' in data:
            name = data['name']
        ok = xbmcgui.Dialog().yesno(lang(30166), lang(30054),
                                    color('FFFF0000', name))
        if not ok:
            info(self, "Deleting playlist aborted...")
            return False
        res = False
        if data['owner']['name'] == login:
            info(self, "Deleting playlist: " + str(playlist_id))
            res = api.playlist_delete(playlist_id=playlist_id)
        else:
            info(self, 'Unsuscribe playlist' + str(playlist_id))
            res = api.playlist_unsubscribe(playlist_id=playlist_id)
        if not res:
            warn(self, "Cannot delete playlist with id " + str(playlist_id))
            notifyH(lang(30183),
                    lang(30186) + name, getImage('icon-error-256'))
            return False
        self.delete_cache(playlist_id)
        notifyH(lang(30183), (lang(30184) + "%s" + lang(30185)) % (name))
        url = self.make_url(nt=Flag.USERPLAYLISTS,
                            mode=Mode.VIEW,
                            nm='',
                            nid='')
        executeBuiltin(containerUpdate(url, True))
        return False
Example #21
0
 def gui_remove(self, playlist_id=None):
     if not playlist_id:
         playlist_id = self.nid
     if not playlist_id:
         notifyH(dialogHeading, 'Invalid playlist %s' % (str(playlist_id)))
         return False
     import xbmcgui
     import xbmc
     cid = self.get_current_playlist()
     login = getSetting('username')
     offset = 0
     limit = getSetting('pagination_limit')
     data = api.get('/playlist/get', playlist_id=playlist_id, limit=limit,
                    offset=offset)
     name = ''
     if 'name' in data:
         name = data['name']
     ok = xbmcgui.Dialog().yesno(lang(39010),
                                 lang(30052),
                                 color('FFFF0000', name))
     if not ok:
         info(self, "Deleting playlist aborted...")
         return False
     res = False
     if data['owner']['name'] == login:
         info(self, "Deleting playlist: " + str(playlist_id))
         res = api.playlist_delete(playlist_id=playlist_id)
     else:
         info(self, 'Unsuscribe playlist' + str(playlist_id))
         res = api.playlist_unsubscribe(playlist_id=playlist_id)
     if not res:
         warn(self, "Cannot delete playlist with id " + str(playlist_id))
         notifyH(lang(42001), lang(42004) +
                 name, getImage('icon-error-256'))
         return False
     self.delete_cache(playlist_id)
     notifyH(lang(42001), (lang(42002) + "%s" + lang(42003)) % (name))
     url = self.make_url(nt=Flag.USERPLAYLISTS, mode=Mode.VIEW, nm='', 
                         nid='')
     executeBuiltin(containerUpdate(url, True))
     return False
Example #22
0
 def gui_add_as_new(self, name=None):
     nodes = []
     qnt = int(self.get_parameter('qnt'))
     qid = self.get_parameter('qid')
     if qnt & Flag.SEARCH:
         self.del_parameter('query')
     if qnt & Flag.TRACK == Flag.TRACK:
         node = getNode(qnt, {'nid': qid})
         node.fetch(None,None,None, Flag.NONE)
         nodes.append(node)
     else:
         render = renderer(qnt, self.parameters)
         render.depth = -1
         render.whiteFlag = Flag.TRACK
         render.asList = True
         render.run()
         nodes = render.nodes
         if not name and render.root.get_parameter('query', unQuote=True):
             name = render.root.get_parameter('query', unQuote=True)
     if not name:
         name = self.get_parameter('query', 
                                   unQuote=True) or self.get_label()
     ret = xbmcgui.Dialog().select('Create playlist %s' % (name), [
        node.get_label() for node in nodes                              
     ])
     if ret == -1:
         return False
     playlist = self.create(name)
     if not playlist:
         notifyH('Qobuz', 'Playlist creationg failed', 'icon-error-256')
         warn(self, "Cannot create playlist...")
         return False
     if not self._add_tracks(playlist['id'], nodes):
         notifyH('Qobuz / Cannot add tracks', 
                 "%s" % (name), 'icon-error-256')
         return False
     self.delete_cache(playlist['id'])
     notifyH('Qobuz / Playlist added', 
             '[%s] %s' % (len(nodes), name)) 
     return True