commit 6dbf8f26b4cf94ddfce900ffe7a108e90c79caab
parent 51af0da318c57b561a7104a4973432134c56cdcc
Author: Lazaros Koromilas <lostd@2f30.org>
Date: Wed, 15 Jan 2025 17:09:06 +0200
Migrate to newer File.exist and URI.open calls
Diffstat:
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/bin/musicfix b/bin/musicfix
@@ -260,7 +260,7 @@ cfg['nimg'] = 1
# User configuration overrides
cfgpath = File.expand_path('~/.musicfixrc')
-if File.exists? cfgpath
+if File.exist? cfgpath
new = YAML.load File.open(cfgpath, 'r')
cfg.merge! new
end
@@ -280,7 +280,7 @@ puts cfg.to_yaml
# Early file checks
if cmd == 'dump' or cmd == 'tags' then
- if File.exists? relfile then
+ if File.exist? relfile then
STDERR.puts "Release file #{relfile} exists!"
exit
end
@@ -305,13 +305,13 @@ if cmd == 'load' then
# Load release data from file
if relfile then
# The user specified some file
- unless File.exists? relfile then
+ unless File.exist? relfile then
STDERR.puts "Release file #{relfile} not found!"
exit 1
end
else
# Look for 'release.yaml' first
- if File.exists? 'release.yaml' then
+ if File.exist? 'release.yaml' then
relfile = 'release.yaml'
else
# Look for any '.yaml' file
@@ -374,10 +374,12 @@ elsif cmd == 'tags' then
else
# Get release data from Discogs
STDERR.puts "Getting release data from Discogs..."
- r = YAML.load(open("https://api.discogs.com/releases/#{relid}#{urlopts}",
+ r = YAML.load(
+ URI.open("https://api.discogs.com/releases/#{relid}#{urlopts}",
Headers))
mr = if r['master_id'] then
- YAML.load(open("https://api.discogs.com/masters/#{r['master_id']}#{urlopts}",
+ YAML.load(
+ URI.open("https://api.discogs.com/masters/#{r['master_id']}#{urlopts}",
Headers))
end
# Tracklist can contain dummy header tracks, strip them
@@ -523,10 +525,10 @@ if rel['images'] then
STDERR.puts "Save image to #{imgname}"
unless fake
# Relative path or URL
- if File.exists? imgurl
+ if File.exist? imgurl
img = open(imgurl).read
else
- img = open(imgurl, Headers).read
+ img = URI.open(imgurl, Headers).read
end
File.open(imgname, 'wb').write img
# Update to local relative path now