Exemplo n.º 1
0
def scrobble_view():
    """Add song to last.fm

        id	Yes		A string which uniquely identifies the file to scrobble.
        time	No		(Since 1.8.0) The time (in milliseconds since 1 Jan 1970) at which the song was listened to.
        submission	No	True	Whether this is a "submission" or a "now playing" notification.


    """
    from mediamanager.scrobble import q
    (u, p, v, c, f, callback) = map(
        request.args.get, ['u', 'p', 'v', 'c', 'f', 'callback'])
    (eid, ts, submission) = map(
        request.args.get, ['id', 'time', 'submission'])
    assert eid, "Missing song id"

    log.info("Retrieving scrobbling credentials")
    lastfm_user = app.iposonic.get_users(MediaManager.uuid(u))
    log.info("Scobbling credentials: %s" % lastfm_user)
    # get song info and append timestamp
    info = app.iposonic.get_entry_by_id(eid)
    info.update({'timestamp': int(time.time())})
    q.put(({
        'username': lastfm_user.get('scrobbleUser'),
        'password': lastfm_user.get('scrobblePassword')}, info))

    return request.formatter({})
Exemplo n.º 2
0
def get_cover_art_file(eid, nocache=False):
    from mediamanager.cover_art import q

    """Return coverArt file, eventually downloading it.

        Successful download requires both Artist and Album, so
        store the filename as uuid(Artist/Album)
        1- if parent directory...
        2- if song, download as Artist/Album
        3- if album, download as Artist/Album
        3- if albumId...

        We should manage some border cases:
        a- featured artists
            ex. album: Antonella Ruggiero
                song: Antonella Ruggiero & Subsonica
    """

    # if everything is fine, just get the file
    cover_art_path = os.path.join("/", app.iposonic.cache_dir, "%s" % eid)
    if os.path.exists(cover_art_path):
        return cover_art_path

    # otherwise we need to guess from item info,
    # and hit the database
    info = app.iposonic.get_entry_by_id(eid)
    log.info("search cover_art requires media info from db: %s" % info)

    # search cover_art using id3 tag
    if not info.get('artist') or not info.get('album'):
        return None

    # if we're a CD collection, use parent
    #   TODO add other patterns to "cd" eg. "disk", "volume"
    if info.get('isDir') and info.get('album').lower().startswith("cd"):
        info = app.iposonic.get_entry_by_id(info.get('parent'))
        log.info("album is a cd, getting parent info: %s" % info)

    cover_art_path = os.path.join(
        "/", app.iposonic.cache_dir, MediaManager.cover_art_uuid(info))
    log.info("checking cover_art_uuid: %s" % cover_art_path)
    if os.path.exists(cover_art_path):
        return cover_art_path

    # if we're a file, let's use parent or albumId
    if info.get('isDir') in [False, 'false', 'False']:
        cover_art_path = join(
            "/", app.iposonic.cache_dir, "%s" % info.get('parent'))
        if os.path.exists(cover_art_path):
            log.info("successfully get cover_art from parent directory")
            return cover_art_path

    cover_art_path = join("/", app.iposonic.cache_dir,
                          MediaManager.cover_art_uuid(info))
    if os.path.exists(cover_art_path):
        return cover_art_path

    # if it's not present
    # use the background thread to download
    # and return 503
    q.put(info)
    abort(503)