示例#1
0
def get_album_list_view():
    """Get albums

        params:
           - type   in random,
                    newest,     TODO
                    highest,    TODO
                    frequent,   TODO
                    recent,     TODO
                    starred,    TODO
                    alphabeticalByName, TODO
                    alphabeticalByArtist TODO
           - size   items to return TODO
           - offset paging offset   TODO

        xml response:
            <albumList>
                <album id="11" parent="1" title="Arrival" artist="ABBA" isDir="true" coverArt="22" userRating="4" averageRating="4.5"/>
                <album id="12" parent="1" title="Super Trouper" artist="ABBA" isDir="true" coverArt="23" averageRating="4.4"/>
            </albumList>
    """
    (u, p, v, c, f, callback, dir_id) = map(
        request.args.get, ['u', 'p', 'v', 'c', 'f', 'callback', 'id'])
    (size, type_a, offset) = map(request.args.get, ['size', 'type', 'offset'])

    if not type_a in ['random', 'newest', 'highest', 'frequent', 'recent', 'starred']:
        raise SubsonicProtocolException("Invalid or missing parameter: type")

    try:
        size = int(size)
    except:
        size = 20
    try:
        offset = int(offset)
    except:
        offset = 0

    if type_a == 'random':
        log.info("getting ", type_a)
        albums = app.iposonic.get_albums()
        albums = randomize2_list(albums, size)
    elif type_a == 'highest':
        log.info("getting ", type_a)
        albums = app.iposonic.get_albums(
            query={'userRating': 'notNull'}, order=('userRating', 1))
    elif type_a == 'newest':
        log.info("getting ", type_a)
        albums = app.iposonic.get_albums(
            query={'created': 'notNull'}, order=('created', 1))
    elif type_a == 'starred':
        log.info("getting ", type_a)
        albums = app.iposonic.get_albums(query={'starred': 'notNull'})
    else:
        # get all albums...hey, they may be a lot!
        albums = [a for a in app.iposonic.get_albums()]

    last = min(offset + size, len(albums) - 1)
    log.info("paging albums: %s,%s/%s" % (offset, last, len(albums)))
    return request.formatter({'albumList': {'album': albums[offset:last]}})
示例#2
0
def get_random_songs_view():
    """

    request:
      size    No  10  The maximum number of songs to return. Max 500.
      genre   No      Only returns songs belonging to this genre.
      fromYear    No      Only return songs published after or in this year.
      toYear  No      Only return songs published before or in this year.
      musicFolderId   No      Only return songs in the music folder with the given ID. See getMusicFolders.

    response xml:
      <randomSongs>
      <song id="111" parent="11" title="Dancing Queen" isDir="false"
      album="Arrival" artist="ABBA" track="7" year="1978" genre="Pop" coverArt="24"
      size="8421341" contentType="audio/mpeg" suffix="mp3" duration="146" bitRate="128"
      path="ABBA/Arrival/Dancing Queen.mp3"/>

      <song id="112" parent="11" title="Money, Money, Money" isDir="false"
      album="Arrival" artist="ABBA" track="7" year="1978" genre="Pop" coverArt="25"
      size="4910028" contentType="audio/flac" suffix="flac"
      transcodedContentType="audio/mpeg" transcodedSuffix="mp3"  duration="208" bitRate="128"
      path="ABBA/Arrival/Money, Money, Money.mp3"/>
      </randomSongs>

    response json:
        {'randomSongs':
            { 'song' : [
                {   'id' : ..,
                    'coverArt': ..,
                    'contentType': ..,
                    'transcodedContentType': ..,
                    'transcodedSuffix': ..
                }, ..
            }
        }
    """
    (size, genre, fromYear, toYear, musicFolderId) = map(request.args.get,
                                                         ['size', 'genre', 'fromYear', 'toYear', 'musicFolderId'])
    songs = []
    if genre:
        print("genre: %s" % genre)
        songs = app.iposonic.get_genre_songs(genre.strip().lower())
    else:
        all_songs = app.iposonic.get_songs()
        assert all_songs
        songs = randomize2_list(all_songs)

    # add cover art
    songs = [x.update({'coverArt': x.get('id')}) or x for x in songs]
    return request.formatter({'randomSongs': {'song': songs}})
示例#3
0
def get_playlist_view():
    """Return a playlist.

        response xml:
     <playlist id="15" name="kokos" comment="fan" owner="admin" public="true" songCount="6" duration="1391"
                     created="2012-04-17T19:53:44">
               <allowedUser>sindre</allowedUser>
               <allowedUser>john</allowedUser>
               <entry id="657" parent="655" title="Making Me Nervous" album="I Don&apos;t Know What I&apos;m Doing"
                      artist="Brad Sucks" isDir="false" coverArt="655" created="2008-04-10T07:10:32" duration="159"
                     bitRate="202" track="1" year="2003" size="4060113" suffix="mp3" contentType="audio/mpeg" isVideo="false"
                     path="Brad Sucks/I Don&apos;t Know What I&apos;m Doing/01 - Making Me Nervous.mp3" albumId="58"
                     artistId="45" type="music"/>
        response jsonp:
            {'playlist': {
                'id':,
                'name':,
                'songCount',
                'allowedUser': [ 'user1', 'user2' ],
                'entry': [ {
                    id:,
                    title:,
                    ...
                    },
                ]
                }}

        TODO move database objects to app.iposonicdb. They  shouldn't be
                exposed outside.
    """
    (u, p, v, c, f, callback) = map(
        request.args.get, ['u', 'p', 'v', 'c', 'f', 'callback'])
    eid = request.args.get('id')
    if not eid:
        raise SubsonicProtocolException(
            "Missing required parameter: 'id' in stream.view")

    entries = []
    # use default playlists
    if eid == MediaManager.uuid('starred'):
        j_playlist = app.iposonic.get_playlists_static(eid=eid)
        songs = app.iposonic.get_starred().get('title')
        entries = randomize2_list(songs, 5)
    elif eid in [x.get('id') for x in app.iposonic.get_playlists_static()]:
        j_playlist = app.iposonic.get_playlists_static(eid=eid)
        entries = randomize2_list(app.iposonic.get_songs())
    else:
        playlist = app.iposonic.get_playlists(eid=eid)
        assert playlist, "Playlists: %s" % app.iposonic.db.playlists
        print("found playlist: %s" % playlist)
        entry_ids = playlist.get('entry')
        if entry_ids:
            entries = [x for x in app.iposonic.get_song_list(
                entry_ids.split(","))]
        j_playlist = playlist
    # format output
    assert entries, "Missing entries: %s" % entries
    print("Entries retrieved: %s" % entries)
    j_playlist.update({
        'entry': entries,
        'songCount': len(entries),
        'duration': sum([x.get('duration', 0) for x in entries])
    })
    return request.formatter({'status': 'ok', 'playlist': j_playlist})