Example #1
0
 def get(self):
     handler = self.get_rb_handler()
     entry_ids = handler.get_play_queue()
     entries = self.get_songs_as_json_list(entry_ids)
     playlist = JSon()
     playlist.put('entries', entries)
     return playlist
Example #2
0
    def post(self):
        action = self.get_parameter('action', True)
        
        json = JSon()
        
        if action == 'enqueue':
            if self.has_parameter('playlist'):
                source = self.get_parameter('playlist', True)
            elif self.has_parameter('source'):
                source = self.get_parameter('source', True)
            else:
                raise ServerException(400, 'Bad request, no "source" parameter')

            count = self.get_rb_handler().enqueue_source(int(source))
            json.put('count', count)
            if count > 0:
                json.put('result', 'OK')
                
        if action == 'play_source':
            source = self.get_parameter('source', True)
            if self.get_rb_handler().play_source(int(source)):
                json.put('result', 'OK')
            else:
                json.put('result', 'BAD')
            
        return json
Example #3
0
    def get(self):
        handler = self.get_rb_handler()
        
        if not self.has_path_parameters():
            rbplaylists = handler.get_sources()
            sources = []
            for source in rbplaylists:
                jsource = self.get_source_as_json(source)
                sources.append(jsource)
                
            playlists = JSon()
            playlists.put('playlists', sources)
            
            return playlists
        
        else:
            playlist_id = self.get_path_parameter(0)
            if not playlist_id.isdigit():
                raise ServerException(400, 'Bad request, path parameter must be an int')

            playlist_id = int(playlist_id)
            
            self.trace('Loading playlist with id %d' % playlist_id)
            
            playlist = handler.get_source(playlist_id)
            if playlist is None:
                raise ServerException(400, 'Bad request, playlist id %d is not valid' % playlist_id)
            
            limit = 100
            if self.get_path_parameters_size() > 1:
                _limit = self.get_path_parameter(1)
                if str(limit).isdigit():
                    limit = int(_limit)
            
            jplaylist = self.get_source_as_json(playlist, self.get_source_entries(playlist, limit))
            
            return jplaylist
Example #4
0
 
 def get(self):
     self.info('GET search')
     handler = self.get_rb_handler()
     filter = self.get_filter()
     
     try:
         entry_ids = handler.query(filter)
     except InvalidQueryException, e:
         self.error('Invalid query: %s' % e)
         raise ServerException(400, 'bad request: %s' % e.message)
     except Exception, e:
         self.error('Unknown exception: %s' % e)
         raise ServerException(500, 'Exception when executing query: %s' % e)
     
     json = JSon()
     
     if not entry_ids:
         self.info('Search returned none')
     else:
         entries = self.get_songs_as_json_list(entry_ids)
         json.put('entries', entries)
     
     return json
     
     
     
 def post(self):
     self.trace('POST search')
     return self.get()
     
Example #5
0
 def get(self):
     if not self.has_path_parameters():
         raise ServerException(400, 'Bad request, no parameters')
    
     search_by = self.get_path_parameter(0)
     
     if not SEARCH_TYPES.has_key(search_by):
         raise ServerException(400, 'Bad request, path parameter "%s" not supported' % search_by)
     
     if self.get_path_parameters_size() == 1:
         library = JSon()
         handler = self.get_rb_handler()
         
         if 'artists' == search_by:
             library.put('artists', self.get_library_as_json_list(handler.get_artists()))
             (name, value) = handler.get_biggest_artist()
             library.put('biggest_artist', self.get_name_value_as_json(name, value))
             
         elif 'genres' == search_by:
             library.put('genres', self.get_library_as_json_list(handler.get_genres()))
             (name, value) = handler.get_biggest_genre()
             library.put('biggest_genre', self.get_name_value_as_json(name, value))
             
         else:
             library.put('albums', self.get_library_as_json_list(handler.get_albums()))
             (name, value) = handler.get_biggest_album()
             library.put('biggest_album', self.get_name_value_as_json(name, value))
             
         return library
     
     else:
         value = self.get_path_parameter(1)
         value = str(value).replace('+', ' ')
         
         filter = {}
         filter['type'] = 'song'
         filter[SEARCH_TYPES[search_by]] = value
         filter['exact-match'] = True
         filter['limit'] = 0
         
         handler = self.get_rb_handler()
         
         entry_ids = handler.query(filter)
         entries = self.get_songs_as_json_list(entry_ids)
         library = JSon()
         library.put(SEARCH_TYPES[search_by], value)
         library.put('entries', entries)
         
         return library