summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <yuval@y3xz.com>2016-04-23 18:49:59 +0300
committerYuval Adam <yuval@y3xz.com>2016-04-23 18:49:59 +0300
commitc07c1b8416f7656e88c1671610cbbb0de51f2918 (patch)
treec6ac7feefe8b0f0f38f6613845426f351200feb4
parent313467142882a48405e764b3beee9ba8653e012f (diff)
Basic POC working
-rw-r--r--.gitignore2
-rw-r--r--static/vids/.keep0
-rw-r--r--templates/index.html22
-rw-r--r--yaas.py25
4 files changed, 46 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..00c4beb
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+static/vids/*
+!static/vids/.keep
diff --git a/static/vids/.keep b/static/vids/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/static/vids/.keep
diff --git a/templates/index.html b/templates/index.html
new file mode 100644
index 0000000..7437fc4
--- /dev/null
+++ b/templates/index.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>YaaS</title>
+ </head>
+ <body>
+ <h1>YaaS</h1>
+ <p>Paste a valid youtube URL</p>
+ <form action="/upload" method="POST">
+ <input name="url" type="text"></input>
+ <input name="submit" type="submit" value="Upload"></input>
+ </form>
+ <ul>
+ {% for v in vids %}
+ <li><a href="/static/vids/{{ v }}">{{ v }}</a></li>
+ {% endfor %}
+ </ul>
+ </body>
+</html>
diff --git a/yaas.py b/yaas.py
index 7fad1a7..b98d97a 100644
--- a/yaas.py
+++ b/yaas.py
@@ -1,9 +1,28 @@
-from flask import Flask
+import os
+import youtube_dl
+
+from flask import Flask, redirect, request, render_template
+
app = Flask(__name__)
@app.route('/')
-def hello():
- return 'Hello World!'
+def index():
+ vids = os.listdir('static/vids')
+ return render_template('index.html', vids=vids)
+
+
+@app.route('/upload', methods=['POST'])
+def upload():
+ url = request.form['url']
+ if url:
+ ydl_opts = {
+ 'outtmpl': 'static/vids/%(id)s.%(ext)s'
+ }
+ with youtube_dl.YoutubeDL(ydl_opts) as ydl:
+ info_dict = ydl.extract_info(url, download=False)
+ ydl.download([url])
+
+ return redirect('/')
if __name__ == '__main__':
app.run()