mirror of
https://github.com/cooperhammond/irs.git
synced 2025-01-02 19:15:26 +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 "single_folder_playlist"}:
|
||||||
#{Style.blue "enabled"}: #{Style.green "true"}
|
#{Style.blue "enabled"}: #{Style.green "true"}
|
||||||
#{Style.blue "retain_playlist_order"}: #{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 "===="}
|
#{Style.dim "===="}
|
||||||
EOP
|
EOP
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ module Config
|
||||||
"client_secret",
|
"client_secret",
|
||||||
"single_folder_playlist: enabled",
|
"single_folder_playlist: enabled",
|
||||||
"single_folder_playlist: retain_playlist_order",
|
"single_folder_playlist: retain_playlist_order",
|
||||||
"single_folder_playlist: overwrite_album",
|
"single_folder_playlist: unify_into_album",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@conf = YAML.parse("")
|
@@conf = YAML.parse("")
|
||||||
|
@ -67,8 +67,8 @@ module Config
|
||||||
return @@conf["single_folder_playlist"]["retain_playlist_order"].as_bool
|
return @@conf["single_folder_playlist"]["retain_playlist_order"].as_bool
|
||||||
end
|
end
|
||||||
|
|
||||||
def overwrite_album? : Bool
|
def unify_into_album? : Bool
|
||||||
return @@conf["single_folder_playlist"]["overwrite_album"].as_bool
|
return @@conf["single_folder_playlist"]["unify_into_album"].as_bool
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_necessities
|
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
|
prepped_data.album = album_metadata
|
||||||
|
|
||||||
data = parse_to_json(prepped_data.to_json)
|
data = parse_to_json(prepped_data.to_json)
|
||||||
|
|
|
@ -24,18 +24,27 @@ class PlaylistTracksMapper
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
class AlbumTracksMapper
|
class TrackMapper
|
||||||
JSON.mapping(
|
JSON.mapping(
|
||||||
album: {
|
album: {
|
||||||
type: JSON::Any,
|
type: JSON::Any,
|
||||||
nilable: true,
|
nilable: true,
|
||||||
setter: true,
|
setter: true,
|
||||||
},
|
},
|
||||||
artists: JSON::Any,
|
artists: {
|
||||||
disc_number: Int32,
|
type: Array(JSON::Any),
|
||||||
|
setter: true
|
||||||
|
},
|
||||||
|
disc_number: {
|
||||||
|
type: Int32,
|
||||||
|
setter: true
|
||||||
|
},
|
||||||
id: String,
|
id: String,
|
||||||
name: String,
|
name: String,
|
||||||
track_number: Int32,
|
track_number: {
|
||||||
|
type: Int32,
|
||||||
|
setter: true
|
||||||
|
},
|
||||||
type: String,
|
type: String,
|
||||||
uri: String
|
uri: String
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
|
require "json"
|
||||||
|
|
||||||
require "../bottle/config"
|
require "../bottle/config"
|
||||||
|
|
||||||
require "./song"
|
require "./song"
|
||||||
require "./list"
|
require "./list"
|
||||||
|
require "./mapper"
|
||||||
|
|
||||||
class Playlist < SpotifyList
|
class Playlist < SpotifyList
|
||||||
|
@song_index = 1
|
||||||
@home_music_directory = Config.music_directory
|
@home_music_directory = Config.music_directory
|
||||||
@playlist : JSON::Any?
|
@playlist : JSON::Any?
|
||||||
|
|
||||||
|
@ -28,6 +32,28 @@ class Playlist < SpotifyList
|
||||||
def organize_song_metadata(list : JSON::Any, datum : JSON::Any) : JSON::Any
|
def organize_song_metadata(list : JSON::Any, datum : JSON::Any) : JSON::Any
|
||||||
data = datum
|
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
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,8 @@ class Song
|
||||||
})
|
})
|
||||||
|
|
||||||
if !@metadata
|
if !@metadata
|
||||||
raise("There was no metadata found on Spotify for\n" +
|
raise("There was no metadata found on Spotify for " +
|
||||||
%("#{@song_name}" by "#{@artist_name}\n) +
|
%("#{@song_name}" by "#{@artist_name}". ) +
|
||||||
"Check your input and try again.")
|
"Check your input and try again.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -54,8 +54,8 @@ class Song
|
||||||
url = Youtube.find_url(@song_name, @artist_name, search_terms: "lyrics")
|
url = Youtube.find_url(@song_name, @artist_name, search_terms: "lyrics")
|
||||||
|
|
||||||
if !url
|
if !url
|
||||||
raise("There was no url found on youtube for\n" +
|
raise("There was no url found on youtube for " +
|
||||||
%("#{@song_name}" by "#{@artist_name}\n) +
|
%("#{@song_name}" by "#{@artist_name}. ) +
|
||||||
"Check your input and try again.")
|
"Check your input and try again.")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -67,7 +67,12 @@ class Song
|
||||||
File.write(temp_albumart_filename, response.body_io)
|
File.write(temp_albumart_filename, response.body_io)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 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
|
@artist = data["artists"][0]["name"].to_s
|
||||||
|
end
|
||||||
@album = data["album"]["name"].to_s
|
@album = data["album"]["name"].to_s
|
||||||
|
|
||||||
tagger = Tags.new(@filename)
|
tagger = Tags.new(@filename)
|
||||||
|
|
Loading…
Reference in a new issue