mirror of
https://github.com/cooperhammond/irs.git
synced 2024-12-21 17:25:28 +00:00
feature: unify into album option in config works now
This commit is contained in:
parent
ce6f77d68d
commit
451ef33cca
|
@ -14,7 +14,7 @@ EXAMPLE_CONFIG = <<-EOP
|
|||
#{Style.blue "single_folder_playlist"}:
|
||||
#{Style.blue "enabled"}: #{Style.green "true"}
|
||||
#{Style.blue "retain_playlist_order"}: #{Style.green "true"}
|
||||
#{Style.blue "overwrite_album"}: #{Style.green "false"}
|
||||
#{Style.blue "unify_into_album"}: #{Style.green "false"}
|
||||
#{Style.dim "===="}
|
||||
EOP
|
||||
|
||||
|
@ -28,7 +28,7 @@ module Config
|
|||
"client_secret",
|
||||
"single_folder_playlist: enabled",
|
||||
"single_folder_playlist: retain_playlist_order",
|
||||
"single_folder_playlist: overwrite_album",
|
||||
"single_folder_playlist: unify_into_album",
|
||||
]
|
||||
|
||||
@@conf = YAML.parse("")
|
||||
|
@ -67,8 +67,8 @@ module Config
|
|||
return @@conf["single_folder_playlist"]["retain_playlist_order"].as_bool
|
||||
end
|
||||
|
||||
def overwrite_album? : Bool
|
||||
return @@conf["single_folder_playlist"]["overwrite_album"].as_bool
|
||||
def unify_into_album? : Bool
|
||||
return @@conf["single_folder_playlist"]["unify_into_album"].as_bool
|
||||
end
|
||||
|
||||
def check_necessities
|
||||
|
|
|
@ -33,7 +33,7 @@ class Album < SpotifyList
|
|||
}
|
||||
))
|
||||
|
||||
prepped_data = AlbumTracksMapper.from_json(datum.to_json)
|
||||
prepped_data = TrackMapper.from_json(datum.to_json)
|
||||
prepped_data.album = album_metadata
|
||||
|
||||
data = parse_to_json(prepped_data.to_json)
|
||||
|
|
|
@ -24,18 +24,27 @@ class PlaylistTracksMapper
|
|||
)
|
||||
end
|
||||
|
||||
class AlbumTracksMapper
|
||||
class TrackMapper
|
||||
JSON.mapping(
|
||||
album: {
|
||||
type: JSON::Any,
|
||||
nilable: true,
|
||||
setter: true,
|
||||
},
|
||||
artists: JSON::Any,
|
||||
disc_number: Int32,
|
||||
artists: {
|
||||
type: Array(JSON::Any),
|
||||
setter: true
|
||||
},
|
||||
disc_number: {
|
||||
type: Int32,
|
||||
setter: true
|
||||
},
|
||||
id: String,
|
||||
name: String,
|
||||
track_number: Int32,
|
||||
track_number: {
|
||||
type: Int32,
|
||||
setter: true
|
||||
},
|
||||
type: String,
|
||||
uri: String
|
||||
)
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
require "json"
|
||||
|
||||
require "../bottle/config"
|
||||
|
||||
require "./song"
|
||||
require "./list"
|
||||
require "./mapper"
|
||||
|
||||
class Playlist < SpotifyList
|
||||
@song_index = 1
|
||||
@home_music_directory = Config.music_directory
|
||||
@playlist : JSON::Any?
|
||||
|
||||
|
@ -28,6 +32,28 @@ class Playlist < SpotifyList
|
|||
def organize_song_metadata(list : JSON::Any, datum : JSON::Any) : JSON::Any
|
||||
data = datum
|
||||
|
||||
if Config.retain_playlist_order?
|
||||
track = TrackMapper.from_json(data.to_json)
|
||||
track.track_number = @song_index
|
||||
track.disc_number = 1
|
||||
data = JSON.parse(track.to_json)
|
||||
end
|
||||
|
||||
if Config.unify_into_album?
|
||||
track = TrackMapper.from_json(data.to_json)
|
||||
track.album = JSON.parse(%({
|
||||
"name": "#{list["name"]}",
|
||||
"images": [{"url": "#{list["images"][0]["url"]}"}]
|
||||
}))
|
||||
track.artists.push(JSON.parse(%({
|
||||
"name": "#{list["owner"]["display_name"]}",
|
||||
"owner": true
|
||||
})))
|
||||
data = JSON.parse(track.to_json)
|
||||
end
|
||||
|
||||
@song_index += 1
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
|
|
|
@ -40,8 +40,8 @@ class Song
|
|||
})
|
||||
|
||||
if !@metadata
|
||||
raise("There was no metadata found on Spotify for\n" +
|
||||
%("#{@song_name}" by "#{@artist_name}\n) +
|
||||
raise("There was no metadata found on Spotify for " +
|
||||
%("#{@song_name}" by "#{@artist_name}". ) +
|
||||
"Check your input and try again.")
|
||||
end
|
||||
end
|
||||
|
@ -54,8 +54,8 @@ class Song
|
|||
url = Youtube.find_url(@song_name, @artist_name, search_terms: "lyrics")
|
||||
|
||||
if !url
|
||||
raise("There was no url found on youtube for\n" +
|
||||
%("#{@song_name}" by "#{@artist_name}\n) +
|
||||
raise("There was no url found on youtube for " +
|
||||
%("#{@song_name}" by "#{@artist_name}. ) +
|
||||
"Check your input and try again.")
|
||||
end
|
||||
|
||||
|
@ -67,7 +67,12 @@ class Song
|
|||
File.write(temp_albumart_filename, response.body_io)
|
||||
end
|
||||
|
||||
@artist = data["artists"][0]["name"].to_s
|
||||
# check if song's metadata has been modded in playlist, update artist accordingly
|
||||
if data["artists"][-1]["owner"]?
|
||||
@artist = data["artists"][-1]["name"].to_s
|
||||
else
|
||||
@artist = data["artists"][0]["name"].to_s
|
||||
end
|
||||
@album = data["album"]["name"].to_s
|
||||
|
||||
tagger = Tags.new(@filename)
|
||||
|
@ -75,7 +80,7 @@ class Song
|
|||
tagger.add_text_tag("title", data["name"].to_s)
|
||||
tagger.add_text_tag("artist", @artist)
|
||||
tagger.add_text_tag("album", @album)
|
||||
tagger.add_text_tag("genre",
|
||||
tagger.add_text_tag("genre",
|
||||
@spotify_searcher.find_genre(data["artists"][0]["id"].to_s))
|
||||
tagger.add_text_tag("track", data["track_number"].to_s)
|
||||
tagger.add_text_tag("disc", data["disc_number"].to_s)
|
||||
|
|
Loading…
Reference in a new issue