added coverart
This commit is contained in:
parent
a42165720d
commit
4adc62f499
55
musik.py
55
musik.py
|
@ -25,7 +25,7 @@ FFMPEG_CMD = [
|
||||||
]
|
]
|
||||||
|
|
||||||
class Track:
|
class Track:
|
||||||
def __init__(self, filepath=None, d=None):
|
def __init__(self, filepath=None, d=None, coverart=""):
|
||||||
if d:
|
if d:
|
||||||
for attr, value in d.items():
|
for attr, value in d.items():
|
||||||
setattr(self, attr, value)
|
setattr(self, attr, value)
|
||||||
|
@ -43,6 +43,7 @@ class Track:
|
||||||
self.length = str(int(m.info.length) // 60) + ":"
|
self.length = str(int(m.info.length) // 60) + ":"
|
||||||
self.length += str(int(m.info.length) % 60)
|
self.length += str(int(m.info.length) % 60)
|
||||||
self.filepath = filepath
|
self.filepath = filepath
|
||||||
|
self.coverart = coverart
|
||||||
|
|
||||||
|
|
||||||
def build_library(root_dir):
|
def build_library(root_dir):
|
||||||
|
@ -54,7 +55,11 @@ def build_library(root_dir):
|
||||||
if not os.path.splitext(file)[1][1:] in MUSIC_EXT:
|
if not os.path.splitext(file)[1][1:] in MUSIC_EXT:
|
||||||
continue
|
continue
|
||||||
filepath = os.path.join(root_dir, dir_name, file)
|
filepath = os.path.join(root_dir, dir_name, file)
|
||||||
track = Track(filepath)
|
if "folder.jpg" in files:
|
||||||
|
coverart = os.path.join(root_dir, dir_name, "folder.jpg")
|
||||||
|
else:
|
||||||
|
coverart = ""
|
||||||
|
track = Track(filepath, coverart=coverart)
|
||||||
tracks.append(track)
|
tracks.append(track)
|
||||||
print("Done")
|
print("Done")
|
||||||
return tracks
|
return tracks
|
||||||
|
@ -125,6 +130,11 @@ class Selection(Resource):
|
||||||
artist=track.artist,
|
artist=track.artist,
|
||||||
album=track.album,
|
album=track.album,
|
||||||
track=track.title)
|
track=track.title)
|
||||||
|
found['coverart'] = url_for(
|
||||||
|
'coverart',
|
||||||
|
artist=track.artist,
|
||||||
|
album=track.album,
|
||||||
|
track=track.title)
|
||||||
return found
|
return found
|
||||||
|
|
||||||
elif args.get('album'):
|
elif args.get('album'):
|
||||||
|
@ -190,36 +200,21 @@ def stream(artist, album, track):
|
||||||
return Response(generate(), mimetype="audio/ogg")
|
return Response(generate(), mimetype="audio/ogg")
|
||||||
|
|
||||||
|
|
||||||
@app.route('/get_shuffle')
|
@app.route('/coverart/<artist>/<album>/<track>')
|
||||||
def shuffle():
|
def coverart(artist, album, track):
|
||||||
"""Returns a randomly selected track from the library."""
|
|
||||||
item = random.choice(os.listdir(MUSIC_DIR))
|
|
||||||
path = os.path.join(MUSIC_DIR, item)
|
|
||||||
n = 0
|
|
||||||
while not item.rpartition('.')[2] in MUSIC_EXT:
|
|
||||||
n += 1
|
|
||||||
item = random.choice(os.listdir(path))
|
|
||||||
if os.path.isdir(os.path.join(path, item)):
|
|
||||||
path = os.path.join(path, item)
|
|
||||||
if n == 5:
|
|
||||||
item = random.choice(os.listdir(MUSIC_DIR))
|
|
||||||
path = os.path.join(MUSIC_DIR, item)
|
|
||||||
n = 0
|
|
||||||
path = os.path.join(path, item)
|
|
||||||
return path.replace(MUSIC_DIR, '')
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/album_cover/<path:cover>')
|
|
||||||
def album_cover(cover):
|
|
||||||
"""View for the raw audio file."""
|
"""View for the raw audio file."""
|
||||||
path = os.path.join(MUSIC_DIR, cover)
|
for t in tracks:
|
||||||
path = os.path.abspath(path)
|
if (t.artist == artist and
|
||||||
if not path.startswith(MUSIC_DIR):
|
t.album == album and
|
||||||
return "False"
|
t.title == track):
|
||||||
if not os.path.isfile(path):
|
break
|
||||||
return "False"
|
else:
|
||||||
|
abort(404, message="Track does not exist.")
|
||||||
|
|
||||||
return send_file(path)
|
if t.coverart:
|
||||||
|
return send_file(t.coverart)
|
||||||
|
else:
|
||||||
|
return "False"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -74,7 +74,5 @@ function change_track(track) {
|
||||||
player.play();
|
player.play();
|
||||||
document.getElementById('nowPlaying').innerHTML = track.title;
|
document.getElementById('nowPlaying').innerHTML = track.title;
|
||||||
|
|
||||||
//let arr = track.split('/');
|
document.getElementById('albumCover').firstChild.src = track.coverart;
|
||||||
//let art = document.getElementById('albumCover');
|
|
||||||
//art.firstChild.src = '/musik/album_cover' + arr.slice(0, arr.length-1).join("/") + '/folder.jpg';
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user