Passed
Push — master ( 8cfbab...2694e9 )
by Quentin
50s
created

main.url_dec()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
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
from threading import Thread
8
9
from flask import Flask, redirect, render_template, url_for
10
import googleapiclient.discovery as google
11
12
import config
13
from util import url_dec, url_enc, YoutubeWrapper
14
15
16
app = Flask(__name__)
17
youtube = YoutubeWrapper()
18
19
20
@app.route('/')
21
def index():
22
    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...
23
                           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...
24
                           # volume=int(player.volume))
25
                           volume=100)
26
27
28
@app.route('/search/<keyword>')
29
def search_results(keyword):
30
    keyword = url_dec(keyword)
31
    vids = youtube.search(keyword, 50)
32
    return render_template('results.html', videos=vids,
33
                           header='Search Results', subheader='For: '+keyword)
34
35
36
@app.route('/rec/<ytid>/<title>')
37
def yt_recommendations(ytid, title):
38
    title = url_dec(title)
39
    vids = youtube.search(ytid, 50, recs=True)
40
    return render_template('results.html', videos=vids,
41
                           header='Recommendations',
42
                           subheader='Based on: '+title)
43
44
45
@app.route('/add/<ytid>/<title>')
46
def add_song(ytid, title):
47
    title = url_dec(title)
48
    already_downloaded = False
49
    if os.path.isfile('downloads/'+ytid):
50
        already_downloaded = True
51
    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...
52
    return render_template('added')
53
54
55
@app.route('/remove/<ytid>')
56
def remove_song(ytid):
57
    global queue
58
    queue = list(filter(lambda x: x[0] != ytid, queue))
59
    return redirect(url_for('/'))
60
61
62
# @app.route('/skip')
63
# def skip_song():
64
#     player.seek(100, 'absolute-percent')
65
#     return redirect(url_for('/'))
66
67
68
# @app.route('/volume/<vol>')
69
# def change_volume(vol):
70
#     if int(vol) > player.volume_max:
71
#         player.volume = player.volume_max
72
#     else:
73
#         player.volume = vol
74
#     return redirect(url_for('/'))
75