parent
b2723e06ac
commit
2bfbf2da58
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,10 @@ |
|||||||
|
[package] |
||||||
|
name = "spotify-dump" |
||||||
|
version = "0.1.0" |
||||||
|
authors = ["Katharina Fey <kookie@spacekookie.de>"] |
||||||
|
edition = "2018" |
||||||
|
|
||||||
|
[dependencies] |
||||||
|
librespot = "0.1" |
||||||
|
tokio-core = "0.1" |
||||||
|
env_logger = "*" |
@ -0,0 +1,3 @@ |
|||||||
|
# spotify-dump |
||||||
|
|
||||||
|
Get play metadata from spotify |
@ -0,0 +1,16 @@ |
|||||||
|
with (import <nixpkgs> {}); |
||||||
|
|
||||||
|
stdenv.mkDerivation { |
||||||
|
name = "rust-devel"; |
||||||
|
buildInputs = with pkgs; [ |
||||||
|
cargo |
||||||
|
cargo-watch |
||||||
|
clangStdenv |
||||||
|
rust-analyzer |
||||||
|
rustc |
||||||
|
rustfmt |
||||||
|
|
||||||
|
pkg-config |
||||||
|
alsaLib |
||||||
|
]; |
||||||
|
} |
@ -0,0 +1,57 @@ |
|||||||
|
use env_logger; |
||||||
|
use std::env; |
||||||
|
use tokio_core::reactor::Core; |
||||||
|
|
||||||
|
use librespot::core::authentication::Credentials; |
||||||
|
use librespot::core::config::SessionConfig; |
||||||
|
use librespot::core::session::Session; |
||||||
|
use librespot::core::spotify_id::SpotifyId; |
||||||
|
use librespot::metadata::{Metadata, Playlist, Track, Album}; |
||||||
|
|
||||||
|
use std::collections::HashMap; |
||||||
|
|
||||||
|
fn main() { |
||||||
|
env_logger::init(); |
||||||
|
let mut core = Core::new().unwrap(); |
||||||
|
let handle = core.handle(); |
||||||
|
|
||||||
|
let session_config = SessionConfig::default(); |
||||||
|
|
||||||
|
let args: Vec<_> = env::args().collect(); |
||||||
|
if args.len() != 4 { |
||||||
|
println!("Usage: {} USERNAME PASSWORD PLAYLIST", args[0]); |
||||||
|
std::process::exit(1); |
||||||
|
} |
||||||
|
let username = args[1].to_owned(); |
||||||
|
let password = args[2].to_owned(); |
||||||
|
let credentials = Credentials::with_password(username, password); |
||||||
|
|
||||||
|
let uri_split = args[3].split(":"); |
||||||
|
let uri_parts: Vec<&str> = uri_split.collect(); |
||||||
|
println!("{}, {}, {}", uri_parts[0], uri_parts[1], uri_parts[2]); |
||||||
|
|
||||||
|
let plist_uri = SpotifyId::from_base62(uri_parts[2]).unwrap(); |
||||||
|
|
||||||
|
let session = core |
||||||
|
.run(Session::connect(session_config, credentials, None, handle)) |
||||||
|
.unwrap(); |
||||||
|
|
||||||
|
let plist = core.run(Playlist::get(&session, plist_uri)).unwrap(); |
||||||
|
|
||||||
|
let mut albums = HashMap::new(); |
||||||
|
|
||||||
|
for track_id in plist.tracks { |
||||||
|
let plist_track = core.run(Track::get(&session, track_id)).unwrap(); |
||||||
|
let album_id = plist_track.album; |
||||||
|
|
||||||
|
if !albums.contains_key(&album_id) { |
||||||
|
println!("New album ID: {:?}", album_id); |
||||||
|
let album = core.run(Album::get(&session, album_id)).unwrap(); |
||||||
|
albums.insert(album_id, album.name); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
for (_, name) in albums { |
||||||
|
println!("Album: {} ", name); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue