7digital.rb: Support MissingFiles.txt

This commit is contained in:
2025-11-16 12:47:23 +01:00
parent 964d815a90
commit a3530666a6
9 changed files with 20 additions and 11 deletions

2
.gitignore vendored
View File

@@ -2,4 +2,4 @@
/config/*.toml
/log/
/tmp/
/vendor/
vendor/

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
source "https://rubygems.org"
source 'https://rubygems.org'
gem 'rubyzip', '~> 3.2'
gem 'pg', '~> 1.6'

View File

@@ -1,13 +1,12 @@
#!/usr/bin/env ruby
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/. -}
# obtain one at https://mozilla.org/MPL/2.0/.
# frozen_string_literal: true
require 'pathname'
require 'open3'
require 'optparse'
require 'zip'
# Renames music files in a directory according to the file's tags.
@@ -38,7 +37,6 @@ end
def extract_and_rename_archive(album_archive, music_directory)
music_directory.mkpath
artist_name, album_name = album_archive.basename('.zip').to_s.split(' - ')
Zip::File.open album_archive.to_path do |zip_file|
zip_file.each do |entry|
@@ -78,6 +76,7 @@ unless ARGV.length == 2
exit 1
end
exit_code = 0
album_archive = Pathname.new ARGV[0]
music_directory = Pathname.new ARGV[1]
metadata = {}
@@ -87,7 +86,12 @@ extract_and_rename_archive album_archive, music_directory
Dir.each_child music_directory do |filename|
song_path = music_directory + filename
metadata[song_path] = probe_song(song_path)
if filename == 'MissingFiles.txt'
IO.copy_stream File.open(song_path, 'r'), $stderr
exit_code = 2
else
metadata[song_path] = probe_song(song_path)
end
end
metadata.each_pair do |from, to|
@@ -96,3 +100,5 @@ metadata.each_pair do |from, to|
album_path.mkpath
File.rename(from, album_path + to.to_s)
end
exit exit_code

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/. -}
# obtain one at https://mozilla.org/MPL/2.0/.
# frozen_string_literal: true

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/. -}
# obtain one at https://mozilla.org/MPL/2.0/.
# frozen_string_literal: true

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/. -}
# obtain one at https://mozilla.org/MPL/2.0/.
# frozen_string_literal: true

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/. -}
# obtain one at https://mozilla.org/MPL/2.0/.
# frozen_string_literal: true

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/. -}
# obtain one at https://mozilla.org/MPL/2.0/.
# frozen_string_literal: true

View File

@@ -1,4 +1,7 @@
#!/usr/bin/env ruby
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/.
require 'pathname'
require 'mysql2'