|
1 | 1 | use dirs::home_dir;
|
2 |
| -use std::fs; |
| 2 | +use std::{fs, io::Read}; |
3 | 3 |
|
4 | 4 | use serde::{Deserialize, Serialize};
|
5 |
| -use serde_yaml::{self}; |
6 | 5 |
|
7 | 6 | #[derive(Debug, Serialize, Deserialize, Clone)]
|
8 | 7 | pub struct Config {
|
9 |
| - pub blur: bool, |
10 |
| - pub blur_amount: f32, |
11 |
| - pub blur_output_fps: f32, |
12 |
| - pub blur_weighting: String, |
| 8 | + pub blending: Blending, |
| 9 | + pub interpolation: Interpolation, |
| 10 | + pub encoding: Encoding, |
| 11 | + pub timescale: Timescale, |
13 | 12 |
|
14 |
| - pub interpolate: bool, |
15 |
| - pub interpolated_fps: f32, |
| 13 | + pub filters: Filters, |
16 | 14 |
|
17 |
| - pub quality: u32, |
18 |
| - pub detailed_filenames: bool, |
| 15 | + pub advanced: Advanced, |
| 16 | +} |
| 17 | + |
| 18 | +#[derive(Debug, Serialize, Deserialize, Clone)] |
| 19 | +pub struct Blending { |
| 20 | + pub enabled: bool, |
| 21 | + pub amount: f32, |
| 22 | + pub weighting: String, |
| 23 | + pub output_fps: i32, |
| 24 | +} |
19 | 25 |
|
20 |
| - pub input_timescale: f32, |
21 |
| - pub output_timescale: f32, |
22 |
| - pub adjust_timescaled_audio_pitch: bool, |
| 26 | +#[derive(Debug, Serialize, Deserialize, Clone)] |
| 27 | +pub struct Interpolation { |
| 28 | + pub enabled: bool, |
| 29 | + pub fps: f32, |
| 30 | +} |
| 31 | + |
| 32 | +#[derive(Debug, Serialize, Deserialize, Clone)] |
| 33 | +pub struct Encoding { |
| 34 | + pub quality: i32, |
| 35 | + pub detailed_filename: bool, |
| 36 | + pub container: String |
| 37 | +} |
| 38 | + |
| 39 | +#[derive(Debug, Serialize, Deserialize, Clone)] |
| 40 | +pub struct Timescale { |
| 41 | + pub input: f32, |
| 42 | + pub output: f32, |
| 43 | + pub adjust_audio_pitch: bool, |
| 44 | +} |
23 | 45 |
|
| 46 | +#[derive(Debug, Serialize, Deserialize, Clone)] |
| 47 | +pub struct Filters { |
24 | 48 | pub brightness: f32,
|
25 | 49 | pub contrast: f32,
|
26 | 50 | pub saturation: f32,
|
| 51 | +} |
| 52 | + |
| 53 | +#[derive(Debug, Serialize, Deserialize, Clone)] |
| 54 | +pub struct Advanced { |
| 55 | + pub encoding: AdvancedEncoding, |
| 56 | + pub blend_weighting: AdvancedBlending, |
| 57 | + pub interpolation: AdvancedInterpolation, |
| 58 | +} |
27 | 59 |
|
| 60 | +#[derive(Debug, Serialize, Deserialize, Clone)] |
| 61 | +pub struct AdvancedEncoding { |
28 | 62 | pub gpu: bool,
|
29 | 63 | pub gpu_type: String,
|
30 | 64 | pub deduplicate: bool,
|
31 |
| - pub custom_ffmpeg_filters: String, |
| 65 | + pub custom_ffmpeg_filters: Option<String>, |
| 66 | +} |
32 | 67 |
|
33 |
| - pub blur_weighting_gaussian_std_dev: f32, |
34 |
| - pub blur_weighting_triangle_reverse: bool, |
35 |
| - pub blur_weighting_bound: Vec<f32>, |
| 68 | +#[derive(Debug, Serialize, Deserialize, Clone)] |
| 69 | +pub struct AdvancedBlending { |
| 70 | + pub gaussian_std_dev: i32, |
| 71 | + pub triangle_reverse: bool, |
| 72 | + pub bound: Vec<i32>, |
| 73 | +} |
36 | 74 |
|
37 |
| - pub interpolation_program: String, |
38 |
| - pub interpolation_speed: String, |
39 |
| - pub interpolation_tuning: String, |
40 |
| - pub interpolation_algorithm: String, |
| 75 | +#[derive(Debug, Serialize, Deserialize, Clone)] |
| 76 | +pub struct AdvancedInterpolation { |
| 77 | + pub program: String, |
| 78 | + pub speed: String, |
| 79 | + pub tuning: String, |
| 80 | + pub algorithm: String, |
41 | 81 | }
|
42 | 82 |
|
43 | 83 | impl Config {
|
44 | 84 | pub fn parse() -> Config {
|
45 | 85 | let filepath = home_dir().unwrap();
|
46 |
| - let config_file = filepath.join(".config/teres/config.yml"); |
| 86 | + let config_file = filepath.join(".config/teres/teres.toml"); |
47 | 87 | if !config_file.exists() {
|
48 | 88 | Config::create(&config_file);
|
49 | 89 | }
|
50 | 90 |
|
51 |
| - let f = std::fs::File::open(config_file).expect("Could not open file."); |
52 |
| - let scrape_config: Config = serde_yaml::from_reader(f).expect("Could not read values."); |
| 91 | + let mut f = std::fs::File::open(config_file).expect("Could not open file."); |
| 92 | + let mut contents = String::new(); |
| 93 | + f.read_to_string(&mut contents) |
| 94 | + .expect("Could not parse config file to string"); |
| 95 | + let scrape_config: Config = toml::from_str(&contents).expect("Could not read values."); |
53 | 96 | scrape_config
|
54 | 97 | }
|
55 | 98 |
|
56 | 99 | pub fn create(filepath: &std::path::Path) {
|
57 | 100 | let prefix = filepath.parent().unwrap();
|
58 | 101 | std::fs::create_dir_all(prefix).unwrap();
|
59 |
| - fs::write( |
60 |
| - filepath, |
61 |
| - "# blur |
62 |
| -blur: true |
63 |
| -blur_amount: 1 |
64 |
| -blur_output_fps: 60 |
65 |
| -blur_weighting: equal |
66 |
| -
|
67 |
| -# interpolation |
68 |
| -interpolate: true |
69 |
| -interpolated_fps: 480 |
70 |
| -
|
71 |
| -# rendering |
72 |
| -quality: 18 |
73 |
| -detailed_filenames: false |
74 |
| -
|
75 |
| -# timescale |
76 |
| -input_timescale: 1 |
77 |
| -output_timescale: 1 |
78 |
| -adjust_timescaled_audio_pitch: false |
79 |
| -
|
80 |
| -# filters |
81 |
| -brightness: 1 |
82 |
| -saturation: 1 |
83 |
| -contrast: 1 |
84 |
| -
|
85 |
| -# advanced rendering |
86 |
| -gpu: false |
87 |
| -gpu_type: nvidia #nvidia/amd/intel |
88 |
| -deduplicate: false |
89 |
| -custom_ffmpeg_filters: |
90 |
| -
|
91 |
| -# advanced blur |
92 |
| -blur_weighting_gaussian_std_dev: 2 |
93 |
| -blur_weighting_triangle_reverse: false |
94 |
| -blur_weighting_bound: [0, 2] |
95 |
| -
|
96 |
| -# advanced interpolation |
97 |
| -interpolation_program: svp #svp/rife/rife-ncnn |
98 |
| -interpolation_speed: default |
99 |
| -interpolation_tuning: default |
100 |
| -interpolation_algorithm: default", |
101 |
| - ) |
102 |
| - .expect("Failed to create config file") |
| 102 | + fs::write(filepath, String::from("# Teres Configuration |
| 103 | +# For documentation for what each value means and the accecpted values see |
| 104 | +# https://animafps.github.io/teres/docs/configuration |
| 105 | +
|
| 106 | +[blending] |
| 107 | +enabled = true |
| 108 | +amount = 1.0 |
| 109 | +weighting = \"equal\" # equal/gaussian/gaussian_sym/pyramid/pyramid_sym |
| 110 | +output_fps = 60 |
| 111 | +
|
| 112 | +[interpolation] |
| 113 | +enabled = true |
| 114 | +fps = 480.0 |
| 115 | +
|
| 116 | +[encoding] |
| 117 | +quality = 18 |
| 118 | +detailed_filename = false |
| 119 | +container = mp4 |
| 120 | +
|
| 121 | +[timescale] |
| 122 | +input = 1.0 |
| 123 | +output = 1.0 |
| 124 | +adjust_audio_pitch = false |
| 125 | +
|
| 126 | +[filters] |
| 127 | +brightness = 1.0 |
| 128 | +contrast = 1.0 |
| 129 | +saturation = 1.0 |
| 130 | +
|
| 131 | +[advanced.encoding] |
| 132 | +gpu = false |
| 133 | +gpu_type = \"nvidia\" # nvidia/intel/amd |
| 134 | +deduplicate = false |
| 135 | +
|
| 136 | +[advanced.blend_weighting] |
| 137 | +gaussian_std_dev = 2 |
| 138 | +triangle_reverse = false |
| 139 | +bound = [0, 2] |
| 140 | +
|
| 141 | +[advanced.interpolation] |
| 142 | +program = \"svp\" # svp/rife/rife-ncnn |
| 143 | +speed = \"default\" # medium/fast/faster/default (default is medium) |
| 144 | +tuning = \"default\" # film/animation/weak/smooth/default (default is smooth) |
| 145 | +algorithm = \"default\" # 2/13/23/default (default is 13)")) |
| 146 | + .expect("Failed to create config file") |
103 | 147 | }
|
104 | 148 | }
|
0 commit comments