~metalune/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH 1/2] Support video subtitles in HTML output, allow to run on different interface/port, update README

southerntofu
Details
Message ID
<20210728184225.681784-1-southerntofu@thunix.net>
DKIM signature
missing
Download raw message
Patch: +45 -3
---
 README.md            | 27 ++++++++++++++++++++++++++-
 main.py              | 14 +++++++++++++-
 peertube.py          |  4 ++++
 templates/video.html |  3 ++-
 4 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 4994ad3..03792e0 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
### SimpleerTube
# SimpleerTube

Active Known Instances:
- https://simpleertube.metalune.xyz
@@ -11,3 +11,28 @@ If you want to visit any page from your PeerTube instance of choice in SimpleerT
So, `https://videos.lukesmith.xyz/accounts/luke` becomes `https://simpleertube.metalune.xyz/videos.lukesmith.xyz/accounts/luke`.

If you visit the main page, you can search globally (it uses [Sepia Search](https://sepiasearch.org) in the backend).

## Setup

You need to setup the `quart` web framework first, usually using pip (`sudo apt install python3-pip` on Debian):

```
$ sudo pip3 install quart
```

**Note:** If there are other dependencies that are not packaged with your system, please report them to us so they can be added to this README.

Now you can run a development environment like so:

```
$ python3 main.py # Starts on localhost:5000
$ python3 main.py 192.168.42.2 # Starts on 192.168.42.2:5000
$ python3 main.py 7171 # Starts on localhost:7171
$ python3 main.py 192.168.42.2 7171 # Starts on 192.168.42.2:7171
```

It is strongly disrecommended to run the production using this command. Instead, please refer to the [Quart deployment docs](https://pgjones.gitlab.io/quart/tutorials/deployment.html).

## License

This software is distributed under the AGPLv3 license. You can find a copy in the [LICENSE](LICENSE) file.
diff --git a/main.py b/main.py
index be65f29..d0596ec 100644
--- a/main.py
+++ b/main.py
@@ -3,6 +3,7 @@ from datetime import datetime
from math import ceil
import peertube
import html2text
import sys

h2t = html2text.HTML2Text()
h2t.ignore_links = True
@@ -29,6 +30,7 @@ class VideoWrapper:
        self.commentsEnabled = a["commentsEnabled"]

        self.resolutions = []
        self.captions = a["captions"]
        self.video = None

        self.files = a["files"]
@@ -250,6 +252,7 @@ async def search(domain, term, page):
@app.route("/<string:domain>/videos/watch/<string:id>/")
async def video(domain, id):
    data = peertube.video(domain, id)
    data["captions"] = peertube.video_captions(domain, id)
    quality = request.args.get("quality")
    embed = request.args.get("embed")
    vid = VideoWrapper(data, quality)
@@ -397,4 +400,13 @@ async def video_channels__about(domain, name):
    )

if __name__ == "__main__":
    app.run()
    if len(sys.argv) == 3:
        interface = sys.argv[1]
        port = sys.argv[2]
    elif len(sys.argv) == 2:
        interface = "127.0.0.1"
        port = sys.argv[1]
    else:
        interface = "127.0.0.1"
        port = "5000"
    app.run(host=interface, port=port)
diff --git a/peertube.py b/peertube.py
index 5bbc03e..b5011b4 100644
--- a/peertube.py
+++ b/peertube.py
@@ -22,6 +22,10 @@ def video(domain, id):
    url = "https://" + domain + "/api/v1/videos/" + id
    return json.loads(requests.get(url).text)

def video_captions(domain, id):
    url = "https://" + domain + "/api/v1/videos/" + id + "/captions"
    return json.loads(requests.get(url).text)

def search(domain, term, start=0, count=10):
    url = "https://" + domain + "/api/v1/search/videos?start=" + str(start) + "&count=" + str(count) + "&search=" + term + "&sort=-match&searchTarget=local"
    return json.loads(requests.get(url).text)
diff --git a/templates/video.html b/templates/video.html
index 80c6b90..7206987 100644
--- a/templates/video.html
+++ b/templates/video.html
@@ -22,7 +22,8 @@ By:
    <b>Resolutions:</b>
{% else %}
    <video height="300" style="max-width: 100%" controls>
        <source src="{{ video.video }}">
        <source src="{{ video.video }}">{% for track in video.captions.data %}
        <track kind="subtitles" srclang="{{ track.language.id }}" src="https://{{ domain }}{{ track.captionPath }}">{% endfor %}
    </video>
    <br>
    <b>Resolutions:</b>
-- 
2.30.2

[PATCH 2/2] Don't produce garbage logs when browser asks for favicon, do 404 instead

southerntofu
Details
Message ID
<20210728184225.681784-2-southerntofu@thunix.net>
In-Reply-To
<20210728184225.681784-1-southerntofu@thunix.net> (view parent)
DKIM signature
missing
Download raw message
Patch: +3 -1
---
 README.md | 1 +
 main.py   | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 03792e0..548c156 100644
--- a/README.md
+++ b/README.md
@@ -29,6 +29,7 @@ $ python3 main.py # Starts on localhost:5000
$ python3 main.py 192.168.42.2 # Starts on 192.168.42.2:5000
$ python3 main.py 7171 # Starts on localhost:7171
$ python3 main.py 192.168.42.2 7171 # Starts on 192.168.42.2:7171
$ python3 main.py ::1 7171 # Also works with IPv6 addresses
```

It is strongly disrecommended to run the production using this command. Instead, please refer to the [Quart deployment docs](https://pgjones.gitlab.io/quart/tutorials/deployment.html).
diff --git a/main.py b/main.py
index d0596ec..576a08a 100644
--- a/main.py
+++ b/main.py
@@ -1,4 +1,4 @@
from quart import Quart, request, render_template, redirect
from quart import Quart, request, render_template, redirect, abort
from datetime import datetime
from math import ceil
import peertube
@@ -150,6 +150,7 @@ async def simpleer_search(query, page):

@app.route("/<string:domain>/")
async def instance(domain):
    if domain == "favicon.ico": abort(404)
    return redirect("/" + domain + "/videos/trending")

@app.route("/<string:domain>/videos/local", defaults = {"page": 1})
-- 
2.30.2
Reply to thread Export thread (mbox)