-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
88 lines (72 loc) · 2.63 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
import flask
import pafy
import os
import subprocess
from flask import Flask, request, jsonify, url_for, abort, render_template
from flask_ngrok import run_with_ngrok
from threading import Timer
app = Flask(__name__)
app.config["DEBUG"] = True
#run_with_ngrok(app) # Start ngrok when app is run
# Create some test data for our catalog in the form of a list of dictionaries.
# books = [
# {'id': 0,
# 'title': 'A Fire Upon the Deep',
# 'author': 'Vernor Vinge',
# 'first_sentence': 'The coldsleep itself was dreamless.',
# 'year_published': '1992'},
# {'id': 1,
# 'title': 'The Ones Who Walk Away From Omelas',
# 'author': 'Ursula K. Le Guin',
# 'first_sentence': 'With a clamor of bells that set the swallows soaring, the Festival of Summer came to the city Omelas, bright-towered by the sea.',
# 'published': '1973'},
# {'id': 2,
# 'title': 'Dhalgren',
# 'author': 'Samuel R. Delany',
# 'first_sentence': 'to wound the autumnal city.',
# 'published': '1975'}
# ]
#CurrentFileName = './static/audio/LiSA 『炎』 -MUSiC CLiP-.m4a'
#FinalFileName = './static/audio/LiSA 『炎』 -MUSiC CLiP-.mp3'
@app.route('/', methods=['GET'])
def home():
return render_template('index.html')
# A route to return all of the available entries in our catalog.
# @app.route('/api/v1/resources/books/all', methods=['GET'])
# def api_all():
# return jsonify(books)
@app.route('/api/v1/download', methods=['POST'])
def download():
content = request.get_json(force=True)
ip = request.remote_addr
vUrl = content['url']
vType = content['type']
server_path = './static/' + vType
if (vType != "video" and vType != "audio"):
abort(404)
v = pafy.new(vUrl)
#logger
try:
with open('log.txt', 'a') as the_file:
the_file.write('{0} {1} {2} {3}\n'.format(ip, vType, vUrl, v.title))
except:
pass
path = 'error'
if (vType == "video"):
v.getbest().download(server_path)
path = v.title + '.mp4'
else:
v.getbestaudio('m4a').download(server_path)
path = v.title + '.m4a'
#mp3_path = v.title + '.mp3'
#subprocess.call(['ffmpeg', '-y', '-i', './static/audio/' + path, './static/audio/' + mp3_path]) # convert m4a to mp3
#subprocess.call(['ffmpeg', '-y', '-i', CurrentFileName, FinalFileName])
#os.remove(server_path + '/' + path)
return url_for('static', filename = vType + '/' + path)
if __name__ == '__main__':
app.run(port=3176, debug=True)
#app.run()
#Steps to put it online:
# 1. lt --port 3176 --subdomain zachan0001
# 2. NameCheap redirect
# 3. python main.py