From 49e81ef0e8aa3b1644ee602e9506adf3904fd867 Mon Sep 17 00:00:00 2001 From: metalune Date: Sun, 17 Jan 2021 16:04:24 +0100 Subject: [PATCH] Initial commit --- main.py | 63 +++++++++++++++++++++++++++++++++++ peertube.py | 24 +++++++++++++ templates/domain_index.html | 0 templates/index.html | 0 templates/search_results.html | 24 +++++++++++++ templates/video.html | 51 ++++++++++++++++++++++++++++ 6 files changed, 162 insertions(+) create mode 100644 main.py create mode 100644 peertube.py create mode 100644 templates/domain_index.html create mode 100644 templates/index.html create mode 100644 templates/search_results.html create mode 100644 templates/video.html diff --git a/main.py b/main.py new file mode 100644 index 0000000..ea27539 --- /dev/null +++ b/main.py @@ -0,0 +1,63 @@ +from quart import Quart, request, render_template +import peertube + +# Wrapper, only containing information that's important for us, and in some cases provides simplified ways to get information +class VideoWrapper: + def __init__(self, a, quality): + self.name = a["name"] + self.channel = a["channel"] + self.description = a["description"] + self.thumbnailPath = a["thumbnailPath"] + + self.category = a["category"] + self.licence = a["licence"] + self.language = a["language"] + self.privacy = a["privacy"] + self.tags = a["tags"] + + self.views = a["views"] + self.likes = a["likes"] + self.dislikes = a["dislikes"] + + + + self.resolutions = [] + self.video = None + + for entry in a["files"]: + resolution = (entry["resolution"])["id"] + self.resolutions.append(entry["resolution"]) + + if str(resolution) == str(quality): + self.video = entry["fileUrl"] + + self.no_quality_selected = not self.video + + +app = Quart(__name__) + +@app.route('/') +async def main(): + return await render_template('index.html') + +@app.route('/') +async def domain_main(domain): + return await render_template('domain_index.html') + +@app.route('//search/') +async def search(domain, term): + amount, results = peertube.search(domain, term) + return await render_template('search_results.html', domain=domain, amount=amount, results=results) + +@app.route('//watch//') +async def video(domain, id): + data = peertube.video(domain, id) + quality = request.args.get("quality") + if quality == None: + quality = "best" + vid = VideoWrapper(data, quality) + + return await render_template('video.html', video=vid, quality=quality) + +if __name__ == "__main__": + app.run() diff --git a/peertube.py b/peertube.py new file mode 100644 index 0000000..94a113a --- /dev/null +++ b/peertube.py @@ -0,0 +1,24 @@ +from bs4 import BeautifulSoup +import requests +import json + +def video(domain, id): + video_url = "https://" + domain + "/api/v1/videos/" + id + video_object = json.loads(requests.get(video_url).text) + return video_object + +def search(domain, term, start = 0, count = 10): + search_url = "https://" + domain + "/api/v1/search/videos?start=" + str(start) + "&count=" + str(count) + "&search=" + term + "&sort=-match&searchTarget=local" + search_object = json.loads(requests.get(search_url).text) + + amount = search_object["total"] + results = search_object["data"] + + return amount, results + + +if __name__ == "__main__": + vid = video("diode.zone", "5405dac8-05c1-4512-b842-67be43ce7442") + print(json.dumps(vid, indent=2)) + #_, results = search("diode.zone", "test") + #print(json.dumps(results, indent=2)) diff --git a/templates/domain_index.html b/templates/domain_index.html new file mode 100644 index 0000000..e69de29 diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..e69de29 diff --git a/templates/search_results.html b/templates/search_results.html new file mode 100644 index 0000000..c70b4f1 --- /dev/null +++ b/templates/search_results.html @@ -0,0 +1,24 @@ + + + +

{{ amount }} results

+ + {% for result in results %} + + + + + {% endfor %} +
+ + + + + {{ result.name }} +
+ {{ result.views }} Views +
+ {{ result.channel.displayName }} +
+ + diff --git a/templates/video.html b/templates/video.html new file mode 100644 index 0000000..891e590 --- /dev/null +++ b/templates/video.html @@ -0,0 +1,51 @@ + + + +

{{ video.name }}

+ By: + {{ video.channel.displayName }} ({{ video.channel.name }}@{{ video.channel.host }}) +
+ {% if video.no_quality_selected %} + +

Please select a resolution:

+ {% else %} + +
+ Resolutions: + {% endif %} + + {% for resolution in video.resolutions %} + {{ resolution.label }} + {% endfor %} + +
+ Views: {{ video.views }} Likes: {{ video.likes }} Dislikes: {{ video.dislikes }} + +
+
+ {{ video.description }} +
+
+ + + + + + + + + + + + + + + + + + +
Category{{ video.category.label }}
License{{ video.licence.label }}
Language{{ video.language.label }}
Privacy{{ video.privacy.label }}
+ +