summaryrefslogtreecommitdiffstats
path: root/src/cmd/sync.rs
diff options
context:
space:
mode:
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(())
+}