-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
190 lines (163 loc) · 7.06 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
"""
Euphony Server, for playing music from YouTube and other sources right from your browser.
Copyright (C) 2023 SGtOriginal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Contact SGtOriginal using the this email: [email protected]
"""
from flask import *
from threading import Thread
import requests
import time
import os
import sqlite3
import euphony
app = Flask('Euphony', static_folder='static')
@app.route("/")
def home():
return render_template("home.html", search=url_for('search'))
@app.route("/test")
def home_test():
return render_template("home_test.html")
@app.route("/search", methods=['GET', 'POST'])
def search():
if request.method == 'GET':
if request.args.get('name') != None:
name = request.args.get('name')
if "-" in name:
name = " ".join(name.split("-"))
info = euphony.ytsearch(name)
table = []
for i in range(0, len(info)):
table.append(
f"<tr>\n <td>{info[i][0]}</td>\n <td>{info[i][1]}</td>\n <td><a href = '{url_for('play')}?id={info[i][0]}'>Click to listen</a></td>\n</tr>"
)
table = ''.join(table)
return f"<table>\n <tr>\n <th>YTId</th>\n <th>Title</th>\n <th>Link</th>\n </tr>\n {table}\n</table>"
else:
return "<form action=\"search\" method=\"post\">\n <label for=\"search\">Song Name</label>\n <input type=\"text\" name=\"search\" value=\"\" required></br></br>\n <button type=\"submit\">Search</button>\n</form>"
elif request.method == 'POST':
if request.form['search']:
name = request.form['search']
else:
return redirect(url_for("search"))
if "-" in name:
name = " ".join(name.split("-"))
return redirect(url_for("search", name=name))
@app.route("/play")
@app.route("/play/<string:audid>")
def play(audid=None):
if request.args.get('id') != None:
id = request.args.get('id')
check1 = os.listdir(os.path.join(os.getcwd(), 'static', 'music'))
if f"{id}.mp3" not in check1:
conn = sqlite3.connect('euphonydb.db')
cur = conn.cursor()
cur.execute("SELECT * FROM musicdata WHERE id=?", (id, ))
check2 = cur.fetchall()
conn.close()
if len(check2) != 0:
euphony.getfromdb(id)
return render_template("song.html", id=id)
elif len(check2) == 0:
euphony.download(id)
euphony.uploadtodb(id)
return render_template("song.html", id=id)
elif f"{id}.mp3" in check1:
conn = sqlite3.connect('euphonydb.db')
cur = conn.cursor()
cur.execute("SELECT * FROM musicdata WHERE id=?", (id, ))
check2 = cur.fetchall()
if len(check2) != 0:
return render_template("song.html", id=id)
elif len(check2) == 0:
euphony.uploadtodb(id)
return render_template("song.html", id=id)
elif audid != None:
check1 = os.listdir(os.path.join(os.getcwd(), 'static', 'music'))
if f"{audid}.mp3" not in check1:
conn = sqlite3.connect('euphonydb.db')
cur = conn.cursor()
cur.execute("SELECT * FROM musicdata WHERE id=?", (audid, ))
check2 = cur.fetchall()
conn.close()
if len(check2) != 0:
euphony.getfromdb(id)
return send_file(f"static/music/{audid}.mp3", mimetype="audio/mp3")
elif len(check2) == 0:
euphony.download(audid)
euphony.uploadtodb(audid)
return send_file(f"static/music/{audid}.mp3", mimetype="audio/mp3")
elif f"{audid}.mp3" in check1:
conn = sqlite3.connect('euphonydb.db')
cur = conn.cursor()
cur.execute("SELECT * FROM musicdata WHERE id=?", (audid, ))
check2 = cur.fetchall()
if len(check2) != 0:
return send_file(f"static/music/{audid}.mp3", mimetype="audio/mp3")
elif len(check2) == 0:
euphony.uploadtodb(id)
return send_file(f"static/music/{audid}.mp3", mimetype="audio/mp3")
else:
return redirect(url_for("search"))
def run():
app.run(host='0.0.0.0', port=8080)
def server():
th = Thread(target=run)
th.start()
while True:
requests.get("https://Euphony-Server.sgtoriginal.repl.co")
time.sleep(30)
if os.path.exists("static"):
os.chdir("static")
if os.path.exists("music"):
os.chdir(app.root_path)
pass
else:
os.mkdir("music")
os.chdir(app.root_path)
else:
os.mkdir("static")
os.chdir("static")
os.mkdir("music")
os.chdir(app.root_path)
conn = sqlite3.connect("euphonydb.db")
cur = conn.cursor()
cur.executescript("""
CREATE TABLE IF NOT EXISTS "musicdata" (
"id" TEXT,
"url" TEXT,
"yturl" TEXT,
"file" BLOB
)
""")
conn.commit()
if os.name == 'nt':
os.system('cls')
else:
os.system("clear")
print("""
-----------------------------------------------------------------------------------
#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#
-----------------------------------------------------------------------------------
▄████████ ███ █▄ ▄███████▄ ▄█ █▄ ▄██████▄ ███▄▄▄▄ ▄██ ▄
███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███▀▀▀██▄ ███ ██▄
███ █▀ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███▄▄▄███
▄███▄▄▄ ███ ███ ███ ███ ▄███▄▄▄▄███▄▄ ███ ███ ███ ███ ▀▀▀▀▀▀███
▀▀███▀▀▀ ███ ███ ▀█████████▀ ▀▀███▀▀▀▀███▀ ███ ███ ███ ███ ▄██ ███
███ █▄ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
██████████ ████████▀ ▄████▀ ███ █▀ ▀██████▀ ▀█ █▀ ▀█████▀
-----------------------------------------------------------------------------------
X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X#X
-----------------------------------------------------------------------------------
""")
server()