NewEpisode: refactor another if else statement and document it.

This commit is contained in:
Jordan Petridis 2018-04-03 20:05:00 +03:00
parent c910e0af40
commit 52cbe67756
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6

View File

@ -196,11 +196,14 @@ impl NewEpisodeMinimal {
let title = item.title().unwrap().trim().to_owned(); let title = item.title().unwrap().trim().to_owned();
let guid = item.guid().map(|s| s.value().trim().to_owned()); let guid = item.guid().map(|s| s.value().trim().to_owned());
let uri = if let Some(url) = item.enclosure().map(|s| url_cleaner(s.url())) { let uri = item.enclosure()
Some(url) .map(|s| url_cleaner(s.url()))
} else if item.link().is_some() { // Fallback to Rss.Item.link if enclosure is None.
item.link().map(|s| url_cleaner(s)) .or_else(|| item.link().map(|s| url_cleaner(s)));
} else {
// If url is still None return an Error as this behaviour is
// compliant with the RSS Spec.
if uri.is_none() {
let err = DataError::ParseEpisodeError { let err = DataError::ParseEpisodeError {
reason: "No url specified for the item.".into(), reason: "No url specified for the item.".into(),
parent_id, parent_id,