Debian Codegraph @

podcasts-data/src/discovery/data.rs

raw symbols SCIP
1 // data.rs
2 //
3 // Copyright 2022-2024 nee <[email protected]>
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // SPDX-License-Identifier: GPL-3.0-or-later
19
20 use chrono::prelude::*;
21 use url::Url;
22
23 pub(crate) type UrlString = String;
24
25 #[derive(Clone, Debug)]
26 pub struct FoundPodcast {
27 pub feed: UrlString,
28 pub title: String,
29 pub author: String,
30 pub description: String,
31 pub art: UrlString,
32 pub episode_count: Option<i32>,
33 pub last_publication: Option<DateTime<Local>>,
34 }
35 /// checks for rougly the same feed url
36 impl PartialEq for FoundPodcast {
37 fn eq(&self, other: &Self) -> bool {
38 let a = Url::parse(&self.feed);
39 let b = Url::parse(&other.feed);
40
41 if let (Ok(a), Ok(b)) = (a, b) {
42 a.path().trim_end_matches('/') == b.path().trim_end_matches('/')
43 && a.host() == b.host()
44 && a.query() == b.query()
45 } else {
46 self.feed == other.feed
47 }
48 }
49 }
50
51 impl FoundPodcast {
52 /// use the longer description / bigger episode number
53 pub(crate) fn combine(&mut self, other: FoundPodcast) {
54 if other.episode_count.unwrap_or_default() > self.episode_count.unwrap_or_default() {
55 self.episode_count = other.episode_count;
56 }
57 if other.description.len() > self.description.len() {
58 self.description = other.description;
59 }
60 }
61 }
62
63 pub const ALL_PLATFORM_IDS: [&str; 2] = ["fyyd.de", "itunes.apple.com"];