about summary refs log tree commit diff stats
path: root/crates/yt_dlp/src/wrapper/yt_dlp_options.rs
blob: c2a86df3028d5a1da022b145a75011ee34767afe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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 pyo3::{types::PyDict, Bound, PyResult, Python};
use serde::Serialize;

use crate::json_loads;

#[derive(Serialize, Clone)]
pub struct YtDlpOptions {
    pub playliststart: u32,
    pub playlistend: u32,
    pub noplaylist: bool,
    pub extract_flat: ExtractFlat,
    // pub extractor_args: ExtractorArgs,
    // pub format: String,
    // pub fragment_retries: u32,
    // #[serde(rename(serialize = "getcomments"))]
    // pub get_comments: bool,
    // #[serde(rename(serialize = "ignoreerrors"))]
    // pub ignore_errors: bool,
    // pub retries: u32,
    // #[serde(rename(serialize = "writeinfojson"))]
    // pub write_info_json: bool,
    // pub postprocessors: Vec<serde_json::Map<String, serde_json::Value>>,
}

#[derive(Serialize, Copy, Clone)]
pub enum ExtractFlat {
    #[serde(rename(serialize = "in_playlist"))]
    InPlaylist,

    #[serde(rename(serialize = "discard_in_playlist"))]
    DiscardInPlaylist,
}

#[derive(Serialize, Clone)]
pub struct ExtractorArgs {
    pub youtube: YoutubeExtractorArgs,
}

#[derive(Serialize, Clone)]
pub struct YoutubeExtractorArgs {
    comment_sort: Vec<String>,
    max_comments: Vec<String>,
}

impl YtDlpOptions {
    pub fn to_py_dict(self, py: Python) -> PyResult<Bound<PyDict>> {
        let string = serde_json::to_string(&self).expect("This should always work");

        let output: Bound<PyDict> = json_loads(py, string)?;
        Ok(output)
    }
}