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