-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #563 from RustyNova016/feat/playlist_converter
feat: playlist exporter
- Loading branch information
Showing
16 changed files
with
257 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Playlist | ||
|
||
Those commands interact with playlists | ||
|
||
## `convert` | ||
|
||
Convert a playlist from one service to another | ||
|
||
[Usage](../CommandLineHelp.md#alistral-playlist-convert) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use listenbrainz::raw::jspf; | ||
use listenbrainz::raw::jspf::Track; | ||
use musicbrainz_rs::utils::parse_mbid; | ||
|
||
use crate::models::messy_recording::MessyRecording; | ||
use crate::models::playlist_stub::PlaylistStub; | ||
|
||
impl From<jspf::PlaylistInfo> for PlaylistStub { | ||
fn from(value: jspf::PlaylistInfo) -> Self { | ||
PlaylistStub { | ||
title: value.title, | ||
description: value.annotation.unwrap_or_default(), | ||
recordings: value.track.into_iter().map(MessyRecording::from).collect(), | ||
} | ||
} | ||
} | ||
|
||
impl From<Track> for MessyRecording { | ||
fn from(value: Track) -> Self { | ||
Self { | ||
id: 0, | ||
artist_credits: value.creator, | ||
title: value.title, | ||
release: Some(value.album), | ||
mbid: value | ||
.identifier | ||
.into_iter() | ||
.filter_map(|s| parse_mbid(&s)) | ||
.next(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use clap::Parser; | ||
use interzic::models::services::listenbrainz::Listenbrainz; | ||
use interzic::models::services::youtube::Youtube; | ||
use tuillez::fatal_error::IntoFatal; | ||
|
||
use crate::api::clients::ALISTRAL_CLIENT; | ||
use crate::tools::playlist::PlaylistOrigin; | ||
use crate::tools::playlist::PlaylistTarget; | ||
|
||
#[derive(Parser, Debug, Clone)] | ||
pub struct PlaylistConvertCommand { | ||
/// Get the playlist from which service? | ||
pub source: PlaylistOrigin, | ||
|
||
/// The id of the playlist on the external service | ||
pub id: String, | ||
|
||
/// Convert to this service | ||
pub target: PlaylistTarget, | ||
} | ||
|
||
impl PlaylistConvertCommand { | ||
pub async fn run(&self, _conn: &mut sqlx::SqliteConnection) -> Result<(), crate::Error> { | ||
let playlist = match self.source { | ||
PlaylistOrigin::Listenbrainz => { | ||
Listenbrainz::import_playlist(&ALISTRAL_CLIENT.interzic, &self.id) | ||
.expect_fatal("Couldn't retrieve the playlist. Check for typos.")? | ||
} | ||
}; | ||
|
||
let playlist = playlist | ||
.save_recordings(&ALISTRAL_CLIENT.interzic) | ||
.await | ||
.expect_fatal("Couldn't save the playlist's recording")?; | ||
|
||
match self.target { | ||
PlaylistTarget::Youtube => { | ||
Youtube::create_playlist(&ALISTRAL_CLIENT.interzic, playlist) | ||
.await | ||
.expect_fatal("Couldn't send the playlist to youtube")?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.