示例#1
0
    def dispatch(self):
        """Routing based on parameters
        """
        if self.MODE == Mode.PLAY:
            from player import QobuzPlayer
            debug(self, "Playing song")
            player = QobuzPlayer()
            if player.play(self.params['nid']):
                return True
            return False

        from renderer import renderer

        if self.MODE == Mode.VIEW:
            r = renderer(self.nodeType, self.params)
            return r.run()
        elif self.MODE == Mode.VIEW_BIG_DIR:
            r = renderer(self.nodeType, self.params)
            r.whiteFlag = Flag.TRACK | Flag.ALBUM
            r.depth = -1
            return r.run()
        elif self.MODE == Mode.SCAN:
            r = renderer(self.nodeType, self.params)
            r.enable_progress = False
            r.whiteFlag = Flag.TRACK 
            r.depth = -1
            return r.scan()
        else:
            raise QobuzXbmcError(
                who=self, what="unknow_mode", additional=self.MODE)
        return True
示例#2
0
 def playlist_delete(self, **ka):
     self._check_ka(ka, ['playlist_id'])
     if not 'playlist_id' in ka:
         raise QobuzXbmcError(who=self,
                              what='missing_parameter',
                              additional='playlist_id')
     return self._api_request(ka, '/playlist/delete')
示例#3
0
 def set_user_data(self, user_id, user_auth_token):
     if not (user_id or user_auth_token):
         raise QobuzXbmcError(who=self,
                              what='missing_argument',
                              additional='uid|token')
     self.user_auth_token = user_auth_token
     self.user_id = user_id
     self.logged_on = time()
示例#4
0
 def _check_ka(self, ka, mandatory, allowed=[]):
     """
     Checking parameters before sending our request
     - if mandatory parameter is missing raise error
     - if a given parameter is neither in mandatory or allowed
     raise error (Creating exception class like MissingParameter
     may be a good idea)
     """
     for label in mandatory:
         if not label in ka:
             raise QobuzXbmcError(who=self,
                                  what='missing_parameter',
                                  additional=label)
     for label in ka:
         if label not in mandatory and label not in allowed:
             raise QobuzXbmcError(who=self,
                                  what='invalid_parameter',
                                  additional=label)
示例#5
0
 def search_getResults(self, **ka):
     self._check_ka(ka, ['query'], ['type', 'limit', 'offset'])
     mandatory = ['query', 'type']
     for label in mandatory:
         if not label in ka:
             raise QobuzXbmcError(who=self,
                                  what='missing_parameter',
                                  additional=label)
     return self._api_request(ka, '/search/getResults')
示例#6
0
 def playlist_subscribe(self, **ka):
     mandatory = ['playlist_id']
     found = None
     for label in mandatory:
         if label in ka:
             found = label
     if not found:
         raise QobuzXbmcError(who=self,
                              what='missing_parameter',
                              additional='playlist_id')
     return self._api_request(ka, '/playlist/subscribe')
示例#7
0
 def favorite_delete(self, **ka):
     mandatory = ['artist_ids', 'album_ids', 'track_ids']
     found = None
     for label in mandatory:
         if label in ka:
             found = label
     if not found:
         raise QobuzXbmcError(who=self,
                              what='missing_parameter',
                              additional='artist_ids|albums_ids|track_ids')
     return self._api_request(ka, '/favorite/delete')
示例#8
0
 def bootstrap_registry(self):
     from api import api
     cache.base_path = qobuz.path.cache
     api.stream_format = 6 if getSetting('streamtype') == 'flac' else 5
     if not api.login(getSetting('username'), getSetting('password')):
         dialogLoginFailure()
         #@TODO sys.exit killing XBMC? FRODO BUG ?
         # sys.exit(1)
         containerRefresh()
         raise QobuzXbmcError(
             who=self, what='invalid_login', additional=None)
示例#9
0
 def to_s(self, flag):
     if not flag:
         warn(self, "Missing flag parameter")
         return ''
     flag = int(flag)
     if flag & self.TRACK == self.TRACK:
         return "track"
     elif flag & self.PLAYLIST == self.PLAYLIST:
         return "playlist"
     elif flag & self.USERPLAYLISTS == self.USERPLAYLISTS:
         return "user_playlists"
     elif flag & self.RECOMMENDATION == self.RECOMMENDATION:
         return "recommendation"
     elif flag & self.ROOT == self.ROOT:
         return "root"
     elif flag & self.ALBUM == self.ALBUM:
         return "album"
     elif flag & self.PURCHASES == self.PURCHASES:
         return "purchases"
     elif flag & self.FAVORITES == self.FAVORITES:
         return "favorites"
     elif flag & self.SEARCH == self.SEARCH:
         return "search"
     elif flag & self.ARTIST == self.ARTIST:
         return "artist"
     elif flag & self.SIMILAR_ARTIST == self.SIMILAR_ARTIST:
         return "similar_artist"
     elif flag & self.FRIEND == self.FRIEND:
         return "friend"
     elif flag & self.FRIEND_LIST == self.FRIEND_LIST:
         return "friend_list"
     elif flag & self.GENRE == self.GENRE:
         return "genre"
     elif flag & self.LABEL == self.LABEL:
         return "label"
     elif flag & self.NODE == self.NODE:
         return "inode"
     elif flag & self.STOPBUILD == self.STOPBUILD:
         return "stop_build_down"
     elif flag & self.ARTICLES == self.ARTICLES:
         return "articles"
     elif flag & self.ARTICLE == self.ARTICLE:
         return "article"
     elif flag & self.PUBLIC_PLAYLISTS == self.PUBLIC_PLAYLISTS:
         return "public_playlists"
     elif flag & self.ARTICLE_RUBRICS == self.ARTICLE_RUBRICS:
         return "article_rubrics"
     elif flag & self.ALBUMS_BY_ARTIST == self.ALBUMS_BY_ARTIST:
         return "albums_by_artist"
     else:
         raise QobuzXbmcError(
             who=self, what='invalid_flag', additional=repr(flag))
示例#10
0
 def search_type(self, st):
     if st == 'artists':
         self.label = lang(30015)
         self.content_type = 'files'
         self.image = getImage('artist')
     elif st == 'albums':
         self.label = lang(30014)
         self.content_type = 'albums'
         self.image = getImage('album')
     elif st == 'tracks':
         self.label = lang(30013)
         self.content_type = 'songs'
         self.image = getImage('song')
     else:
         raise QobuzXbmcError(who=self, what='invalid_type', additional=st)
     self._search_type = st
示例#11
0
 def send(self, request):
     if not request:
         raise QobuzXbmcError(who=self,
                              what='missing_parameter',
                              additional='request')
     return JsonResponse(xbmc.executeJSONRPC(request.to_json()))