Skip to content

Commit

Permalink
feat: adding export command
Browse files Browse the repository at this point in the history
  • Loading branch information
SilentVoid13 committed Oct 15, 2024
1 parent 285a411 commit 75d83dd
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sync_dis_boi"
version = "0.2.0"
version = "0.3.0"
edition = "2021"

[dependencies]
Expand Down
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ SyncDisBoi is a simple and efficient tool designed to synchronize playlists acro
- [Spotify](https://open.spotify.com/)
- [Tidal](https://tidal.com/)

It's the perfect solution for music enthusiasts who want to keep their playlists updated across different music streaming platforms and enjoy the various recommendations algorithms, or who simply want to migrate to a new music platform and preserve their playlists.
SyncDisBoi is the ideal tool for music enthusiasts who want to:
- Seamlessly migrate to a new music platform while preserving their playlists
- Keep playlists in sync across multiple platforms and enjoy each platform's unique recommendation algorithms
- Export existing playlists in a portable JSON format for easy backup or sharing

> **Disclaimer**: While SyncDisBoi doesn't perform any deletion operations, it's always a good practice to backup your playlists. I am not responsible for any unintended changes to your playlists.
Expand All @@ -24,10 +27,16 @@ Notes:
- The artist names are not used because the metadata is inconsistent across platforms.
- For Youtube Music, SyncDisBoi won't sync tracks lacking album metadata, as this typically indicates a video from Youtube, which lacks the necessary metadata for accurate synchronization.

## Usage
## Download and Build

Pre-built binaries of SyncDisBoi for Linux, Windows, and macOS are available under the [releases](https://github.com/SilentVoid13/SyncDisBoi/releases) section.

You can find binaries of SyncDisBoi for all major platforms (Linux, Windows, Mac) under [releases](https://github.com/SilentVoid13/SyncDisBoi/releases).
If you prefer to build SyncDisBoi from source you simply need the rust toolchain, e.g. available via [rustup](https://rustup.rs/).
A [Nix flake](https://github.com/SilentVoid13/SyncDisBoi/blob/master/flake.nix) is also available with a pre-configured environment with support for cross-compilation.

## Usage

Here are some command examples:
```bash
# sync from Youtube Music to Spotify
./sync_dis_boi yt-music spotify --client-id "<CLIENT_ID>" --client-secret "<CLIENT_SECRET>"
Expand All @@ -37,6 +46,13 @@ You can find binaries of SyncDisBoi for all major platforms (Linux, Windows, Mac
./sync_dis_boi tidal yt-music
# sync from Spotify to Youtube Music, with debug mode enabled to generate detailed statistics about the synchronization process
./sync_dis_boi --debug spotify --client-id "<CLIENT_ID>" --client-secret "<CLIENT_SECRET>" yt-music

# export Spotify playlists to JSON
./sync_dis_boi spotify export -d ./spotify.json
# export Youtube Music playlists to JSON
./sync_dis_boi yt-music export -d ./yt_music.json
# export Tidal playlists to JSON
./sync_dis_boi tidal export -d ./tidal.json
```

To use SyncDisBoi, you need to set up account access for the API of the corresponding music platform.
Expand Down
10 changes: 10 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::PathBuf;

use clap::{Parser, Subcommand, ValueEnum};
use tracing::Level;

Expand Down Expand Up @@ -128,6 +130,14 @@ pub enum MusicPlatformDst {
#[arg(long)]
clear_cache: bool,
},
Export {
/// The path to the file to export the playlists to
#[arg(short, long)]
dest: PathBuf,
/// Minify the exported JSON file
#[arg(long, default_value = "false")]
minify: bool,
}
}

#[derive(ValueEnum, Clone, Debug)]
Expand Down
4 changes: 3 additions & 1 deletion src/build_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::Path;

use async_trait::async_trait;
use color_eyre::eyre::Result;
use color_eyre::eyre::{eyre, Result};
use sync_dis_boi::music_api::DynMusicApi;
use sync_dis_boi::spotify::SpotifyApi;
use sync_dis_boi::tidal::TidalApi;
Expand Down Expand Up @@ -72,6 +72,8 @@ macro_rules! impl_build_api {
)
.await?,
),
#[allow(unreachable_patterns)]
_ => return Err(eyre!("Invalid API type: {:?}", self)),
};
Ok(api)
}
Expand Down
21 changes: 21 additions & 0 deletions src/export.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::path::Path;

use color_eyre::eyre::Result;
use tracing::info;

use crate::music_api::DynMusicApi;

pub async fn export(src_api: DynMusicApi, path: &Path, minify: bool) -> Result<()> {
info!("retrieving playlists...");
let src_playlists = src_api.get_playlists_full().await?;

info!("exporting playlists...");
if !minify {
serde_json::to_writer_pretty(std::fs::File::create(path)?, &src_playlists)?;
} else {
serde_json::to_writer(std::fs::File::create(path)?, &src_playlists)?;
}
info!("successfully exported playlists to: {:?}", path);

Ok(())
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod export;
pub mod music_api;
pub mod spotify;
pub mod sync;
Expand Down
14 changes: 11 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ mod build_api;

use std::path::Path;

use args::RootArgs;
use args::{MusicPlatformDst, RootArgs};
use build_api::BuildApi;
use clap::Parser;
use color_eyre::eyre::{eyre, Result};
use sync_dis_boi::export::export;
use sync_dis_boi::sync::synchronize;
use tracing::{debug, info, Level};
use tracing_subscriber::filter::Targets;
Expand Down Expand Up @@ -45,8 +46,15 @@ async fn main() -> Result<()> {
debug!("logging level: {}", level);

let src_api = args.src.parse(&args, &config_dir).await?;
let dst_api = args.src.get_dst().parse(&args, &config_dir).await?;
synchronize(src_api, dst_api, args.debug).await?;
match args.src.get_dst() {
MusicPlatformDst::Export { dest, minify } => {
export(src_api, dest, *minify).await?;
},
_ => {
let dst_api = args.src.get_dst().parse(&args, &config_dir).await?;
synchronize(src_api, dst_api, args.debug).await?;
}
}

Ok(())
}

0 comments on commit 75d83dd

Please sign in to comment.