| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
use crate::discovery::data::*; |
| 21 |
use anyhow::Result; |
| 22 |
use chrono::prelude::*; |
| 23 |
use serde::Deserialize; |
| 24 |
use url::Url; |
| 25 |
|
| 26 |
|
| 27 |
#[derive(Deserialize, Debug)] |
| 28 |
struct Response { |
| 29 |
data: Vec<Podcast>, |
| 30 |
} |
| 31 |
|
| 32 |
#[derive(Deserialize, Debug)] |
| 33 |
struct Podcast { |
| 34 |
title: String, |
| 35 |
author: String, |
| 36 |
description: String, |
| 37 |
lastpub: Option<DateTime<Local>>, |
| 38 |
#[serde(rename = "xmlURL")] |
| 39 |
xml_url: UrlString, |
| 40 |
#[serde(rename = "smallImageURL")] |
| 41 |
small_image_url: UrlString, |
| 42 |
episode_count: i32, |
| 43 |
} |
| 44 |
|
| 45 |
impl From<Podcast> for FoundPodcast { |
| 46 |
fn from(p: Podcast) -> FoundPodcast { |
| 47 |
FoundPodcast { |
| 48 |
feed: p.xml_url, |
| 49 |
title: p.title, |
| 50 |
author: p.author, |
| 51 |
description: p.description, |
| 52 |
art: p.small_image_url, |
| 53 |
episode_count: Some(p.episode_count), |
| 54 |
last_publication: p.lastpub, |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
pub async fn search(query: &str, enabled: bool) -> Result<Vec<FoundPodcast>> { |
| 60 |
if !enabled { |
| 61 |
return Ok(vec![]); |
| 62 |
} |
| 63 |
let url = Url::parse_with_params( |
| 64 |
"https://api.fyyd.de/0.2/search/podcast?count=10", |
| 65 |
&[("term", query)], |
| 66 |
)?; |
| 67 |
let client = crate::downloader::client_builder().build()?; |
| 68 |
let result: Response = client.get(url).send().await?.json().await?; |
| 69 |
Ok(result.data.into_iter().map(|p| p.into()).collect()) |
| 70 |
} |
| 71 |
|
| 72 |
#[cfg(test)] |
| 73 |
mod tests { |
| 74 |
use super::*; |
| 75 |
|
| 76 |
#[test] |
| 77 |
fn test_1_result() -> Result<()> { |
| 78 |
let input = std::fs::read_to_string("tests/fyyd/search_1.json")?; |
| 79 |
let result: Response = serde_json::from_str(&input)?; |
| 80 |
let found: Vec<FoundPodcast> = result.data.into_iter().map(|p| p.into()).collect(); |
| 81 |
let expected: Vec<FoundPodcast> = vec![ |
| 82 |
FoundPodcast { |
| 83 |
feed: "https://feeds.buzzsprout.com/1890340.rss".to_string(), |
| 84 |
title: "The Deprogram".to_string(), |
| 85 |
author: "JT, Hakim, and Yugopnik".to_string(), |
| 86 |
description: " What do an Iraqi, a Balkan Slav and a Texan have in common? A burning hatred for the system. Oh, and a podcast. Say no to eating out of the trash can of ideology. Join us on a journey exploring and critically assessing the perceived “normalcy” of late-stage capitalism. The only truly international, global, and anti-capitalist podcast you’ll find. SUPPORT US on PATREON: https://www.patreon.com/TheDeprogram FOLLOW US on Twitter @TheDeprogramPod ".to_string(), |
| 87 |
art: "https://img-1.fyyd.de/pd/small/7733270e232241983f50e3e88665b72cfa4f5.jpg".to_string(), |
| 88 |
episode_count: Some(242), |
| 89 |
last_publication: Some(chrono::DateTime::parse_from_rfc3339("2024-03-08T13:00:00+01:00").unwrap().with_timezone(&chrono::Local)) |
| 90 |
}]; |
| 91 |
assert_eq!(1, found.len()); |
| 92 |
assert_eq!(expected, found); |
| 93 |
Ok(()) |
| 94 |
} |
| 95 |
|
| 96 |
#[test] |
| 97 |
fn test_5_results() -> Result<()> { |
| 98 |
let input = std::fs::read_to_string("tests/fyyd/search_5.json")?; |
| 99 |
let result: Response = serde_json::from_str(&input)?; |
| 100 |
let found: Vec<FoundPodcast> = result.data.into_iter().map(|p| p.into()).collect(); |
| 101 |
let expected: Vec<FoundPodcast> = vec![ |
| 102 |
FoundPodcast { |
| 103 |
feed: "https://feeds.acast.com/public/shows/7540dfb3-3c5f-43ae-91d3-aad22b2ede46".to_string(), |
| 104 |
title: "Chapo".to_string(), |
| 105 |
author: "VICE".to_string(), |
| 106 |
description: "As Sinaloa cartel leader Joaquín “El Chapo” Guzmán goes on trial, VICE News explores his high-stakes case through the stories of people caught up in the drug war in the U.S. and Mexico. Hosted on Acast. See acast.com/privacy for more information.".to_string(), |
| 107 |
art: "https://img-1.fyyd.de/pd/small/8374473344d689aada87d46655bb0d1e89028.jpg".to_string(), |
| 108 |
episode_count: Some(17), |
| 109 |
last_publication: Some(chrono::DateTime::parse_from_rfc3339("2019-02-22T23:19:05+01:00").unwrap().with_timezone(&chrono::Local)) |
| 110 |
}, |
| 111 |
FoundPodcast { |
| 112 |
feed: "https://feeds.soundcloud.com/users/soundcloud:users:211911700/sounds.rss".to_string(), |
| 113 |
title: "Chapo Trap House".to_string(), |
| 114 |
author: "Chapo Trap House".to_string(), |
| 115 |
description: "Podcast by Chapo Trap House".to_string(), |
| 116 |
art: "https://img-1.fyyd.de/pd/small/58282c0c842fc16e73e519ff141e856b175f8.jpg".to_string(), |
| 117 |
episode_count: Some(792), |
| 118 |
last_publication: Some(chrono::DateTime::parse_from_rfc3339("2024-03-08T08:01:37+01:00").unwrap().with_timezone(&chrono::Local)) |
| 119 |
}, |
| 120 |
FoundPodcast { |
| 121 |
feed: "https://www.omnycontent.com/d/playlist/e73c998e-6e60-432f-8610-ae210140c5b1/a6b57093-81fe-4401-a963-af2000fe4e3a/56b7926c-6bfd-4d8c-81f9-af2000ffad49/podcast.rss".to_string(), |
| 122 |
title: "Surviving El Chapo: The Twins Who Brought Down A Drug Lord".to_string(), |
| 123 |
author: "iHeartPodcasts".to_string(), |
| 124 |
description: "Identical twins Jay and Pete Flores, who were once North America’s biggest drug traffickers and El Chapo’s right hand men, turned themselves into the U.S. government with the hopes of starting a new, safer life for their family. But after years of cooperating to get the world's most powerful drug kingpin behind bars, and finally gaining their freedom with a chance to start again, everything for the Flores family began to unravel. In Season 2 of Surviving El Chapo, hosts Curtis \"50 Cent\" Jackson and Charlie Webster hear Jay and Pete reveal for the first time what really happened during their turbulent 14-year prison journey and what it was like to come face-to-face in court with El Chapo. Plus, find out the shocking backstory to the prison sentence that the Flores wives are currently facing.\n\nHosted and executive produced by award-winning artist and producer Curtis \"50 Cent\" Jackson and critically acclaimed broadcast journalist and producer Charlie Webster. Brought to you by Lionsgate Sound as a world exclusive with iHeartPodcasts.".to_string(), |
| 125 |
art: "https://img-1.fyyd.de/pd/small/80419996d728f3c44a832def2cffbae93e380.jpg".to_string(), |
| 126 |
episode_count: Some(26), |
| 127 |
last_publication: Some(chrono::DateTime::parse_from_rfc3339("2023-12-06T09:00:00+01:00").unwrap().with_timezone(&chrono::Local)) |
| 128 |
}, |
| 129 |
FoundPodcast { |
| 130 |
feed: "https://feeds.buzzsprout.com/350771.rss".to_string(), |
| 131 |
title: "People's History of Ideas Podcast".to_string(), |
| 132 |
author: "Matthew Rothwell".to_string(), |
| 133 |
description: "In this podcast, Matthew Rothwell, author of Transpacific Revolutionaries: The Chinese Revolution in Latin America, explores the global history of ideas related to rebellion and revolution. The main focus of this podcast for the near future will be on the history of the Chinese Revolution, going all the way back to its roots in the initial Chinese reactions to British imperialism during the Opium War of 1839-1842, and then following the development of the revolution and many of the ideas that were products of the revolution through to their transnational diffusion in the late 20th century.".to_string(), |
| 134 |
art: "https://img-1.fyyd.de/pd/small/8442586e8539fdf80c9748cea30f43e638922.jpg".to_string(), |
| 135 |
episode_count: Some(112), |
| 136 |
last_publication: Some(chrono::DateTime::parse_from_rfc3339("2024-02-04T21:00:00+01:00").unwrap().with_timezone(&chrono::Local)) |
| 137 |
}, |
| 138 |
FoundPodcast { |
| 139 |
feed: "https://badfaith.libsyn.com/rss".to_string(), |
| 140 |
title: "Bad Faith".to_string(), |
| 141 |
author: "Briahna Joy Gray & Virgil Texas".to_string(), |
| 142 |
description: "America's only podcast. //\r\n\r\nwith Briahna Joy Gray, former National Press Secretary for Bernie Sanders' Presidential campaign //\r\n\r\nand Virgil Texas //\r\n\r\nSubscribe for exclusive premium episodes at patreon.com/badfaithpodcast /\r\n@badfaithpod / \r\nbadfaithpodcast at gmail dot com".to_string(), |
| 143 |
art: "https://img-1.fyyd.de/pd/small/6132904ae864f41dbbb60eaf1054cbfcc6292.jpg".to_string(), |
| 144 |
episode_count: Some(372), |
| 145 |
last_publication: Some(chrono::DateTime::parse_from_rfc3339("2024-03-07T11:44:00+01:00").unwrap().with_timezone(&chrono::Local)) |
| 146 |
}]; |
| 147 |
assert_eq!(5, found.len()); |
| 148 |
assert_eq!(expected, found); |
| 149 |
Ok(()) |
| 150 |
} |
| 151 |
|
| 152 |
#[test] |
| 153 |
fn empty_result() -> Result<()> { |
| 154 |
let input = std::fs::read_to_string("tests/fyyd/search_empty.json")?; |
| 155 |
let result: Response = serde_json::from_str(&input)?; |
| 156 |
let found: Vec<FoundPodcast> = result.data.into_iter().map(|p| p.into()).collect(); |
| 157 |
let expected: Vec<FoundPodcast> = vec![]; |
| 158 |
assert_eq!(expected, found); |
| 159 |
Ok(()) |
| 160 |
} |
| 161 |
|
| 162 |
#[test] |
| 163 |
fn unicode_result() -> Result<()> { |
| 164 |
let input = std::fs::read_to_string("tests/fyyd/search_unicode.json")?; |
| 165 |
let result: Response = serde_json::from_str(&input)?; |
| 166 |
let found: Vec<FoundPodcast> = result.data.into_iter().map(|p| p.into()).collect(); |
| 167 |
let expected: Vec<FoundPodcast> = vec![ |
| 168 |
FoundPodcast { feed: "https://feeds.fireside.fm/cornerspaeti/rss".to_string(), |
| 169 |
title: "Corner Späti".to_string(), |
| 170 |
author: "The Späti Boys".to_string(), |
| 171 |
description: "Weekly discussions of a deteriorating world all from the comfort of your local smoke-filled Spätkauf.\nhttps://www.patreon.com/cornerspaeti\nhttps://www.operationglad.io/start\n".to_string(), |
| 172 |
art: "https://img-1.fyyd.de/pd/small/77182e877ac679f9414148fab3dddb74782c2.jpg".to_string(), |
| 173 |
episode_count: Some(348), |
| 174 |
last_publication: Some(chrono::DateTime::parse_from_rfc3339("2024-03-07T10:00:00+01:00").unwrap().with_timezone(&chrono::Local)) |
| 175 |
}]; |
| 176 |
assert_eq!(expected, found); |
| 177 |
Ok(()) |
| 178 |
} |
| 179 |
} |