Files
ncspot/src/model/episode.rs
dependabot[bot] 2a44323d59 chore(deps): bump the cargo group with 8 updates (#1359)
* chore(deps): bump the cargo group with 8 updates

Bumps the cargo group with 8 updates:

| Package | From | To |
| --- | --- | --- |
| [clap](https://github.com/clap-rs/clap) | `4.4.11` | `4.4.12` |
| [crossbeam-channel](https://github.com/crossbeam-rs/crossbeam) | `0.5.9` | `0.5.10` |
| [futures](https://github.com/rust-lang/futures-rs) | `0.3.29` | `0.3.30` |
| [reqwest](https://github.com/seanmonstar/reqwest) | `0.11.22` | `0.11.23` |
| [serde_json](https://github.com/serde-rs/json) | `1.0.108` | `1.0.109` |
| [tokio](https://github.com/tokio-rs/tokio) | `1.35.0` | `1.35.1` |
| [clap_mangen](https://github.com/clap-rs/clap) | `0.2.15` | `0.2.16` |
| [clap_complete](https://github.com/clap-rs/clap) | `4.4.4` | `4.4.5` |


Updates `clap` from 4.4.11 to 4.4.12
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/v4.4.11...v4.4.12)

Updates `crossbeam-channel` from 0.5.9 to 0.5.10
- [Release notes](https://github.com/crossbeam-rs/crossbeam/releases)
- [Changelog](https://github.com/crossbeam-rs/crossbeam/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crossbeam-rs/crossbeam/compare/crossbeam-channel-0.5.9...crossbeam-channel-0.5.10)

Updates `futures` from 0.3.29 to 0.3.30
- [Release notes](https://github.com/rust-lang/futures-rs/releases)
- [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/futures-rs/compare/0.3.29...0.3.30)

Updates `reqwest` from 0.11.22 to 0.11.23
- [Release notes](https://github.com/seanmonstar/reqwest/releases)
- [Changelog](https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/seanmonstar/reqwest/compare/v0.11.22...v0.11.23)

Updates `serde_json` from 1.0.108 to 1.0.109
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.108...v1.0.109)

Updates `tokio` from 1.35.0 to 1.35.1
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.35.0...tokio-1.35.1)

Updates `clap_mangen` from 0.2.15 to 0.2.16
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_mangen-v0.2.15...clap_mangen-v0.2.16)

Updates `clap_complete` from 4.4.4 to 4.4.5
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.4.4...clap_complete-v4.4.5)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: crossbeam-channel
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: futures
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: reqwest
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: serde_json
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: tokio
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: clap_mangen
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: clap_complete
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
...

Signed-off-by: dependabot[bot] <support@github.com>

* Use `.first()` instead of `.get(0)`

* Update dependencies

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
2024-01-01 14:56:39 +00:00

121 lines
3.3 KiB
Rust

use crate::library::Library;
use crate::model::playable::Playable;
use crate::queue::Queue;
use crate::traits::{ListItem, ViewExt};
use crate::utils::ms_to_hms;
use chrono::{DateTime, Utc};
use rspotify::model::show::{FullEpisode, SimplifiedEpisode};
use rspotify::model::Id;
use std::fmt;
use std::sync::Arc;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Episode {
pub id: String,
pub uri: String,
pub duration: u32,
pub name: String,
pub description: String,
pub release_date: String,
pub cover_url: Option<String>,
pub added_at: Option<DateTime<Utc>>,
pub list_index: usize,
}
impl Episode {
pub fn duration_str(&self) -> String {
ms_to_hms(self.duration)
}
}
impl From<&SimplifiedEpisode> for Episode {
fn from(episode: &SimplifiedEpisode) -> Self {
Self {
id: episode.id.id().to_string(),
uri: episode.id.uri(),
duration: episode.duration.num_milliseconds() as u32,
name: episode.name.clone(),
description: episode.description.clone(),
release_date: episode.release_date.clone(),
cover_url: episode.images.first().map(|img| img.url.clone()),
added_at: None,
list_index: 0,
}
}
}
impl From<&FullEpisode> for Episode {
fn from(episode: &FullEpisode) -> Self {
Self {
id: episode.id.id().to_string(),
uri: episode.id.uri(),
duration: episode.duration.num_milliseconds() as u32,
name: episode.name.clone(),
description: episode.description.clone(),
release_date: episode.release_date.clone(),
cover_url: episode.images.first().map(|img| img.url.clone()),
added_at: None,
list_index: 0,
}
}
}
impl fmt::Display for Episode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.name)
}
}
impl ListItem for Episode {
fn is_playing(&self, queue: &Queue) -> bool {
let current = queue.get_current();
current
.map(|t| t.id() == Some(self.id.clone()))
.unwrap_or(false)
}
fn display_left(&self, _library: &Library) -> String {
self.name.clone()
}
fn display_right(&self, _library: &Library) -> String {
format!("{} [{}]", self.duration_str(), self.release_date)
}
fn play(&mut self, queue: &Queue) {
let index = queue.append_next(&vec![Playable::Episode(self.clone())]);
queue.play(index, true, false);
}
fn play_next(&mut self, queue: &Queue) {
queue.insert_after_current(Playable::Episode(self.clone()));
}
fn queue(&mut self, queue: &Queue) {
queue.append(Playable::Episode(self.clone()));
}
fn toggle_saved(&mut self, _library: &Library) {}
fn save(&mut self, _library: &Library) {}
fn unsave(&mut self, _library: &Library) {}
fn open(&self, _queue: Arc<Queue>, _library: Arc<Library>) -> Option<Box<dyn ViewExt>> {
None
}
fn share_url(&self) -> Option<String> {
Some(format!("https://open.spotify.com/episode/{}", self.id))
}
#[inline]
fn is_playable(&self) -> bool {
true
}
fn as_listitem(&self) -> Box<dyn ListItem> {
Box::new(self.clone())
}
}