Issues (3)

main.py (3 issues)

1
# -*- coding: utf-8 -*-
2
#
3
# Copyright 2020 Quentin Kniep <[email protected]>
4
# Distributed under terms of the MIT license.
5
6
import os.path
7
8
from flask import Flask, redirect, render_template, url_for
9
10
from util import url_dec, url_enc, YoutubeWrapper
11
12
13
app = Flask(__name__)
14
youtube = YoutubeWrapper()
15
16
17
@app.route('/')
18
def index():
19
    return render_template('index.html', videos=queue,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable queue does not seem to be defined.
Loading history...
20
                           numVids=len(queue), current=currentlyPlaying,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable currentlyPlaying does not seem to be defined.
Loading history...
21
                           # volume=int(player.volume))
22
                           volume=100)
23
24
25
@app.route('/search/<keyword>')
26
def search_results(keyword):
27
    keyword = url_dec(keyword)
28
    vids = youtube.search(keyword, 50)
29
    return render_template('results.html', videos=vids,
30
                           header='Search Results', subheader='For: '+keyword)
31
32
33
@app.route('/rec/<ytid>/<title>')
34
def yt_recommendations(ytid, title):
35
    title = url_dec(title)
36
    vids = youtube.search(ytid, 50, recs=True)
37
    return render_template('results.html', videos=vids,
38
                           header='Recommendations',
39
                           subheader='Based on: '+title)
40
41
42
@app.route('/add/<ytid>/<title>')
43
def add_song(ytid, title):
44
    title = url_dec(title)
45
    already_downloaded = False
46
    if os.path.isfile('downloads/'+ytid):
47
        already_downloaded = True
48
    queue.append([ytid, title, url_enc(title), already_downloaded])
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable queue does not seem to be defined.
Loading history...
49
    return render_template('added')
50
51
52
@app.route('/remove/<ytid>')
53
def remove_song(ytid):
54
    global queue
55
    queue = list(filter(lambda x: x[0] != ytid, queue))
56
    return redirect(url_for('/'))
57
58
59
# @app.route('/skip')
60
# def skip_song():
61
#     player.seek(100, 'absolute-percent')
62
#     return redirect(url_for('/'))
63
64
65
# @app.route('/volume/<vol>')
66
# def change_volume(vol):
67
#     if int(vol) > player.volume_max:
68
#         player.volume = player.volume_max
69
#     else:
70
#         player.volume = vol
71
#     return redirect(url_for('/'))
72
73
74
if __name__ == '__main__':
75
    app.run(debug=True)
76