def _index(): if not request.values.get("song"): return redirect("/?song=0") page = int(request.values.get("song")) if request.method == "POST": song = request.files.getlist('song[]') for song in song: name = song.filename if not name.endswith(".mp3"): return "Only MP3 files are supported." name = uuid.uuid4().hex+".mp3" with open("static/songs/"+name, 'wb') as file: file.write(song.read()) obj = Reader("static/songs/"+name) title = obj.getValue("title") if not title: title = song.filename.split(".mp3")[0] artist = obj.getValue("performer") if not artist: artist = "Unknown" year = obj.getValue("year") url = "../static/songs/"+name if not db.find("songs", {"title":title}): db.insert("songs", {"title":title, "artist":artist, "year":year, "url":url}) else: os.remove("static/songs/"+name) songs = db.find("songs", "all") playlists = db.find("playlists", "all") if songs: try: first = songs[page] except IndexError: return redirect("/") else: first = [] if not playlists: playlists = [] if not songs: songs = [] if page > 0: autoplay = {"autoplay":"autoplay", "play":"pause"} else: autoplay = {"autoplay":"", "play":"play"} return render_template("index.html", autoplay=autoplay, page=page, first=first, songs=songs, playlists=playlists)
def get_track_bpm_from_id3_tag(file_path): # Read BPM from ID3 tag print file_path if file_path.endswith('.mp3'): return Reader(file_path).getValue('TBPM') # Otherwise standard .wav file format should have BPM then space else: if '/' in file_path: return file_path[reverse_find(file_path, '/'):file_path.find(' ')] else: return file_path[0:file_path.find(' ')]
def songManager(): while True: for x in os.listdir("songs"): id_ = hashlib.md5(open("songs/" + x).read()).hexdigest() if id_ not in songs: data = Reader("songs/" + x) songs[id_] = { "artist": data.getValue("performer"), "title": data.getValue("title"), "year": data.getValue("year"), "directory": "songs/" + x, "id": id_, "genre": data.getValue("genre") } time.sleep(15)