示例#1
0
文件: echonest.py 项目: aaronyo/panko
def main():
    echonest.config_service()
    args = parse_args()
    if args.command == "playlist.static":
        print "["
        for file_path in args.files:
            try:
                af = audiofile.open(file_path)
                id = af.read_tags().get("echonest_id", None)
                songs_by_file = {}
                if id:
                    songs = []
                    for song in echonest.playlist.static(
                        song_id=id, results=20, seed_catalog="CAMQJMD133B59A5B1C", type="catalog"
                    ):
                        songs.append(
                            {
                                "id": song.id,
                                "title": song.title,
                                "artist_name": song.artist_name,
                                "artist_id": song.artist_id,
                            }
                        )
                    print json.dumps({file_path: songs}, sort_keys=True)
                    print ","
            except Exception, e:
                sys.stderr.write(str(e))
        print "]"
示例#2
0
def recommend(artist, title):
        echonest.config_service()
        matches = echonest.song.search(artist=artist, title=title, )
        if not matches:
            return []
        echonest_id = matches[0].id
        songs = []
        for song in echonest.playlist.static(song_id=echonest_id, results=20, seed_catalog='CAMQJMD133B59A5B1C', type='catalog'):
            songs.append( {'id':song.id,
                           'title':song.title,
                           'artist':song.artist_name,
                           'artist_id':song.artist_id} )
        return songs
示例#3
0
def main():
    echonest.config_service()
    args = parse_args()
    recommendations = recommend(args.artist, args.title)
    print json.dumps(recommendations, sort_keys=True)
示例#4
0
文件: discover.py 项目: aaronyo/panko
def main():
    args = parse_args()
    for filepath in args.files:
#        try:
            target_file = audiofile.open(filepath)
            tags = target_file.read_tags()
            if args.cover \
            and (not args.if_needed or not target_file.has_embedded_cover()):
                lfm_service = lastfm.make_service()
                cover_url = lfm_service.get_cover_art_url(tags)
                if args.update:
                    target_file.embed_cover( albumart.load_url(cover_url),
                                             format=args.cover_format )
                    print '%s: updated with cover %s' % (filepath, cover_url)
                else:
                    print cover_url
            elif args.echonest_id \
            and (not args.if_needed or 'echonest_id' not in target_file.read_tags()):
                echonest.config_service(codegen_start_=args.codegen_start,
                                        codegen_duration_=args.codegen_duration)
                echonest_id = echonest.song.identify(filepath,
                                                     codegen_start = echonest.codegen_start,
                                                     codegen_duration = echonest.codegen_duration)[0].id
                if args.update:
                    target_file.write_tags({'echonest_id':echonest_id})
                    print '%s: updated with id %s' % (filepath, echonest_id)
                else:
                    print echonest_id
            elif args.echonest_profile:
                echonest.config_service()
                buckets=["audio_summary", "artist_familiarity", "artist_hotttnesss",
                         "artist_location", "song_hotttnesss", "tracks", "id:7digital-US"]
                song = echonest.song.profile( target_file.read_tags()['echonest_id'],
                                              buckets=buckets )[0]
                track = echonest.track.track_from_id(target_file.read_tags()['echonest_id'])
                if args.update:
                    target_file.write_tags({'echonest_id':echonest_id})
                    print '%s: updated with id %s' % (filepath, echonest_id)
                else:
                    print "Audio Summary"
                    print song.audio_summary
                    print
                    print "Artist Familiarity"
                    print song.artist_familiarity
                    print
                    print "Artist Hotttnesss"
                    print song.artist_hotttnesss
                    print
                    print "Artist Location"
                    print song.artist_location
                    print
                    print "Song Hotttnesss"
                    print song.song_hotttnesss,
                    print
                    print "Tracks"
                    song = echonest.song.Song(target_file.read_tags()['echonest_id'])
                    print song.get_tracks('7digital')[0]
                    print
                    print "Track analysis"
                    print track.__dict__
            else:
                print '%s: nothing to do' % filepath
#        except Exception as e:
#            print 'Trouble with file %s: %s' % (filepath, e)
            sys.stdout.flush()