~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
13 2

[PATCH 1/6] Support custom interface/port in main.py

southerntofu
Details
Message ID
<20210728234335.2325479-1-southerntofu@thunix.net>
DKIM signature
missing
Download raw message
Patch: +11 -2
---
 main.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/main.py b/main.py
index be65f29..8f9961c 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
@@ -281,7 +282,6 @@ async def video(domain, id):
        embed=embed,
    )


def build_channel_or_account_name(domain, name):
    if '@' in name:
        return name
@@ -397,4 +397,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)
-- 
2.30.2

[PATCH 2/6] Update the README

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

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

Active Known Instances:
- https://simpleertube.metalune.xyz
@@ -11,3 +11,29 @@ 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 a few dependencies first, usually using pip (`sudo apt install python3-pip` on Debian):

```
$ sudo pip3 install quart bs4 html2text lxml
```

**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
$ 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).

## License

This software is distributed under the AGPLv3 license. You can find a copy in the [LICENSE](LICENSE) file.
-- 
2.30.2

[PATCH 3/6] Don't commit vim temporary files

southerntofu
Details
Message ID
<20210728234335.2325479-3-southerntofu@thunix.net>
In-Reply-To
<20210728234335.2325479-1-southerntofu@thunix.net> (view parent)
DKIM signature
missing
Download raw message
Patch: +1 -0
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index c18dd8d..e501caa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
__pycache__/
.*.sw*
-- 
2.30.2

[PATCH 4/6] Don't traceback when favicon.ico is requested, display a nice error instead

southerntofu
Details
Message ID
<20210728234335.2325479-4-southerntofu@thunix.net>
In-Reply-To
<20210728234335.2325479-1-southerntofu@thunix.net> (view parent)
DKIM signature
missing
Download raw message
Patch: +15 -0
---
 main.py              | 7 +++++++
 templates/error.html | 8 ++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 templates/error.html

diff --git a/main.py b/main.py
index 8f9961c..2d884a1 100644
--- a/main.py
+++ b/main.py
@@ -149,6 +149,13 @@ async def simpleer_search(query, page):

@app.route("/<string:domain>/")
async def instance(domain):
    # favicon.ico is not a domain name
    if domain == "favicon.ico":
        return await render_template(
            "error.html",
            error_number = "404",
            error_reason = "We don't have a favicon yet. If you would like to contribute one, please send it to ~metalune/public-inbox@lists.sr.ht"
        ), 404
    return redirect("/" + domain + "/videos/trending")

@app.route("/<string:domain>/videos/local", defaults = {"page": 1})
diff --git a/templates/error.html b/templates/error.html
new file mode 100644
index 0000000..7d8f4c5
--- /dev/null
+++ b/templates/error.html
@@ -0,0 +1,8 @@
{% extends "base.html" %}

{% block title %}ERROR: {% endblock %}

{% block content %}
<h1>Error {{ error_number }}</h1>
<p>{{ error_reason }}</p>
{% endblock %}
-- 
2.30.2

[PATCH 5/6] Propose subtitles in the native video player

southerntofu
Details
Message ID
<20210728234335.2325479-5-southerntofu@thunix.net>
In-Reply-To
<20210728234335.2325479-1-southerntofu@thunix.net> (view parent)
DKIM signature
missing
Download raw message
Patch: +27 -1
---
 main.py              | 15 +++++++++++++++
 peertube.py          | 10 ++++++++++
 templates/video.html |  3 ++-
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/main.py b/main.py
index 2d884a1..3c20fb9 100644
--- a/main.py
+++ b/main.py
@@ -12,6 +12,7 @@ h2t.ignore_links = True
class VideoWrapper:
    def __init__(self, a, quality):
        self.name = a["name"]
        self.uuid = a["uuid"]
        self.channel = a["channel"]
        self.description = a["description"]
        self.thumbnailPath = a["thumbnailPath"]
@@ -19,6 +20,7 @@ class VideoWrapper:
        self.category = a["category"]
        self.licence = a["licence"]
        self.language = a["language"]
        self.captions = a["captions"]
        self.privacy = a["privacy"]
        self.tags = a["tags"]

@@ -258,6 +260,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)
@@ -403,6 +406,18 @@ async def video_channels__about(domain, name):
        about = peertube.video_channel(domain, name)
    )

# --- Subtitles/captions proxying ---
@app.route("/<string:domain>/videos/watch/<string:id>/<string:lang>.vtt")
async def subtitles(domain, id, lang):
    try:
        return peertube.video_captions_download(domain, id, lang)
    except Exception as e:
        return await render_template(
            "error.html",
            error_number = "500",
            error_reason = e
        ), 500

if __name__ == "__main__":
    if len(sys.argv) == 3:
        interface = sys.argv[1]
diff --git a/peertube.py b/peertube.py
index 5bbc03e..186c473 100644
--- a/peertube.py
+++ b/peertube.py
@@ -22,6 +22,16 @@ 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 video_captions_download(domain, id, lang):
    # URL is hardcoded to prevent further proxying. URL may change with updates, see captions API
    # eg. https://kolektiva.media/api/v1/videos/9c9de5e8-0a1e-484a-b099-e80766180a6d/captions
    url = "https://" + domain + "/lazy-static/video-captions/" + id + '-' + lang + ".vtt"
    return 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..d64f791 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 }}" label="{{ track.language.label }}" src="/{{ domain }}/videos/watch/{{ video.uuid }}/{{ track.language.id }}.vtt">{% endfor %}
    </video>
    <br>
    <b>Resolutions:</b>
-- 
2.30.2

[PATCH 6/6] Also serve /favicon.ico directly as 404 to avoid pointless requests

southerntofu
Details
Message ID
<20210728234335.2325479-6-southerntofu@thunix.net>
In-Reply-To
<20210728234335.2325479-1-southerntofu@thunix.net> (view parent)
DKIM signature
missing
Download raw message
Patch: +10 -6
---
 main.py | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/main.py b/main.py
index 3c20fb9..d326f0a 100644
--- a/main.py
+++ b/main.py
@@ -152,12 +152,7 @@ async def simpleer_search(query, page):
@app.route("/<string:domain>/")
async def instance(domain):
    # favicon.ico is not a domain name
    if domain == "favicon.ico":
        return await render_template(
            "error.html",
            error_number = "404",
            error_reason = "We don't have a favicon yet. If you would like to contribute one, please send it to ~metalune/public-inbox@lists.sr.ht"
        ), 404
    if domain == "favicon.ico": return await favicon()
    return redirect("/" + domain + "/videos/trending")

@app.route("/<string:domain>/videos/local", defaults = {"page": 1})
@@ -418,6 +413,15 @@ async def subtitles(domain, id, lang):
            error_reason = e
        ), 500

# --- Favicon ---
@app.route("/favicon.ico")
async def favicon():
    return await render_template(
        "error.html",
        error_number = "404",
        error_reason = "We don't have a favicon yet. If you would like to contribute one, please send it to ~metalune/public-inbox@lists.sr.ht"
    ), 404

if __name__ == "__main__":
    if len(sys.argv) == 3:
        interface = sys.argv[1]
-- 
2.30.2

Re: [PATCH 2/6] Update the README

Details
Message ID
<CD6N31AYW7UZ.17IBD1O3RVFXN@thinkpad>
In-Reply-To
<20210728234335.2325479-2-southerntofu@thunix.net> (view parent)
DKIM signature
pass
Download raw message
Thank you
Details
Message ID
<CD6N7QKKZISG.2OHMWRT552GG8@thinkpad>
In-Reply-To
<20210728234335.2325479-1-southerntofu@thunix.net> (view parent)
DKIM signature
pass
Download raw message
thank you

Re: [PATCH 4/6] Don't traceback when favicon.ico is requested, display a nice error instead

Details
Message ID
<CD6N7ZXB7YO1.1FEZZSHH4VUUK@thinkpad>
In-Reply-To
<20210728234335.2325479-4-southerntofu@thunix.net> (view parent)
DKIM signature
pass
Download raw message
Thank you

Re: [PATCH 3/6] Don't commit vim temporary files

Details
Message ID
<CD6N8M1TOG78.HHTAAQRKV5EN@thinkpad>
In-Reply-To
<20210728234335.2325479-3-southerntofu@thunix.net> (view parent)
DKIM signature
pass
Download raw message
Seems a little bit unnecessary, but I guess that is useful for some
people

Re: [PATCH 6/6] Also serve /favicon.ico directly as 404 to avoid pointless requests

Details
Message ID
<CD6N8UKDQTXW.I5EDUQZQD1GM@thinkpad>
In-Reply-To
<20210728234335.2325479-6-southerntofu@thunix.net> (view parent)
DKIM signature
pass
Download raw message
Thank you

Re: [PATCH 6/6] Also serve /favicon.ico directly as 404 to avoid pointless requests

Details
Message ID
<CD6N9S2IXPQ6.3QW4CIJMY3N53@thinkpad>
In-Reply-To
<20210728234335.2325479-6-southerntofu@thunix.net> (view parent)
DKIM signature
pass
Download raw message
Pardon, I replied to the wrong email, this patch doesn't apply to the
current version

Re: [PATCH 5/6] Propose subtitles in the native video player

Details
Message ID
<CD6NB0X0RGWF.O28YSKCGDGCO@thinkpad>
In-Reply-To
<20210728234335.2325479-5-southerntofu@thunix.net> (view parent)
DKIM signature
pass
Download raw message
Thank you

Re: [PATCH 6/6] Also serve /favicon.ico directly as 404 to avoid pointless requests

Details
Message ID
<CD77SN2963YG.2G0Q5QRW4TD9J@thinkpad>
In-Reply-To
<20210728234335.2325479-6-southerntofu@thunix.net> (view parent)
DKIM signature
pass
Download raw message
Thank you
Reply to thread Export thread (mbox)