Handle microsecond timestamps

This commit is contained in:
George Hahn 2023-01-03 22:26:28 -07:00
parent edf646d4bb
commit 512c799266

View file

@ -129,6 +129,23 @@ impl Metadata for Playlist {
impl TryFrom<&<Playlist as Metadata>::Message> for SelectedListContent {
type Error = librespot_core::Error;
fn try_from(playlist: &<Playlist as Metadata>::Message) -> Result<Self, Self::Error> {
let timestamp = playlist.get_timestamp();
let timestamp = if timestamp > 1672809484000 {
// timestamp is way out of range for milliseconds. Some seem to be in microseconds?
// Observed on playlists where:
// format: "artist-mix-reader"
// format_attributes {
// key: "mediaListConfig"
// value: "spotify:medialistconfig:artist-seed-mix:default_v18"
// }
warn!("timestamp is very large; assuming it's in microseconds");
timestamp / 1000
} else {
timestamp
};
let timestamp = Date::from_timestamp_ms(timestamp)?;
Ok(Self {
revision: playlist.get_revision().to_owned(),
length: playlist.get_length(),
@ -144,7 +161,7 @@ impl TryFrom<&<Playlist as Metadata>::Message> for SelectedListContent {
has_multiple_heads: playlist.get_multiple_heads(),
is_up_to_date: playlist.get_up_to_date(),
nonces: playlist.get_nonces().into(),
timestamp: Date::from_timestamp_ms(playlist.get_timestamp())?,
timestamp,
owner_username: playlist.get_owner_username().to_owned(),
has_abuse_reporting: playlist.get_abuse_reporting_enabled(),
capabilities: playlist.get_capabilities().into(),