Skip to content

Commit 8aed436

Browse files
authored
Merge pull request #352 from euzu/feature/xtream_series_info_fix_and_unsecure_ssl_certs
Fixed SeriesInfo episode data-type problem, Added accept_unsecure_sll_certifcates to config.yml
2 parents 09ec339 + 7c99c66 commit 8aed436

File tree

9 files changed

+58
-26
lines changed

9 files changed

+58
-26
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Top level entries in the config files are:
9090
* `ipcheck` _optional_
9191
* `config_hot_reload` _optional_, default false.
9292
* `sleep_timer_mins` _optional_, used for closing stream after the given minutes.
93+
* `accept_unsecure_ssl_certificates` _optional_, default false.
9394

9495
### 1.1. `threads`
9596
If you are running on a cpu which has multiple cores, you can set for example `threads: 2` to run two threads.

backend/src/api/model/active_provider_manager.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,9 @@ mod tests {
934934
}
935935
}
936936

937+
fn dummy_callback(_: &str, _: usize) {}
938+
939+
937940
// Test acquiring with an alias
938941
#[test]
939942
fn test_provider_with_alias() {
@@ -943,10 +946,10 @@ mod tests {
943946
// Adding alias to the provider
944947
input.aliases = Some(vec![alias]);
945948

946-
let (change_tx, _) = tokio::sync::mpsc::channel::<(String, usize)>(1);
949+
let change_callback: ProviderConnectionChangeCallback = Arc::new(dummy_callback);
947950
let dummy_get_connection = |_s: &str| -> Option<&ProviderConfigConnection> { None };
948951
// Create MultiProviderLineup with the provider and alias
949-
let lineup = MultiProviderLineup::new(&input, Some(dummy_get_connection), &change_tx);
952+
let lineup = MultiProviderLineup::new(&input, Some(dummy_get_connection), &change_callback);
950953
let rt = tokio::runtime::Runtime::new().unwrap();
951954
rt.block_on(async move {
952955
// Test that the alias provider is available
@@ -968,9 +971,9 @@ mod tests {
968971
let alias = create_config_input_alias(2, "http://alias.com", 0, 2);
969972
// Adding alias with different priority
970973
input.aliases = Some(vec![alias]);
971-
let (change_tx, _) = tokio::sync::mpsc::channel::<(String, usize)>(1);
974+
let change_callback: ProviderConnectionChangeCallback = Arc::new(dummy_callback);
972975
let dummy_get_connection = |_s: &str| -> Option<&ProviderConfigConnection> { None };
973-
let lineup = MultiProviderLineup::new(&input, Some(dummy_get_connection), &change_tx);
976+
let lineup = MultiProviderLineup::new(&input, Some(dummy_get_connection), &change_callback);
974977
// The alias has a higher priority, so the alias should be acquired first
975978
let rt = tokio::runtime::Runtime::new().unwrap();
976979
rt.block_on(async move {
@@ -990,9 +993,9 @@ mod tests {
990993

991994
// Adding multiple aliases
992995
input.aliases = Some(vec![alias1, alias2]);
993-
let (change_tx, _) = tokio::sync::mpsc::channel::<(String, usize)>(1);
996+
let change_callback: ProviderConnectionChangeCallback = Arc::new(dummy_callback);
994997
let dummy_get_connection = |_s: &str| -> Option<&ProviderConfigConnection> { None };
995-
let lineup = MultiProviderLineup::new(&input, Some(dummy_get_connection), &change_tx);
998+
let lineup = MultiProviderLineup::new(&input, Some(dummy_get_connection), &change_callback);
996999
let rt = tokio::runtime::Runtime::new().unwrap();
9971000
rt.block_on(async move {
9981001
// The alias with priority 0 should be acquired first (higher priority)
@@ -1021,9 +1024,9 @@ mod tests {
10211024

10221025
// Adding alias
10231026
input.aliases = Some(vec![alias1, alias2]);
1024-
let (change_tx, _) = tokio::sync::mpsc::channel::<(String, usize)>(1);
1027+
let change_callback: ProviderConnectionChangeCallback = Arc::new(dummy_callback);
10251028
let dummy_get_connection = |_s: &str| -> Option<&ProviderConfigConnection> { None };
1026-
let lineup = MultiProviderLineup::new(&input, Some(dummy_get_connection), &change_tx);
1029+
let lineup = MultiProviderLineup::new(&input, Some(dummy_get_connection), &change_callback);
10271030
let rt = tokio::runtime::Runtime::new().unwrap();
10281031
rt.block_on(async move {
10291032
// Acquire connection from alias2
@@ -1049,10 +1052,9 @@ mod tests {
10491052
#[test]
10501053
fn test_acquire_when_capacity_available() {
10511054
let cfg = create_config_input(1, "provider5_1", 1, 2);
1052-
let on_connection_change = move |_name, _connections| {};
1053-
let change_tx = Arc::new(on_connection_change);
1055+
let change_callback: ProviderConnectionChangeCallback = Arc::new(dummy_callback);
10541056
let dummy_get_connection = |_s: &str| -> Option<&ProviderConfigConnection> { None };
1055-
let lineup = SingleProviderLineup::new(&cfg, Some(dummy_get_connection), &change_tx);
1057+
let lineup = SingleProviderLineup::new(&cfg, Some(dummy_get_connection), &change_callback);
10561058
let rt = tokio::runtime::Runtime::new().unwrap();
10571059
rt.block_on(async move {
10581060
// First acquire attempt should succeed
@@ -1071,11 +1073,10 @@ mod tests {
10711073
#[test]
10721074
fn test_release_connection() {
10731075
let cfg = create_config_input(1, "provider7_1", 1, 2);
1074-
let on_connection_change = move |_name, _connections| {};
1075-
let change_tx = Arc::new(on_connection_change);
1076+
let change_callback: ProviderConnectionChangeCallback = Arc::new(dummy_callback);
10761077
let dummy_get_connection = |_s: &str| -> Option<&ProviderConfigConnection> { None };
10771078

1078-
let lineup = SingleProviderLineup::new(&cfg, Some(dummy_get_connection), &change_tx);
1079+
let lineup = SingleProviderLineup::new(&cfg, Some(dummy_get_connection), &change_callback);
10791080
let rt = tokio::runtime::Runtime::new().unwrap();
10801081
rt.block_on(async move {
10811082
// Acquire two connections
@@ -1103,9 +1104,9 @@ mod tests {
11031104
cfg1.aliases = Some(vec![alias]);
11041105

11051106
// Create MultiProviderLineup with the provider and alias
1106-
let (change_tx, _) = tokio::sync::mpsc::channel::<(String, usize)>(1);
1107+
let change_callback: ProviderConnectionChangeCallback = Arc::new(dummy_callback);
11071108
let dummy_get_connection = |_s: &str| -> Option<&ProviderConfigConnection> { None };
1108-
let lineup = MultiProviderLineup::new(&cfg1, Some(dummy_get_connection), &change_tx);
1109+
let lineup = MultiProviderLineup::new(&cfg1, Some(dummy_get_connection), &change_callback);
11091110
let rt = tokio::runtime::Runtime::new().unwrap();
11101111
rt.block_on(async move {
11111112
// Test acquiring the first provider
@@ -1136,10 +1137,9 @@ mod tests {
11361137
#[test]
11371138
fn test_concurrent_acquire() {
11381139
let cfg = create_config_input(1, "provider9_1", 1, 2);
1139-
let on_connection_change = move |_name, _connections| {};
1140-
let change_tx = Arc::new(on_connection_change);
1140+
let change_callback: ProviderConnectionChangeCallback = Arc::new(dummy_callback);
11411141
let dummy_get_connection = |_s: &str| -> Option<&ProviderConfigConnection> { None };
1142-
let lineup = Arc::new(SingleProviderLineup::new(&cfg, Some(dummy_get_connection), &change_tx));
1142+
let lineup = Arc::new(SingleProviderLineup::new(&cfg, Some(dummy_get_connection), &change_callback));
11431143

11441144
let available_count = Arc::new(AtomicU16::new(2));
11451145
let grace_period_count = Arc::new(AtomicU16::new(1));

backend/src/model/config/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fn create_directories(cfg: &Config, temp_path: &Path) {
4040
}
4141
}
4242

43+
#[allow(clippy::struct_excessive_bools)]
4344
#[derive(Debug, Clone, Default)]
4445
pub struct Config {
4546
pub threads: u8,
@@ -57,6 +58,7 @@ pub struct Config {
5758
pub sleep_timer_mins: Option<u32>,
5859
pub update_on_boot: bool,
5960
pub config_hot_reload: bool,
61+
pub accept_unsecure_ssl_certificates: bool,
6062
pub web_ui: Option<WebUiConfig>,
6163
pub messaging: Option<MessagingConfig>,
6264
pub reverse_proxy: Option<ReverseProxyConfig>,
@@ -137,6 +139,7 @@ impl From<&ConfigDto> for Config {
137139
sleep_timer_mins: dto.sleep_timer_mins,
138140
update_on_boot: dto.update_on_boot,
139141
config_hot_reload: dto.config_hot_reload,
142+
accept_unsecure_ssl_certificates: dto.accept_unsecure_ssl_certificates,
140143
web_ui: dto.web_ui.as_ref().map(Into::into),
141144
messaging: dto.messaging.as_ref().map(Into::into),
142145
reverse_proxy: dto.reverse_proxy.as_ref().map(Into::into),

backend/src/model/xtream.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ pub struct XtreamSeriesInfoEpisodeInfo {
277277
// Used for serde_json deserialization, can not be used with bincode
278278
#[derive(Debug, Clone, Serialize, Deserialize)]
279279
pub struct XtreamSeriesInfoEpisode {
280-
#[serde(default, deserialize_with = "string_default_on_null")]
281-
pub id: String,
280+
#[serde(default, deserialize_with = "string_or_number_u32")]
281+
pub id: u32,
282282
#[serde(default, deserialize_with = "string_or_number_u32")]
283283
pub episode_num: u32,
284284
#[serde(default, deserialize_with = "string_default_on_null")]
@@ -299,7 +299,7 @@ pub struct XtreamSeriesInfoEpisode {
299299

300300
impl XtreamSeriesInfoEpisode {
301301
pub fn get_id(&self) -> u32 {
302-
self.id.parse::<u32>().unwrap_or(0)
302+
self.id
303303
}
304304
}
305305

backend/src/processing/parser/xtream.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ pub fn parse_xtream_series_info(info: &Value, group_title: &str, series_name: &s
4949
(episode.clone(),
5050
PlaylistItem {
5151
header: PlaylistItemHeader {
52-
id: episode.id.clone(),
53-
uuid: generate_playlist_uuid(&input.name, &episode.id, PlaylistItemType::Series, &episode_url),
52+
id: episode.id.to_string(),
53+
uuid: generate_playlist_uuid(&input.name, &episode.id.to_string(), PlaylistItemType::Series, &episode_url),
5454
name: series_name.to_string(),
5555
logo: episode.info.as_ref().map_or_else(String::new, |info| info.movie_image.clone()),
5656
group: group_title.to_string(),
@@ -189,3 +189,17 @@ pub fn parse_xtream(input: &ConfigInput,
189189
Err(err) => Err(err)
190190
}
191191
}
192+
193+
#[cfg(test)]
194+
mod tests {
195+
use std::fs;
196+
use crate::model::XtreamSeriesInfo;
197+
198+
#[test]
199+
fn test_read_json_file_into_struct() {
200+
let file_content = fs::read_to_string("series-info.json").expect("Unable to read file");
201+
let _info: XtreamSeriesInfo = serde_json::from_str(&file_content).expect("JSON was not well-formatted");
202+
203+
}
204+
205+
}

backend/src/utils/network/request.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,13 @@ pub async fn get_input_json_content(client: Arc<reqwest::Client>, input: &InputS
395395

396396

397397
pub fn create_client(cfg: &AppConfig) -> reqwest::ClientBuilder {
398+
let config = cfg.config.load();
398399
let mut client = reqwest::Client::builder()
399400
.redirect(reqwest::redirect::Policy::limited(10))
400401
.pool_idle_timeout(Duration::from_secs(30))
401-
.pool_max_idle_per_host(10);
402+
.pool_max_idle_per_host(10)
403+
.danger_accept_invalid_certs(config.accept_unsecure_ssl_certificates);
402404

403-
let config = cfg.config.load();
404405

405406
if let Some(proxy_cfg) = config.proxy.as_ref() {
406407
match Url::parse(&proxy_cfg.url) {

frontend/public/assets/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206
"SLEEP_TIMER_MINS": "Sleep Timer (mins)",
207207
"CONNECT_TIMEOUT_SECS": "Connect Timeout (secs)",
208208
"CONFIG_HOT_RELOAD": "Config Hot Reload",
209+
"ACCEPT_UNSECURE_SSL_CERTIFICATES": "Accept Unsecure SSL Certificates",
209210
"CUSTOM_STREAM_RESPONSE_PATH": "Custom Stream Response dir",
210211
"REVERSE_PROXY": "Reverse Proxy",
211212
"WEB_SEARCH": "Web Search",

frontend/src/app/components/config/main_config_view.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const LABEL_USER_CONFIG_DIR: &str = "LABEL.USER_CONFIG_DIR";
1818
const LABEL_SLEEP_TIMER_MINS: &str = "LABEL.SLEEP_TIMER_MINS";
1919
const LABEL_CONNECT_TIMEOUT_SECS: &str = "LABEL.CONNECT_TIMEOUT_SECS";
2020
const LABEL_CUSTOM_STREAM_RESPONSE_PATH: &str = "LABEL.CUSTOM_STREAM_RESPONSE_PATH";
21+
const LABEL_ACCEPT_UNSECURE_SSL_CERTIFICATES: &str = "LABEL.ACCEPT_UNSECURE_SSL_CERTIFICATES";
2122

2223
generate_form_reducer!(
2324
state: MainConfigFormState { form: MainConfigDto },
@@ -26,6 +27,7 @@ generate_form_reducer!(
2627
UpdateOnBoot => update_on_boot: bool,
2728
ConfigHotReload => config_hot_reload: bool,
2829
UserAccessControl => user_access_control: bool,
30+
AcceptUnsecureSslCertificates => accept_unsecure_ssl_certificates: bool,
2931
Threads => threads: u8,
3032
WorkingDir => working_dir: String,
3133
MappingPath => mapping_path: Option<String>,
@@ -75,6 +77,7 @@ pub fn MainConfigView() -> Html {
7577
{ config_field_bool!(form_state.form, translate.t(LABEL_UPDATE_ON_BOOT), update_on_boot) }
7678
{ config_field_bool!(form_state.form, translate.t(LABEL_CONFIG_HOT_RELOAD), config_hot_reload) }
7779
{ config_field_bool!(form_state.form, translate.t(LABEL_USER_ACCESS_CONTROL), user_access_control) }
80+
{ config_field_bool!(form_state.form, translate.t(LABEL_ACCEPT_UNSECURE_SSL_CERTIFICATES), accept_unsecure_ssl_certificates) }
7881
{ config_field!(form_state.form, translate.t(LABEL_THREADS), threads) }
7982
{ config_field!(form_state.form, translate.t(LABEL_WORKING_DIR), working_dir) }
8083
{ config_field_optional!(form_state.form, translate.t(LABEL_MAPPING_PATH), mapping_path) }
@@ -92,6 +95,7 @@ pub fn MainConfigView() -> Html {
9295
{ edit_field_bool!(form_state, translate.t(LABEL_UPDATE_ON_BOOT), update_on_boot, MainConfigFormAction::UpdateOnBoot) }
9396
{ edit_field_bool!(form_state, translate.t(LABEL_CONFIG_HOT_RELOAD), config_hot_reload, MainConfigFormAction::ConfigHotReload) }
9497
{ edit_field_bool!(form_state, translate.t(LABEL_USER_ACCESS_CONTROL), user_access_control, MainConfigFormAction::UserAccessControl) }
98+
{ edit_field_bool!(form_state, translate.t(LABEL_ACCEPT_UNSECURE_SSL_CERTIFICATES), user_access_control, MainConfigFormAction::AcceptUnsecureSslCertificates) }
9599
{ edit_field_number_u8!(form_state, translate.t(LABEL_THREADS), threads, MainConfigFormAction::Threads) }
96100
{ edit_field_text!(form_state, translate.t(LABEL_WORKING_DIR), working_dir, MainConfigFormAction::WorkingDir) }
97101
{ edit_field_text_option!(form_state, translate.t(LABEL_MAPPING_PATH), mapping_path, MainConfigFormAction::MappingPath) }

shared/src/model/config/base.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub struct ConfigDto {
3737
#[serde(default)]
3838
pub config_hot_reload: bool,
3939
#[serde(default)]
40+
pub accept_unsecure_ssl_certificates: bool,
41+
#[serde(default)]
4042
pub web_ui: Option<WebUiConfigDto>,
4143
#[serde(default, skip_serializing_if = "Option::is_none")]
4244
pub messaging: Option<MessagingConfigDto>,
@@ -75,6 +77,8 @@ pub struct MainConfigDto {
7577
pub update_on_boot: bool,
7678
#[serde(default)]
7779
pub config_hot_reload: bool,
80+
#[serde(default)]
81+
pub accept_unsecure_ssl_certificates: bool,
7882
}
7983

8084
impl Default for MainConfigDto {
@@ -91,6 +95,7 @@ impl Default for MainConfigDto {
9195
sleep_timer_mins: None,
9296
update_on_boot: false,
9397
config_hot_reload: false,
98+
accept_unsecure_ssl_certificates: false,
9499
}
95100
}
96101
}
@@ -109,6 +114,7 @@ impl From<&ConfigDto> for MainConfigDto {
109114
sleep_timer_mins: config.sleep_timer_mins,
110115
update_on_boot: config.update_on_boot,
111116
config_hot_reload: config.config_hot_reload,
117+
accept_unsecure_ssl_certificates: config.accept_unsecure_ssl_certificates,
112118
}
113119
}
114120
}
@@ -242,5 +248,7 @@ impl ConfigDto {
242248
self.sleep_timer_mins = main_config.sleep_timer_mins;
243249
self.update_on_boot = main_config.update_on_boot;
244250
self.config_hot_reload = main_config.config_hot_reload;
251+
self.accept_unsecure_ssl_certificates = main_config.accept_unsecure_ssl_certificates;
252+
245253
}
246254
}

0 commit comments

Comments
 (0)