Ejemplo n.º 1
0
def api_v1_audio_song(songID):
    try:
        songs = getSongs(songID=int(songID))
        if not songs:
            raise ValueError
    except ValueError:
        abort(404)
    song = songs[0]
    print('Delivering song %s: %s' % (songID, song.path()))
    localfilename = song.path()
    return send_file(localfilename)
Ejemplo n.º 2
0
def song_set_ratings():
    if request.method != 'GET':
        return None
    song_id = request.args.get('id', type=int)
    rating = request.args.get('rating', type=int)
    song = getSongs(songID=song_id)
    if not song:
        return ''
    song = song[0]
    song.setUserRating(rating, current_user.userID)

    return ''
Ejemplo n.º 3
0
def api_v1_coverart_song(songID):
    songs = getSongs(songID=songID)
    if not songs:
        abort(404)
    song = songs[0]
    print('Delivering coverart of song %s: %s' % (songID, song.path()))
    coverart = song.getCoverImage()
    if isinstance(coverart, str):
        return send_file(coverart)
    elif isinstance(coverart, tuple):
        image, data = coverart
        response = Response(data, status=200)
        return response
    elif isinstance(coverart, Image.Image):
        data = coverart.tobytes()
        mime = Image.MIME[coverart.format]
        response = Response(data, status=200, mimetype=mime)
        response.headers["Content-Type"] = mime
        return response

    return ''
Ejemplo n.º 4
0
def print_song_info(song, userID=None, print_analysis=True):  # noqa: C901
    song.loadMetadataInfo()
    print("----------")
    try:
        filesize = "%d bytes" % os.path.getsize(song.path())
    except FileNotFoundError:
        filesize = "File not found"
    print("%s (%s)" % (song.path(), filesize))
    print("song id:", song.id)

    rating = song.userRating(userID)
    if rating:
        print("my rating:", '*' * rating, '(%d/10)' % rating)
    avgrating = song.avgRating(userID)
    if avgrating:
        print("avg rating:", '*' * avgrating, '(%d/10)' % avgrating)

    if not rating and not avgrating:
        rating = song.rating(userID)
        print("rating:", '*' * rating, '(%d/10)' % rating)

    for k in sorted(song.metadata):
        v = song.metadata[k]
        print(TerminalColors.Header + str(k) + TerminalColors.ENDC +
              ' : ' + str(v)[:100])
        if k in ('TMCL', 'TIPL'):
            if len(v) > 1:
                print('*** More than one %s tag in file: ' +
                      'The following list might be incomplete ***')
            txt_repr = v[0]
            m = re.search(r'people=', txt_repr)
            if m:
                pos_bracket = simple_find_matching_square_bracket(
                    txt_repr, m.end())
                txt = txt_repr[m.end():pos_bracket + 1]
                list_artists = eval(txt)
                for instrument, artist in list_artists:
                    print('    %s : %s' % (instrument, artist))

    print("file sha256sum: ", song.fileSha256sum())
    print("audio track sha256sum: ", song.audioSha256sum())

    print('duration: %s s' % formatLength(song.duration()))
    print(('duration without silences: %s s' %
           formatLength(song.durationWithoutSilences())),
          ' (silences: %s + %s)' %
          (formatLength(song.silenceAtStart()),
           formatLength(song.silenceAtEnd())))
    printProperties(song)
    if song.coverWidth():
        print('cover:  %dx%d' %
              (song.coverWidth(), song.coverHeight()))

    if print_analysis:
        print_song_info_analysis(song)

    similar_pairs = MusicDatabase.getSimilarSongsToSongID(song.id)
    if similar_pairs:
        print('Similar songs:')

    similarSongs = []
    for otherID, offset, similarity in similar_pairs:
        otherSong = getSongs(songID=otherID)[0]
        try:
            audioComparison = song.audioCmp(otherSong,
                                            interactive=False)
        except (DifferentLengthException):
            audioComparison = 2
            colors = {'length': TerminalColors.Magenta}
        except (CantCompareSongsException):
            audioComparison = 3
            colors = {}
        else:
            colors = {}
        colors['bitrate'] = TerminalColors.Blue
        propertiesString = getPropertiesAsString(otherSong, colors)
        color = {-1: TerminalColors.Worse,
                 0: TerminalColors.ENDC,
                 1: TerminalColors.Better,
                 2: TerminalColors.DifferentLength,
                 3: TerminalColors.CantCompareSongs}[audioComparison]
        songpath = (color + ' %d ' % otherID + otherSong.path() +
                    TerminalColors.ENDC)
        songprop = '(%d %f %s)' % (offset, similarity,
                                   propertiesString)
        similarSongs.append([songpath] + songprop.split())
    aligned = alignColumns(similarSongs)
    for line in aligned:
        print(line)
Ejemplo n.º 5
0
def api_v1_metadata_song(songID):
    song = getSongs(songID=songID, metadata=True)
    if not song:
        return ''
    song = song[0]
    return jsonify(structFromSong(song))