Initial integration of the itunes resolver with the Add button.
This commit is contained in:
parent
b87c331b12
commit
8a18630ae5
@ -12,6 +12,7 @@ use std::sync::mpsc::Sender;
|
|||||||
|
|
||||||
use app::Action;
|
use app::Action;
|
||||||
use stacks::Content;
|
use stacks::Content;
|
||||||
|
use utils::itunes_to_rss;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Header {
|
pub struct Header {
|
||||||
@ -154,8 +155,18 @@ impl Header {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: THIS ALSO SUCKS!
|
||||||
fn on_add_bttn_clicked(entry: >k::Entry, sender: Sender<Action>) -> Result<(), Error> {
|
fn on_add_bttn_clicked(entry: >k::Entry, sender: Sender<Action>) -> Result<(), Error> {
|
||||||
let url = entry.get_text().unwrap_or_default();
|
let url = entry.get_text().unwrap_or_default();
|
||||||
|
let url = if url.contains("itunes.com") || url.contains("apple.com") {
|
||||||
|
info!("Detected itunes url.");
|
||||||
|
let foo = itunes_to_rss(&url)?;
|
||||||
|
info!("Resolved to {}", foo);
|
||||||
|
foo
|
||||||
|
} else {
|
||||||
|
url.to_owned()
|
||||||
|
};
|
||||||
|
|
||||||
let source = Source::from_url(&url).context("Failed to convert url to a Source entry.")?;
|
let source = Source::from_url(&url).context("Failed to convert url to a Source entry.")?;
|
||||||
entry.set_text("");
|
entry.set_text("");
|
||||||
|
|
||||||
@ -165,6 +176,7 @@ fn on_add_bttn_clicked(entry: >k::Entry, sender: Sender<Action>) -> Result<(),
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: THIS SUCKS!
|
||||||
fn on_url_change(
|
fn on_url_change(
|
||||||
entry: >k::Entry,
|
entry: >k::Entry,
|
||||||
result: >k::Label,
|
result: >k::Label,
|
||||||
|
|||||||
@ -133,11 +133,9 @@ fn lookup_id(id: u32) -> Result<String, Error> {
|
|||||||
let url = format!("https://itunes.apple.com/lookup?id={}&entity=podcast", id);
|
let url = format!("https://itunes.apple.com/lookup?id={}&entity=podcast", id);
|
||||||
let req: Value = reqwest::get(&url)?.json()?;
|
let req: Value = reqwest::get(&url)?.json()?;
|
||||||
// FIXME: First time using serde, this could be done better and avoid using [] for indexing.
|
// FIXME: First time using serde, this could be done better and avoid using [] for indexing.
|
||||||
let feedurl = req["results"][0]["feedUrl"]
|
let feedurl = req["results"][0]["feedUrl"].as_str();
|
||||||
.as_str()
|
let feedurl = feedurl.ok_or_else(|| format_err!("Failed to get url from itunes response"))?;
|
||||||
.ok_or_else(|| format_err!("Failed to get url from itunes response"))?
|
Ok(feedurl.into())
|
||||||
.into();
|
|
||||||
Ok(feedurl)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user