From 3d4acdeaea581f9087e5b963ee1f3fa03293964a Mon Sep 17 00:00:00 2001 From: imsamuka Date: Sun, 2 Jan 2022 20:25:47 -0300 Subject: [PATCH] add option to skip tracks on albums/playlists --- src/bottle/cli.cr | 4 +++- src/glue/list.cr | 27 +++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/bottle/cli.cr b/src/bottle/cli.cr index 2ff974a..c0d22bb 100755 --- a/src/bottle/cli.cr +++ b/src/bottle/cli.cr @@ -21,7 +21,8 @@ class CLI [["-A", "--album"], "album", "string"], [["-p", "--playlist"], "playlist", "string"], [["-u", "--url"], "url", "string"], - [["-S", "--select"], "select", "bool"] + [["-S", "--select"], "select", "bool"], + [["--ask-skip"], "ask_skip", "bool"] ] @args : Hash(String, String) @@ -54,6 +55,7 @@ class CLI #{Style.blue " "} (for albums and playlists, the command-line #{Style.blue " "} argument is ignored, and it should be '') #{Style.blue "-S, --select"} Use a menu to choose each song's video source + #{Style.blue "--ask-skip"} Before every playlist/album song, ask to skip #{Style.bold "Examples:"} $ #{Style.green %(irs --song "Bohemian Rhapsody" --artist "Queen")} diff --git a/src/glue/list.cr b/src/glue/list.cr index 717b0ed..6cfc11c 100755 --- a/src/glue/list.cr +++ b/src/glue/list.cr @@ -29,6 +29,8 @@ abstract class SpotifyList # Finds the list, and downloads all of the songs using the `Song` class def grab_it(flags = {} of String => String) ask_url = flags["url"]? + ask_skip = flags["ask_skip"]? + is_playlist = flags["playlist"]? if !@spotify_searcher.authorized? raise("Need to call provide_client_keys on Album or Playlist class.") @@ -45,22 +47,28 @@ abstract class SpotifyList i = 0 contents.each do |datum| + i += 1 if datum["track"]? datum = datum["track"] end data = organize_song_metadata(list, datum) - song = Song.new(data["name"].to_s, data["artists"][0]["name"].to_s) + s_name = data["name"].to_s + s_artist = data["artists"][0]["name"].to_s + + song = Song.new(s_name, s_artist) song.provide_spotify(@spotify_searcher) song.provide_metadata(data) - puts Style.bold("[#{data["track_number"]}/#{contents.size}]") - song.grab_it(flags: flags) + puts Style.bold("[#{i}/#{contents.size}]") - organize(song) - - i += 1 + unless ask_skip && skip?(s_name, s_artist, is_playlist) + song.grab_it(flags: flags) + organize(song) + else + puts "Skipping..." + end end end @@ -69,6 +77,13 @@ abstract class SpotifyList @spotify_searcher.authorize(client_key, client_secret) end + private def skip?(name, artist, is_playlist) + print "Skip #{Style.blue name}" + + (is_playlist ? " (by #{Style.green artist})": "") + "? " + response = gets + return response && response.lstrip.downcase.starts_with? "y" + end + private def outputter(key : String, index : Int32) text = @outputs[key][index] .gsub("%l", @list_name)