コード例 #1
0
ファイル: upload.py プロジェクト: wTheRockb/OSTstream
def upsert_track(path, album_id):
	id3 = Reader(path)
	title = Reader.getValue(id3, "title")
	artist = Reader.getValue(id3, "performer")
	album = Reader.getValue(id3, "album")
	cur.execute("INSERT INTO api.tracks (title, artist, album_id, path) VALUES (%s, %s, %s, %s) ON CONFLICT (title, artist, album_id) DO UPDATE SET (title, artist, album_id, path) = (%s, %s, %s, %s);", [title, artist, album_id, path, title, artist, album_id, path])
	conn.commit()
コード例 #2
0
ファイル: api.py プロジェクト: Max00355/MusicStream
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)
コード例 #3
0
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)
コード例 #4
0
ファイル: index.py プロジェクト: Inqre/Melody
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)
コード例 #5
0
def get_music_file(episode):
    base_query = 'http://www.beatsinspace.net/playlists/%s' % episode
    html = get(base_query)
    soup = BeautifulSoup(html.text)
    links = [link.get('href') for link in soup.findAll('a')]
    mp3_urls = [link for link in links if link and link.endswith('.mp3')]
    for mp3 in mp3_urls:
        title = soup.title.string[:19]
        print 'MP3s from %s will be downloaded' % title
        with open(title, 'w') as f:
            f.write(get(mp3).content)
        x = Reader(title)
        rename(title, (x.getValue('title') + '.mp3'))
コード例 #6
0
ファイル: upload.py プロジェクト: wTheRockb/OSTstream
def upsert_album(path):
	album_image = 0
	for root, dirs, files in os.walk(path):
		for f in files:
			if ".mp3" in f:
				id3 = Reader(os.path.join(root, f))
				album_title = Reader.getValue(id3, "album")
			if ".jpg" in f:
				album_image = os.path.join(root, f)
	if album_image:
		cur.execute("INSERT INTO api.albums (title, image_path) VALUES (%s, %s) ON CONFLICT (title) DO UPDATE SET (title, image_path, updated_at) = (%s, %s, now()) RETURNING id;", [album_title, album_image, album_title, album_image])
		album_id = cur.fetchone()[0]
		conn.commit()
	else:
		cur.execute("INSERT INTO api.albums (title) VALUES (%s) ON CONFLICT (title) DO UPDATE SET (title, updated_at) = (%s, now()) RETURNING id;", [album_title, album_title])
		album_id = cur.fetchone()[0]
		conn.commit()
	for root, dirs, files in os.walk(path):
		for f in files:
			if ".mp3" in f:
				upsert_track((os.path.join(root, f)), album_id)