-
Notifications
You must be signed in to change notification settings - Fork 0
/
catapy.py
executable file
·151 lines (135 loc) · 5.18 KB
/
catapy.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/python3
from flask import Flask, request, render_template, redirect
import yt_dlp as youtube_dl
import pandas as pd
import numpy as np
import os
import guigolock as ggl
app = Flask(__name__)
if os.path.exists("/home/pi/karaokeApplication/catalogo.csv"):
df = pd.read_csv("/home/pi/karaokeApplication/catalogo.csv", delimiter =',', encoding = 'utf-8', dtype=str)
else:
df = pd.read_csv("./catalogo.csv", delimiter=',', encoding='utf-8', dtype=str)
if os.path.exists("catalogo_custom.csv"):
dfc = pd.read_csv("catalogo_custom.csv", delimiter =',', encoding = 'utf-8', dtype=str)
dt = pd.concat([df, dfc])
else:
dfc = pd.DataFrame(columns=df.columns)
dt = df
def downloadYouTube(videourl, path, name):
ydl_opts = {
'outtmpl': name + ".mp4" , 'format' : 'mp4'
}
os.chdir(path)
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([videourl])
if os.path.exists("/home/pi/karaokeApplication/"):
os.chdir("/home/pi/karaokeApplication/")
else:
os.chdir("../")
@app.route('/', methods=['GET', 'POST'])
def html_table():
text = request.form.get('textbox')
print(text)
if text is None:
return render_template('cataLogo.html', tables=[dt.iloc[:,[0,2,3,4]].to_html(classes='data', index=False)], titles=dt.iloc[:,[0,2,3,4]].columns.values)
else:
rows = np.column_stack([dt[col].str.contains(text, na=False, case=False) for col in dt])
return render_template('cataLogo.html', tables=[dt.iloc[:,[0,2,3,4]][rows.any(axis=1)].to_html(classes='data', index=False)], titles=dt.iloc[:,[0,2,3,4]].columns.values)
@app.route('/fila', methods=['GET', 'POST'])
def filas():
fila = pd.read_csv('./filomena', index_col=[0])
print(fila)
return render_template('fila.html', tables=fila, titles=fila.columns.values)
@app.route('/fila_adm', methods=['GET', 'POST'])
def fila_adm():
fila = pd.read_csv('./filomena', index_col=[0])
print(fila)
return render_template('fila_adm.html', tables=fila)
@app.route('/delete/<musc_id>', methods=['POST'])
def delete_music(musc_id):
print(musc_id)
a = musc_id.split('_')
b = int(a[0])
c = int(a[1])
while ggl.check_free('./filomena', 'ctp') != True:
print('filomena presa')
fila = pd.read_csv('./filomena', index_col=[0])
if len(fila['codigo']) > 1 and fila['codigo'].iloc[b] == c:
fila = fila.drop(b)
fila = fila.reset_index(drop=True)
elif len(fila['codigo']) == 1 and int(fila['codigo']) == c:
fila = fila.drop(b)
fila = fila.reset_index(drop=True)
else:
print("tamo deletano coisa errada irmao")
fila.to_csv('./filomena')
while ggl.release('./filomena', 'ctp') != True:
print('incapaz de liberar filomena')
return redirect('/fila_adm')
@app.route('/up/<musc_id>', methods=['POST'])
def up_music(musc_id):
print(musc_id)
a = musc_id.split('_')
b = int(a[0])
c = int(a[1])
while ggl.check_free('./filomena', 'ctp') != True:
print('filomena presa')
fila = pd.read_csv('./filomena', index_col=[0])
if len(fila['codigo']) > 1 and b != 0 and fila['codigo'].iloc[b] == c:
tempind = fila.index.values.copy()
tempind[b] = b-1
tempind[b-1] = b
fila = fila.reindex(tempind)
fila = fila.reset_index(drop=True)
else:
print("tamo movendo coisa errada irmao")
fila.to_csv('./filomena')
while ggl.release('./filomena', 'ctp') != True:
print('incapaz de liberar filomena')
return redirect('/fila_adm')
@app.route('/down/<musc_id>', methods=['POST'])
def down_music(musc_id):
print(musc_id)
a = musc_id.split('_')
b = int(a[0])
c = int(a[1])
while ggl.check_free('./filomena', 'ctp') != True:
print('filomena presa')
fila = pd.read_csv('./filomena', index_col=[0])
if len(fila['codigo']) > 1 and b < len(fila['codigo'])-1 and fila['codigo'].iloc[b] == c:
tempind = fila.index.values.copy()
tempind[b] = b+1
tempind[b+1] = b
fila = fila.reindex(tempind)
fila = fila.reset_index(drop=True)
else:
print("tamo movendo coisa errada irmao")
fila.to_csv('./filomena')
while ggl.release('./filomena', 'ctp') != True:
print('incapaz de liberar filomena')
return redirect('/fila_adm')
@app.route('/download', methods=['GET', 'POST'])
def download():
return render_template('download.html')
@app.route('/handle_download', methods=['GET', 'POST'])
def handle_download():
global dfc
global dt
global df
url = request.form.get('URL')
artista = request.form.get('artista')
musica = request.form.get('musica')
number = '90000'
if not dfc.empty:
number = str(int(dfc['code'].max()) + 1)
if os.path.exists("/media/pi/Elements/karaoke/musicas/"):
downloadYouTube(url, "/media/pi/Elements/karaoke/musicas/", number)
else:
downloadYouTube(url, "./musicas/", number)
dfc = dfc.append(pd.Series([number, number + ".mp4" , artista, musica, "nan"], index=dfc.columns ), ignore_index=True)
dfc.to_csv('catalogo_custom.csv', index=False, sep =',')
dt = pd.concat([df, dfc])
return redirect('/')
if __name__ == '__main__':
app.run(host='0.0.0.0')