about summary refs log tree commit diff stats
path: root/src/download/download_options.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-21 10:49:23 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-21 11:28:43 +0200
commit1debeb77f7986de1b659dcfdc442de6415e1d9f5 (patch)
tree4df3e7c3f6a2d1ec116e4088c5ace7f143a8b05f /src/download/download_options.rs
downloadyt-1debeb77f7986de1b659dcfdc442de6415e1d9f5.tar.gz
yt-1debeb77f7986de1b659dcfdc442de6415e1d9f5.zip
chore: Initial Commit
This repository was migrated out of my nixos-config.
Diffstat (limited to 'src/download/download_options.rs')
-rw-r--r--src/download/download_options.rs118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/download/download_options.rs b/src/download/download_options.rs
new file mode 100644
index 0000000..17cf66c
--- /dev/null
+++ b/src/download/download_options.rs
@@ -0,0 +1,118 @@
+// yt - A fully featured command line YouTube client
+//
+// Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// This file is part of Yt.
+//
+// You should have received a copy of the License along with this program.
+// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+
+use serde_json::{json, Value};
+
+use crate::{constants, storage::video_database::YtDlpOptions};
+
+// {
+//     "ratelimit": conf.ratelimit if conf.ratelimit > 0 else None,
+//     "retries": conf.retries,
+//     "merge_output_format": conf.merge_output_format,
+//     "restrictfilenames": conf.restrict_filenames,
+//     "ignoreerrors": False,
+//     "postprocessors": [{"key": "FFmpegMetadata"}],
+//     "logger": _ytdl_logger
+// }
+
+pub fn download_opts(additional_opts: YtDlpOptions) -> serde_json::Map<String, serde_json::Value> {
+    match json!({
+      "extract_flat": false,
+      "extractor_args": {
+        "youtube": {
+          "comment_sort": [
+            "top"
+          ],
+          "max_comments": [
+            "150",
+            "all",
+            "100"
+          ]
+        }
+      },
+      "ffmpeg_location": env!("FFMPEG_LOCATION"),
+      "format": "bestvideo[height<=?1080]+bestaudio/best",
+      "fragment_retries": 10,
+      "getcomments": true,
+      "ignoreerrors": false,
+      "retries": 10,
+
+      "writeinfojson": true,
+      "writeannotations": true,
+      "writesubtitles": true,
+      "writeautomaticsub": true,
+
+      "outtmpl": {
+        "default": constants::download_dir().join("%(channel)s/%(title)s.%(ext)s"),
+        "chapter": "%(title)s - %(section_number)03d %(section_title)s [%(id)s].%(ext)s"
+      },
+      "compat_opts": {},
+      "forceprint": {},
+      "print_to_file": {},
+      "windowsfilenames": false,
+      "restrictfilenames": false,
+      "trim_file_names": false,
+      "postprocessors": [
+        {
+          "api": "https://sponsor.ajay.app",
+          "categories": [
+            "interaction",
+            "intro",
+            "music_offtopic",
+            "sponsor",
+            "outro",
+            "poi_highlight",
+            "preview",
+            "selfpromo",
+            "filler",
+            "chapter"
+          ],
+          "key": "SponsorBlock",
+          "when": "after_filter"
+        },
+        {
+          "force_keyframes": false,
+          "key": "ModifyChapters",
+          "remove_chapters_patterns": [],
+          "remove_ranges": [],
+          "remove_sponsor_segments": [
+            "sponsor"
+          ],
+          "sponsorblock_chapter_title": "[SponsorBlock]: %(category_names)l"
+        },
+        {
+          "add_chapters": true,
+          "add_infojson": null,
+          "add_metadata": false,
+          "key": "FFmpegMetadata"
+        },
+        {
+          "key": "FFmpegConcat",
+          "only_multi_video": true,
+          "when": "playlist"
+        }
+      ]
+    }) {
+        serde_json::Value::Object(mut obj) => {
+            obj.insert(
+                "subtitleslangs".to_owned(),
+                serde_json::Value::Array(
+                    additional_opts
+                        .subtitle_langs
+                        .split(',')
+                        .map(|val| Value::String(val.to_owned()))
+                        .collect::<Vec<_>>(),
+                ),
+            );
+            obj
+        }
+        _ => unreachable!("This is an object"),
+    }
+}