quoting and unquoting url paths

This commit is contained in:
iou1name 2019-02-21 12:57:58 -05:00
parent 1848ebdff4
commit d1e065d9f6

View File

@ -12,7 +12,7 @@ from flask import Flask, Response, render_template, send_file, url_for
from flask_restful import reqparse, abort, Api, Resource
import mutagen
MUSIC_DIR = "/mnt/music/Music"
MUSIC_DIR = "/home/iou1name/music/Music"
MUSIC_EXT = ['flac', 'mp3', 'wav', 'm4a']
FFMPEG_CMD = [
'ffmpeg', '-y',
@ -127,14 +127,14 @@ class Selection(Resource):
found.pop('filepath')
found['streampath'] = url_for(
'stream',
artist=track.artist,
album=track.album,
track=track.title)
artist=parse.quote(track.artist, safe=''),
album=parse.quote(track.album, safe=''),
track=parse.quote(track.title, safe=''))
found['coverart'] = url_for(
'coverart',
artist=track.artist,
album=track.album,
track=track.title)
artist=parse.quote(track.artist, safe=''),
album=parse.quote(track.album, safe=''),
track=parse.quote(track.title, safe=''))
return found
elif args.get('album'):
@ -186,6 +186,7 @@ api.init_app(app)
@app.route('/stream/<artist>/<album>/<track>')
def stream(artist, album, track):
"""View for the raw audio file."""
artist, album, track = map(parse.unquote, (artist, album, track))
for t in tracks:
if (t.artist == artist and
t.album == album and
@ -208,6 +209,7 @@ def stream(artist, album, track):
@app.route('/coverart/<artist>/<album>/<track>')
def coverart(artist, album, track):
"""View for the raw audio file."""
artist, album, track = map(parse.unquote, (artist, album, track))
for t in tracks:
if (t.artist == artist and
t.album == album and