From e9eaabaa69d33323fe311e7176d97e79057bb3d3 Mon Sep 17 00:00:00 2001 From: rebane2001 Date: Thu, 11 May 2023 17:16:46 +0300 Subject: [PATCH 1/3] Updated readme --- README.md | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6e84e27..cee9916 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,25 @@ A lightweight static HTML generator for self-hosting yt-dlp video archives. # Features - Static HTML (fast and secure) - Parses yt-dlp info.json format -- Channel pages (with thumbnails) +- Channel pages (with thumbnails, name history) - Watch page (with stats, description etc) - Download buttons (video, description, thumbnail, subtitles) -- Highlight deleted videos -- Client-side search +- Highlight deleted/unlisted videos +- Client-side search/sorting # Usage 1. Clone this repo (or download as zip). -2. Rename the `default.json` file to `config.json` and edit the `ytpath`, `ytpathweb`, `webpath`, `outpath` and `removedvideosfile` variables to suit your setup. -3. Run `python3 hobune.py`, this will generate HTML files in your `outpath`. +2. Rename the `default.json` file to `config.json` and edit the variables to suit your setup: + - `site_name`: Name/Title of the site (e.g. "Hobune") + - `files_path`: Local path of the video files (e.g. "/var/www/html/files/") + - `files_web_path`: Web path of the video files (e.g. "/files/" or "https://example.com/files/") + - `web_root`: Web root path (e.g. "/" or "https://example.com/") + - `output_path`: Output path for the HTML files (e.g. "/var/www/html/") + - `add_html_ext`: Add HTML extension to links (e.g. link to /videos/foobar.html instead of /videos/foobar) + - `removed_videos_file`: A text file where each line ends with a removed video ID (optional, e.g. "~/removed_videos.txt") + - `unlisted_videos_file`: Unlisted videos file - similar to the removed videos file (optional) + +3. Run `python3 hobune.py`, this will generate HTML files in your `output_path`. 4. (optionally) Configure your webserver to allow downloads from /dl URLs and HTML pages without extensions. ``` @@ -31,8 +40,3 @@ location /dl { ``` It is also recommended to edit the python script to suit your exact needs, since your setup probably won't be 1:1 same as the expected one. - -# Notes (2022) -This codebase is a bit of a mess at the moment and I need to clean it up and refactor it at some point. Windows is not supported without code changes, although it can be made to work. - -I've also added my comments code to this repo in an unorganized fashion. It is disabled by default, if you'd like to use it please read the contents of `comments.py`. From 4cf5f5900a4cd57e3204ec8f14c398f3f8e2ae72 Mon Sep 17 00:00:00 2001 From: rebane2001 Date: Thu, 11 May 2023 17:31:38 +0300 Subject: [PATCH 2/3] remove tag, add ytlink --- hobune/videos.py | 16 +++++----------- hobune_v2.md | 2 +- templates/hobune.css | 14 +++++++++----- templates/video.html | 2 +- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/hobune/videos.py b/hobune/videos.py index 27e0eb8..62de744 100644 --- a/hobune/videos.py +++ b/hobune/videos.py @@ -8,16 +8,9 @@ from hobune.util import generate_meta_tags, quote_url, no_traverse -def generate_download_button(name, url, tag=None, prefix="/dl"): - tag_part = "" - if tag: - tag_part = f""" - - {html.escape(tag)} - """ +def generate_download_button(name, url, prefix="/dl"): return f""" - {tag_part}
{html.escape(name)}
@@ -75,8 +68,8 @@ def create_video_pages(config, channels, templates, html_ext): for ext in ["webm", "mkv"]: if (alt_file := f"{base}.{ext}") in files: alt_file_url = config.files_web_path + (os.path.join(root, alt_file))[len(config.files_path):] - download_buttons_html = generate_download_button("Download video", mp4path, tag="mp4") + \ - generate_download_button("Download video", alt_file_url, tag=ext) + download_buttons_html = generate_download_button("Download mp4", mp4path) + \ + generate_download_button(f"Download {ext}", alt_file_url) # Description download if (desc_file := f"{base}.description") in files: @@ -92,11 +85,12 @@ def create_video_pages(config, channels, templates, html_ext): if vtt.startswith(base): vtt_url = os.path.join(config.files_web_path + root[len(config.files_path):], vtt) vtt_tag = vtt[len(base) + 1:-len('.vtt')] - download_buttons_html += generate_download_button("Subtitles", vtt_url, tag=vtt_tag) + download_buttons_html += generate_download_button(f"Subtitles ({vtt_tag})", vtt_url) # Create HTML page_html = templates["video"].format( title=html.escape(v['title']), + ytlink=f"
YT", description=html.escape(v['description']).replace('\n', '
'), views=v['view_count'], uploader_url=f"{config.web_root}channels/{html.escape(v['channel_id'])}{html_ext}" if is_full_channel(root) else f'{config.web_root}channels/other{html_ext}', diff --git a/hobune_v2.md b/hobune_v2.md index 091680b..230d938 100644 --- a/hobune_v2.md +++ b/hobune_v2.md @@ -19,7 +19,7 @@ Strikethrough means already implemented. - ~~Make it work on Windows by default~~ - Dedupe videos by default - Comments page should show comments count (both top-level and all) -- Link back to YouTube links whereever possible + ~~- Link back to YouTube links wherever possible~~ - Make it easier to download everything, eg provide a wget command (maybe we could even download and generate a zip in JS for smaller channels?) - Support generating comments even if video itself isn't present - Cache folder listings (so we don't like /other a hundred thousand times) diff --git a/templates/hobune.css b/templates/hobune.css index d39ac24..833ce1c 100644 --- a/templates/hobune.css +++ b/templates/hobune.css @@ -359,16 +359,20 @@ a { padding: 7px 14px; } +.ytlink { + font-size: 14px; +} + +.tag { + font-size: 14px; + color: rgba(0,0,0,.6); +} + .rounded { border-radius: 5px; overflow: hidden; } -.ui.footer.segment { - margin: 5em 0em 0em; - padding: 5em 0em; -} - .hide { display: none!important; } diff --git a/templates/video.html b/templates/video.html index 7264f73..6b19982 100644 --- a/templates/video.html +++ b/templates/video.html @@ -10,7 +10,7 @@

{title}

{comments} -

Description

+

Description {ytlink}

{description}

From 2a6ddecdc1f2c5b0d1ae841589eb825893e86278 Mon Sep 17 00:00:00 2001 From: rebane2001 Date: Thu, 11 May 2023 17:48:26 +0300 Subject: [PATCH 3/3] comments --- custom/Example.html | 2 +- hobune/comments.py | 19 ++++++++++++------- hobune/videos.py | 2 +- templates/hobune.css | 2 +- templates/video.html | 2 +- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/custom/Example.html b/custom/Example.html index e37fd10..61af89c 100644 --- a/custom/Example.html +++ b/custom/Example.html @@ -1,3 +1,3 @@ -
+

This is an example of a custom page

\ No newline at end of file diff --git a/hobune/comments.py b/hobune/comments.py index 2eeaf0f..d34a869 100644 --- a/hobune/comments.py +++ b/hobune/comments.py @@ -33,28 +33,33 @@ def getCommentsHTML(title, videoid): with open(f"{comments_path}/{videoid}.jsonl", "r") as f: header = json.loads(f.readline()) # Hacky workaround if you don't use my format of comments (w/header) - if not "time_fetched" in header: + if "time_fetched" not in header: comments.append(header) header = {"time_fetched": "N/A"} for l in f: comments.append(json.loads(l)) except Exception: return False, 0 - comments_html = f"""
-

{title}

- Back to video page | Download comments jsonl -

Comments (archived {header["time_fetched"][:16].replace("T", " ")})

-
\n""" + comments_html = "" comments_count = 0 + total_count = 0 for comment in comments: comments_count += 1 + total_count += 1 csnip = comment["snippet"]["topLevelComment"]["snippet"] comment_html = getCommentHTML(csnip) if "replies" in comment: replies = "" for reply in comment["replies"]["comments"][::-1]: + total_count += 1 replies += f'
{getCommentHTML(reply["snippet"])}
\n' comment_html += f"
Replies ({len(comment['replies']['comments'])})\n{replies}
" comments_html += f'
{comment_html}
\n' - comments_html += "
" + comments_html = f"""
+

{title}

+ Back to video page | Download comments jsonl +

Comments (archived {header["time_fetched"][:16].replace("T", " ")}; {comments_count} top, {total_count} total comments)

+
\n + {comments_html} +
""" return comments_html, comments_count \ No newline at end of file diff --git a/hobune/videos.py b/hobune/videos.py index 62de744..8f4daa5 100644 --- a/hobune/videos.py +++ b/hobune/videos.py @@ -46,7 +46,7 @@ def create_video_pages(config, channels, templates, html_ext): with open(os.path.join(config.output_path, f"comments/{no_traverse(v['id'])}.html"), "w") as f: f.write(templates["base"].format(title=html.escape(v['title'] + ' - Comments'), meta=page_meta, content=comments_html)) - comments_link = f'

View comments ({comments_count})

' + comments_link = f'

View comments ({comments_count})

' # Set mp4 path mp4path = f"{os.path.join(config.files_web_path + root[len(config.files_path):], base)}.mp4" for ext in ["mp4", "webm", "mkv"]: diff --git a/templates/hobune.css b/templates/hobune.css index 833ce1c..5de5335 100644 --- a/templates/hobune.css +++ b/templates/hobune.css @@ -394,7 +394,7 @@ a { } .comment p { - margin-bottom: 0; + margin: 0; } .comment .reply { diff --git a/templates/video.html b/templates/video.html index 6b19982..e9ce1ce 100644 --- a/templates/video.html +++ b/templates/video.html @@ -1,4 +1,4 @@ -
+