Esempio n. 1
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 == 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:
         notify_warn('Qobuz', 'Failed to add tracks')
         return False
     self.delete_cache(cid)
     notify_log('Qobuz / Tracks added', '%s added' % (len(nodes)))
     return True
Esempio n. 2
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 == Flag.SEARCH:
         self.del_parameter('query')
     if qnt & Flag.TRACK == Flag.TRACK:
         node = getNode(qnt, parameters={'nid': qid})
         node.data = node.fetch()
         nodes.append(node)
     else:
         render = renderer(
             qnt,
             parameters=self.parameters,
             depth=-1,
             whiteFlag=Flag.TRACK,
             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:
         notify_warn('Qobuz', 'Failed to add tracks')
         return False
     self.delete_cache(cid)
     notify_log('Qobuz / Tracks added', '%s added' % (len(nodes)))
     executeBuiltin(containerRefresh())
     return True
 def run(self):
     while self.alive:
         if not is_authentication_set():
             gui.notify_warn('Authentication not set',
                             'You need to enter credentials')
         elif not user.logged:
             if not api.login(
                     username=qobuzApp.registry.get('username'),
                     password=qobuzApp.registry.get('password')):
                 gui.notify_warn('Login failed', 'Invalid credentials')
             else:
                 try:
                     application.run(port=self.port,
                                     threaded=True,
                                     processes=0,
                                     debug=False,
                                     use_reloader=False,
                                     use_debugger=False,
                                     use_evalex=True,
                                     passthrough_errors=False)
                 except Exception as e:
                     logger.error('KooliService port: %s Error: %s',
                                  self.port, e)
                     raise e
         time.sleep(1)
Esempio n. 4
0
    def play(self, track_id, params={}):
        """Playing track given a 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")
            return False
        if not track.is_playable():
            warn(self, "Cannot get streaming URL")
            return False
        if 'purchased' in params:
            track.parameters['purchased']= True
        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():
                notify_warn("Qobuz", "Sample returned")
        xbmcgui.Window(10000).setProperty(keyTrackId, track_id)
        """Notify
        """
        if getSetting('notification_playingsong', asBool=True):
            notify_restriction(track)
            notifyH(lang(30132), track.get_label(), image=track.get_image())

        """We are called from playlist...
        """
        if config.app.handle == -1:
            super(QobuzPlayer, self).play(track.get_streaming_url(),
                                          item, False)
        else:
            setResolvedUrl(handle=config.app.handle,
                           succeeded=True,
                           listitem=item)
        return True
Esempio n. 5
0
    def play(self, track_id, params=None):
        """ Playing track given a track id """
        params = {} if params is None else params
        track = getNode(Flag.TRACK, {'nid': track_id})
        data = track.fetch(helper.TreeTraverseOpts(
            lvl=1,
            whiteFlag=Flag.TRACK,
            blackFlag=Flag.NONE))
        if data is None:
            logger.warn('Cannot get track data')
            return False
        track.data = data
        if not track.is_playable():
            logger.warn('Cannot get streaming URL')
            return False
        if 'purchased' in params:
            track.parameters['purchased'] = True
        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():
                notify_warn("Qobuz / Free Account", "Sample returned")
            if track.is_uncredentialed():
                notify_warn("Qobuz / Uncredentialed", "Sample returned")
        xbmcgui.Window(10000).setProperty(keyTrackId, track_id)
        # Notify
        if config.app.registry.get('notification_playingsong', to='bool'):
            notify_restriction(track)
            notifyH(lang(30132), track.get_label(), image=track.get_image())
        # We are called from playlist...
        if config.app.handle == -1:
            super(QobuzPlayer, self).play(track.get_streaming_url(), item,
                                          False)
        else:
            setResolvedUrl(
                handle=config.app.handle, succeeded=True, listitem=item)
        return True
Esempio n. 6
0
def notify_restriction(track):
    restrictions = ''
    for restriction in track.get_restrictions():
        restrictions += '%s\n' % restriction
    if restrictions != '':
        notify_warn("Restriction", restrictions)
Esempio n. 7
0
def notify_restriction(track):
    restrictions = ''
    for restriction in track.get_restrictions():
        restrictions += '%s\n' % restriction
    if restrictions != '':
        notify_warn("Restriction", restrictions, mstime=5000)
                                        use_debugger=False,
                                        use_evalex=True,
                                        passthrough_errors=False)
                    except Exception as e:
                        logger.error('KooliService port: %s Error: %s',
                                     self.port, e)
                        raise e
            time.sleep(1)


if __name__ == '__main__':
    monitor = Monitor()
    if is_service_enable():
        monitor.add_service(KooliService())
    else:
        notify_warn('Qobuz service / HTTPD',
                    'Service is disabled from configuration')
    monitor.start_all_service()
    alive = True
    while alive:
        abort = False
        try:
            abort = monitor.abortRequested
        except Exception as e:
            logger.error('Error while getting abortRequested %s', e)
        if abort:
            alive = False
            continue
        xbmc.sleep(1000)
    monitor.stop_all_service()