summaryrefslogtreecommitdiffstats
path: root/src/cmd/sync.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2018-11-07 20:48:13 -0500
committerJesse Luehrs <doy@tozt.net>2018-11-07 20:48:13 -0500
commit544b316bbaa36448b3272c4e00cd21c07fe0971d (patch)
treede3e491fd9e0f03026dd3a9cf66119c0ba8f014d /src/cmd/sync.rs
parent4f0fe4efb761670fac366122d1f724f54b075b76 (diff)
downloadlastfm-query-544b316bbaa36448b3272c4e00cd21c07fe0971d.tar.gz
lastfm-query-544b316bbaa36448b3272c4e00cd21c07fe0971d.zip
move subcommands to their own file
Diffstat (limited to 'src/cmd/sync.rs')
-rw-r--r--src/cmd/sync.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/cmd/sync.rs b/src/cmd/sync.rs
new file mode 100644
index 0000000..f8ca2b6
--- /dev/null
+++ b/src/cmd/sync.rs
@@ -0,0 +1,31 @@
+use cli;
+use db;
+use exporter;
+use lastfm;
+use paths;
+
+use failure;
+
+pub fn run(opts: &cli::Options) -> failure::Fallible<()> {
+ let db = db::DB::new(&paths::dbpath())?;
+ let lastfm = lastfm::LastFMClient::new(
+ opts.api_key.as_ref().unwrap(),
+ opts.username.as_ref().unwrap()
+ );
+
+ let exporter = exporter::Exporter::new(&db, &lastfm);
+
+ let to_fetch = exporter.tracks_to_sync()?;
+ let bar = indicatif::ProgressBar::new(to_fetch);
+ bar.set_style(
+ indicatif::ProgressStyle::default_bar()
+ .progress_chars("=> ")
+ .template("Downloading {pos}/{len} tracks...\n{percent:>3}% [{wide_bar}] {eta:5}")
+ );
+
+ exporter.sync(|_| { bar.inc(1); })?;
+
+ bar.finish_with_message("done");
+
+ Ok(())
+}