Exemplo n.º 1
0
    def getArtists(self, **kwargs):
        rest = SubsonicREST(kwargs)
        success, response = rest.check_login()
        if not success:
            return response

        root = etree.Element('subsonic-response',
                             status='ok',
                             version=rest.version_server)
        xml_artists = rest.make_ArtistsID3()
        root.append(xml_artists)

        musicFolderId = kwargs.get('musicFolderId')
        if musicFolderId:
            artists = request.env['oomusic.track'].search([
                ('folder_id', 'child_of', int(musicFolderId))
            ]).mapped('artist_id')
        else:
            artists = request.env['oomusic.artist'].search([])

        # Build indexes
        indexes_dict = rest.build_dict_indexes_artists(artists)

        # List of artists
        for k, v in sorted(indexes_dict.iteritems()):
            xml_index = rest.make_IndexID3(k)
            xml_artists.append(xml_index)
            for artist in v:
                xml_artist = rest.make_ArtistID3(artist)
                xml_index.append(xml_artist)

        return rest.make_response(root)
Exemplo n.º 2
0
    def getArtist(self, **kwargs):
        rest = SubsonicREST(kwargs)
        success, response = rest.check_login()
        if not success:
            return response

        artistId = kwargs.get('id')
        if artistId:
            artist = request.env['oomusic.artist'].browse([int(artistId)])
            if not artist.exists():
                return rest.make_error(code='70', message='Artist not found')
        else:
            return rest.make_error(
                code='10',
                message='Required int parameter "id" is not present')

        root = etree.Element('subsonic-response',
                             status='ok',
                             version=rest.version_server)
        xml_artist = rest.make_ArtistID3(artist)
        root.append(xml_artist)

        for album in artist.album_ids:
            xml_album = rest.make_AlbumID3(album)
            xml_artist.append(xml_album)

        return rest.make_response(root)
Exemplo n.º 3
0
    def getStarred2(self, **kwargs):
        rest = SubsonicREST(kwargs)
        success, response = rest.check_login()
        if not success:
            return response

        ArtistObj = request.env['oomusic.artist']
        AlbumObj = request.env['oomusic.album']
        TrackObj = request.env['oomusic.track']

        folderId = kwargs.get('musicFolderId')
        if folderId:
            folder = request.env['oomusic.folder'].browse([int(folderId)])
            if not folder.exists():
                return rest.make_error(code='70', message='Folder not found')
        domain = [('id', 'child_of', int(folderId))] if folderId else []

        root = etree.Element('subsonic-response',
                             status='ok',
                             version=rest.version_server)
        xml_starred_list = rest.make_listSongs('starred2')
        root.append(xml_starred_list)

        artists = ArtistObj.search(domain + [('star', '=', '1')])
        albums = AlbumObj.search(domain + [('star', '=', '1')])
        tracks = TrackObj.search(domain + [('star', '=', '1')])

        for artist in artists:
            xml_artist = rest.make_ArtistID3(artist)
            xml_starred_list.append(xml_artist)

        for album in albums:
            xml_album = rest.make_AlbumID3(album)
            xml_starred_list.append(xml_album)

        for track in tracks:
            xml_song = rest.make_Child_track(track, tag_name='song')
            xml_starred_list.append(xml_song)

        return rest.make_response(root)
Exemplo n.º 4
0
    def search3(self, **kwargs):
        rest = SubsonicREST(kwargs)
        success, response = rest.check_login()
        if not success:
            return response

        query = kwargs.get('query')
        if not query:
            return rest.make_error(
                code='10',
                message='Required str parameter "query" is not present')

        artistCount = min(int(kwargs.get('artistCount', 20)), 500)
        artistOffset = int(kwargs.get('artistOffset', 0))
        albumCount = min(int(kwargs.get('albumCount', 20)), 500)
        albumOffset = int(kwargs.get('albumOffset', 0))
        songCount = min(int(kwargs.get('songCount', 20)), 500)
        songOffset = int(kwargs.get('songOffset', 0))

        folderId = kwargs.get('musicFolderId')
        if folderId:
            folder = request.env['oomusic.folder'].browse([int(folderId)])
            if not folder.exists():
                return rest.make_error(code='70', message='Folder not found')

        domain = [('folder_id', 'child_of', int(folderId))] if folderId else []
        artists = request.env['oomusic.artist'].search(domain +
                                                       [('name', 'ilike',
                                                         query)])
        albums = request.env['oomusic.album'].search(domain +
                                                     [('name', 'ilike',
                                                       query)])
        tracks = request.env['oomusic.track'].search(domain +
                                                     [('name', 'ilike',
                                                       query)])

        root = etree.Element('subsonic-response',
                             status='ok',
                             version=rest.version_server)
        xml_search = rest.make_SearchResult2(tag_name='searchResult3')
        root.append(xml_search)

        if artists:
            min_val = min(artistOffset, len(artists))
            max_val = min_val + artistCount
            for artist in artists[min_val:max_val]:
                xml_artist = rest.make_ArtistID3(artist)
                xml_search.append(xml_artist)

        if albums:
            min_val = min(albumOffset, len(albums))
            max_val = min_val + albumCount
            for album in albums[min_val:max_val]:
                xml_album = rest.make_AlbumID3(album)
                xml_search.append(xml_album)

        if tracks:
            min_val = min(songOffset, len(tracks))
            max_val = min_val + songCount
            for track in tracks[min_val:max_val]:
                xml_song = rest.make_Child_track(track, tag_name='song')
                xml_search.append(xml_song)

        return rest.make_response(root)