7digital.rb: Support MissingFiles.txt
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,4 +2,4 @@
|
|||||||
/config/*.toml
|
/config/*.toml
|
||||||
/log/
|
/log/
|
||||||
/tmp/
|
/tmp/
|
||||||
/vendor/
|
vendor/
|
||||||
|
|||||||
2
Gemfile
2
Gemfile
@@ -1,6 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
source "https://rubygems.org"
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
gem 'rubyzip', '~> 3.2'
|
gem 'rubyzip', '~> 3.2'
|
||||||
gem 'pg', '~> 1.6'
|
gem 'pg', '~> 1.6'
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# This Source Code Form is subject to the terms of the Mozilla Public License,
|
# 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
|
# 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
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
require 'open3'
|
require 'open3'
|
||||||
require 'optparse'
|
|
||||||
require 'zip'
|
require 'zip'
|
||||||
|
|
||||||
# Renames music files in a directory according to the file's tags.
|
# 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)
|
def extract_and_rename_archive(album_archive, music_directory)
|
||||||
music_directory.mkpath
|
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.open album_archive.to_path do |zip_file|
|
||||||
zip_file.each do |entry|
|
zip_file.each do |entry|
|
||||||
@@ -78,6 +76,7 @@ unless ARGV.length == 2
|
|||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
exit_code = 0
|
||||||
album_archive = Pathname.new ARGV[0]
|
album_archive = Pathname.new ARGV[0]
|
||||||
music_directory = Pathname.new ARGV[1]
|
music_directory = Pathname.new ARGV[1]
|
||||||
metadata = {}
|
metadata = {}
|
||||||
@@ -87,8 +86,13 @@ extract_and_rename_archive album_archive, music_directory
|
|||||||
Dir.each_child music_directory do |filename|
|
Dir.each_child music_directory do |filename|
|
||||||
song_path = music_directory + filename
|
song_path = music_directory + filename
|
||||||
|
|
||||||
|
if filename == 'MissingFiles.txt'
|
||||||
|
IO.copy_stream File.open(song_path, 'r'), $stderr
|
||||||
|
exit_code = 2
|
||||||
|
else
|
||||||
metadata[song_path] = probe_song(song_path)
|
metadata[song_path] = probe_song(song_path)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
metadata.each_pair do |from, to|
|
metadata.each_pair do |from, to|
|
||||||
album_path = music_directory + to.album
|
album_path = music_directory + to.album
|
||||||
@@ -96,3 +100,5 @@ metadata.each_pair do |from, to|
|
|||||||
album_path.mkpath
|
album_path.mkpath
|
||||||
File.rename(from, album_path + to.to_s)
|
File.rename(from, album_path + to.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
exit exit_code
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# This Source Code Form is subject to the terms of the Mozilla Public License,
|
# 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
|
# 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
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# This Source Code Form is subject to the terms of the Mozilla Public License,
|
# 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
|
# 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
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# This Source Code Form is subject to the terms of the Mozilla Public License,
|
# 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
|
# 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
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# This Source Code Form is subject to the terms of the Mozilla Public License,
|
# 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
|
# 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
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# This Source Code Form is subject to the terms of the Mozilla Public License,
|
# 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
|
# 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
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/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 'pathname'
|
||||||
require 'mysql2'
|
require 'mysql2'
|
||||||
|
|||||||
Reference in New Issue
Block a user