Initial integration of the itunes resolver with the Add button.

This commit is contained in:
Jordan Petridis 2018-03-12 20:49:02 +02:00
parent b87c331b12
commit 8a18630ae5
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 15 additions and 5 deletions

View File

@ -12,6 +12,7 @@ use std::sync::mpsc::Sender;
use app::Action;
use stacks::Content;
use utils::itunes_to_rss;
#[derive(Debug, Clone)]
pub struct Header {
@ -154,8 +155,18 @@ impl Header {
}
}
// FIXME: THIS ALSO SUCKS!
fn on_add_bttn_clicked(entry: &gtk::Entry, sender: Sender<Action>) -> Result<(), Error> {
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.")?;
entry.set_text("");
@ -165,6 +176,7 @@ fn on_add_bttn_clicked(entry: &gtk::Entry, sender: Sender<Action>) -> Result<(),
Ok(())
}
// FIXME: THIS SUCKS!
fn on_url_change(
entry: &gtk::Entry,
result: &gtk::Label,

View File

@ -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 req: Value = reqwest::get(&url)?.json()?;
// FIXME: First time using serde, this could be done better and avoid using [] for indexing.
let feedurl = req["results"][0]["feedUrl"]
.as_str()
.ok_or_else(|| format_err!("Failed to get url from itunes response"))?
.into();
Ok(feedurl)
let feedurl = req["results"][0]["feedUrl"].as_str();
let feedurl = feedurl.ok_or_else(|| format_err!("Failed to get url from itunes response"))?;
Ok(feedurl.into())
}
#[cfg(test)]