so://phie

verbal

A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal

blob: a415b60e07914e3371abeddf65835e5de81a7645 (1559 bytes)[doc][blame][raw]

1use serde::{Deserialize};

2use regex::Regex;

3

4use crate::common::Station;

5use crate::adapter::Adapter;

6

7#[derive(Debug, Deserialize, Clone)]

8pub struct StationAdapter {

9 pub stationuuid: String,

10 pub name: String,

11 pub url: String,

12 pub votes: i64,

13 pub favicon: String,

14 pub homepage: String,

15 pub tags: String,

16 pub clicktrend: i64,

17 pub clickcount: i64,

18 pub countrycode: String,

19 pub languagecodes: String,

20 pub state: String,

21}

22

23impl Adapter<Station> for StationAdapter {

24 fn populate(self, mut target: Station) -> Station {

25 target.id = self.stationuuid;

26 target.name = self.name;

27 target.stream_url = upgrade_to_https(self.url);

28 target.votes = self.votes;

29 target.favicon = self.favicon;

30 target.homepage = self.homepage;

31 target.tags = to_array(self.tags);

32 target.click_trend = self.clicktrend;

33 target.click_count = self.clickcount;

34 target.country = self.countrycode;

35 target.languages = to_array(self.languagecodes);

36 target.state = self.state;

37 target

38 }

39}

40

41fn to_array(value: String) -> Vec<String> {

42 value.split(",")

43 .map(str::to_string)

44 .filter(|tag| tag.trim().len() > 0)

45 .collect::<Vec<String>>()

46}

47

48fn upgrade_to_https(url: String) -> String {

49 if Regex::new("^http://")

50 .unwrap()

51 .is_match(&url)

52 {

53 /* TODO: include in config struct */

54 return format!("https://api.radio.typable.dev/pass?redirect={}", &url);

55 }

56 url

57}