Initial commit

This commit is contained in:
metalune 2021-01-17 16:04:24 +01:00
parent d3024bcdb6
commit 49e81ef0e8
6 changed files with 162 additions and 0 deletions

63
main.py Normal file
View file

@ -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('/<string:domain>')
async def domain_main(domain):
return await render_template('domain_index.html')
@app.route('/<string:domain>/search/<string:term>')
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('/<string:domain>/watch/<string:id>/')
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()

24
peertube.py Normal file
View file

@ -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))

View file

0
templates/index.html Normal file
View file

View file

@ -0,0 +1,24 @@
<!doctype html>
<html>
<body>
<p>{{ amount }} results</p>
<table>
{% for result in results %}
<tr>
<td>
<a href="/{{ domain}}/watch/{{ result.uuid }}">
<img src="https://{{ domain }}/{{ result.thumbnailPath }}" height="150"/>
</a>
</td>
<td>
<a href="/{{ domain }}/watch/{{ result.uuid }}">{{ result.name }}</a>
<br>
{{ result.views }} Views
<br>
<b>{{ result.channel.displayName }}</b>
</td>
</tr>
{% endfor %}
</table>
</body>
</html>

51
templates/video.html Normal file
View file

@ -0,0 +1,51 @@
<!doctype html>
<html>
<body>
<h3>{{ video.name }}</h3>
By:
<b>{{ video.channel.displayName }}</b> ({{ video.channel.name }}@{{ video.channel.host }})
<br>
{% if video.no_quality_selected %}
<img height="300" src="https://{{ video.channel.host }}{{ video.thumbnailPath }}">
<p style="color: red">Please select a resolution:</p>
{% else %}
<video height="300" controls>
<source src="{{ video.video }}">
</video>
<br>
<b>Resolutions:</b>
{% endif %}
{% for resolution in video.resolutions %}
<a href="?quality={{ resolution.id }}">{{ resolution.label }}</a>
{% endfor %}
<br>
Views: <b>{{ video.views }}</b> Likes: <b>{{ video.likes }}</b> Dislikes: <b>{{ video.dislikes }}</b>
<br>
<br>
{{ video.description }}
<br>
<br>
<table>
<tr>
<td><b>Category</b></td>
<td>{{ video.category.label }}</td>
</tr>
<tr>
<td><b>License</b></td>
<td>{{ video.licence.label }}</td>
</tr>
<tr>
<td><b>Language</b></td>
<td>{{ video.language.label }}</td>
</tr>
<tr>
<td><b>Privacy</b></td>
<td>{{ video.privacy.label }}</td>
</tr>
</table>
</body>
</html>