add option to skip tracks on albums/playlists

This commit is contained in:
imsamuka 2022-01-02 20:25:47 -03:00
parent 72938a9b6a
commit 3d4acdeaea
No known key found for this signature in database
GPG key ID: AF9ACFEF1FD372EE
2 changed files with 24 additions and 7 deletions

View file

@ -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")}

View file

@ -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)