Make channel/item image optional; change item length type

This allows more back-ends to be compatible.
This commit is contained in:
Paul van Tilburg 2022-08-15 20:22:15 +02:00
parent 49e0e47ba2
commit 76f1e01657
Signed by: paul
GPG Key ID: C6DE073EDA9EEC4D
3 changed files with 15 additions and 15 deletions

View File

@ -64,7 +64,7 @@ pub(crate) struct Channel {
pub(crate) categories: Vec<String>,
/// The URL of the image/logo/avatar of a channel.
pub(crate) image: Url,
pub(crate) image: Option<Url>,
/// The contained content items.
pub(crate) items: Vec<Item>,
@ -99,7 +99,7 @@ pub(crate) struct Item {
pub(crate) keywords: Vec<String>,
/// The URL of the image of the item.
pub(crate) image: Url,
pub(crate) image: Option<Url>,
/// The timestamp the item was last updated.
pub(crate) updated_at: DateTime<Utc>,
@ -117,5 +117,5 @@ pub(crate) struct Enclosure {
pub(crate) mime_type: String,
/// The length of the enclosed media content (in bytes).
pub(crate) length: u32,
pub(crate) length: u64,
}

View File

@ -22,7 +22,7 @@ const API_BASE_URL: &str = "https://api.mixcloud.com";
const FILES_BASE_URL: &str = "https://www.mixcloud.com";
/// The default bitrate used by Mixcloud.
const DEFAULT_BITRATE: u32 = 64 * 1024;
const DEFAULT_BITRATE: u64 = 64 * 1024;
/// The default file (MIME) type used by Mixcloud.
const DEFAULT_FILE_TYPE: &str = "audio/mpeg";
@ -190,7 +190,7 @@ impl From<UserWithCloudcasts> for Channel {
description: user.biog,
author: Some(user.name),
categories,
image: user.pictures.large,
image: Some(user.pictures.large),
items,
}
}
@ -225,7 +225,7 @@ impl From<Cloudcast> for Item {
duration: Some(cloudcast.audio_length),
guid: cloudcast.slug,
keywords,
image: cloudcast.pictures.large,
image: Some(cloudcast.pictures.large),
updated_at: cloudcast.updated_time,
}
}
@ -234,8 +234,8 @@ impl From<Cloudcast> for Item {
/// Returns the estimated file size in bytes for a given duration.
///
/// This uses the default bitrate (see [`DEFAULT_BITRATE`]) which is in B/s.
fn estimated_file_size(duration: u32) -> u32 {
DEFAULT_BITRATE * duration / 8
fn estimated_file_size(duration: u32) -> u64 {
DEFAULT_BITRATE * duration as u64 / 8
}
/// Fetches the user from the URL.

View File

@ -34,10 +34,10 @@ pub(crate) fn construct(backend_id: &str, config: &Config, channel: Channel) ->
" ",
env!("CARGO_PKG_VERSION")
));
let image = ImageBuilder::default()
.link(channel.image.clone())
.url(channel.image.clone())
.build();
let image = channel
.image
.clone()
.map(|url| ImageBuilder::default().link(url.clone()).url(url).build());
let items = channel
.items
.into_iter()
@ -52,7 +52,7 @@ pub(crate) fn construct(backend_id: &str, config: &Config, channel: Channel) ->
.map(|cat| ITunesCategoryBuilder::default().text(cat).build())
.collect::<Vec<_>>(),
)
.image(Some(channel.image.to_string()))
.image(channel.image.map(String::from))
.explicit(Some(String::from("no")))
.summary(Some(channel.description.clone()))
.build();
@ -64,7 +64,7 @@ pub(crate) fn construct(backend_id: &str, config: &Config, channel: Channel) ->
.category(category)
.last_build_date(Some(last_build.to_rfc2822()))
.generator(Some(generator))
.image(Some(image))
.image(image)
.items(items)
.itunes_ext(Some(itunes_ext))
.build()
@ -106,7 +106,7 @@ fn construct_item(
.build();
let keywords = item.keywords.join(", ");
let itunes_ext = ITunesItemExtensionBuilder::default()
.image(Some(item.image.to_string()))
.image(item.image.map(String::from))
.duration(item.duration.map(|dur| format!("{dur}")))
.subtitle(item.description.clone())
.keywords(Some(keywords))