mirror of
https://github.com/euzu/tuliprox.git
synced 2026-10-15 20:32:27 +02:00
Some refactorings
- HdHomerun - WebUI GeoIP - Playlist Updates ...
This commit is contained in:
@@ -22,7 +22,7 @@ pub async fn process_group_watch(client: &Arc<reqwest::Client>, cfg: &Config, ta
|
||||
let save_path = path.as_path();
|
||||
let mut changed = false;
|
||||
if path.exists() {
|
||||
if let Some(loaded_tree) = load_watch_tree(&path) {
|
||||
if let Some(loaded_tree) = load_watch_tree(&path).await {
|
||||
// Find elements in set2 but not in set1
|
||||
let added_difference: BTreeSet<String> = new_tree.difference(&loaded_tree).cloned().collect();
|
||||
let removed_difference: BTreeSet<String> = loaded_tree.difference(&new_tree).cloned().collect();
|
||||
@@ -38,7 +38,7 @@ pub async fn process_group_watch(client: &Arc<reqwest::Client>, cfg: &Config, ta
|
||||
changed = true;
|
||||
}
|
||||
if changed {
|
||||
match save_watch_tree(save_path, &new_tree) {
|
||||
match save_watch_tree(save_path, &new_tree).await {
|
||||
Ok(()) => {}
|
||||
Err(err) => {
|
||||
error!("failed to write watch_file {}: {}", save_path.to_str().unwrap_or_default(), err);
|
||||
@@ -64,6 +64,7 @@ async fn handle_watch_notification(client: &Arc<reqwest::Client>, cfg: &Config,
|
||||
let added = added.iter().map(std::string::ToString::to_string).collect::<Vec<String>>();
|
||||
let removed = removed.iter().map(std::string::ToString::to_string).collect::<Vec<String>>();
|
||||
if !added.is_empty() || !removed.is_empty() {
|
||||
|
||||
let changes = WatchChanges {
|
||||
target: target_name.to_string(),
|
||||
group: group_name.to_string(),
|
||||
@@ -77,15 +78,13 @@ async fn handle_watch_notification(client: &Arc<reqwest::Client>, cfg: &Config,
|
||||
}
|
||||
}
|
||||
|
||||
fn load_watch_tree(path: &Path) -> Option<BTreeSet<String>> {
|
||||
std::fs::read(path).map_or(None, |encoded| {
|
||||
let decoded = bincode_deserialize(&encoded[..]).ok()?;
|
||||
Some(decoded)
|
||||
})
|
||||
async fn load_watch_tree(path: &Path) -> Option<BTreeSet<String>> {
|
||||
let encoded = tokio::fs::read(path).await.ok()?;
|
||||
bincode_deserialize(&encoded[..]).ok()
|
||||
}
|
||||
|
||||
fn save_watch_tree(path: &Path, tree: &BTreeSet<String>) -> std::io::Result<()> {
|
||||
async fn save_watch_tree(path: &Path, tree: &BTreeSet<String>) -> std::io::Result<()> {
|
||||
let encoded: Vec<u8> = bincode_serialize(&tree)?;
|
||||
std::fs::write(path, encoded)
|
||||
tokio::fs::write(path, encoded).await
|
||||
}
|
||||
|
||||
|
||||
@@ -620,17 +620,22 @@ async fn process_epg(processed_fetched_playlists: &mut Vec<FetchedPlaylist<'_>>)
|
||||
(new_epg, new_playlist)
|
||||
}
|
||||
|
||||
async fn process_watch(cfg: &Config, client: &Arc<reqwest::Client>, target: &ConfigTarget, new_playlist: &Vec<PlaylistGroup>) -> bool {
|
||||
async fn process_watch(cfg: &Config, client: &Arc<reqwest::Client>, target: &ConfigTarget, new_playlist: &[PlaylistGroup]) -> bool {
|
||||
if let Some(watches) = &target.watch {
|
||||
if default_as_default().eq_ignore_ascii_case(&target.name) {
|
||||
error!("cant watch a target with no unique name");
|
||||
} else {
|
||||
for pl in new_playlist {
|
||||
if watches.iter().any(|r| r.is_match(&pl.title)) {
|
||||
process_group_watch(client, cfg, &target.name, pl).await;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
let mut futs = Vec::new();
|
||||
for pl in new_playlist {
|
||||
if watches.iter().any(|r| r.is_match(&pl.title)) {
|
||||
futs.push(process_group_watch(client, cfg, &target.name, pl));
|
||||
}
|
||||
}
|
||||
if !futs.is_empty() {
|
||||
futures::future::join_all(futs).await;
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
||||
Reference in New Issue
Block a user