Created
February 18, 2021 05:39
-
-
Save deevis/cf49972ca25caa0b2467f4d565bf930e to your computer and use it in GitHub Desktop.
If you have a bunch of F00-F95 mp3 folders with encrypted file names, put this in the same folder to build an unencrypted filename directory structure of files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To build music_log.txt | |
# ------------------------------------ | |
# sudo apt-get install ffmpeg | |
# SAVEIFS=$IFS | |
# IFS=$(echo -en "\n\b") | |
# for file in `find . -iname "*.mp3"`;do echo "=========================="; echo $file; ffprobe $file 2>&1 | grep -A 12 'Metadata:'; done > music_log.txt | |
require 'awesome_print' | |
# require 'byebug' | |
songs = [] | |
song = nil | |
def d(s) | |
return 'Unknown' if s.nil? | |
s.gsub!("'", "") | |
s.gsub!("/", ":") | |
s.gsub!('"','') | |
s.gsub!('*', '') | |
s.gsub!('[', '') | |
s.gsub!(']', '') | |
s | |
end | |
_artist = "artist :" | |
_title = "title :" | |
_album = "album :" | |
_track = "track :" | |
data = File.open("music_log.txt") do |f| | |
while (line = f.readline) != nil | |
if line.index("=====") | |
if !song.nil? | |
directory = "transformed/#{d(song[:artist])}/#{d(song[:album])}" | |
filename = "#{d(song[:track])} - #{d(song[:title])}" | |
fullpath = "'#{directory}/#{filename}'" | |
if `ls -al #{fullpath} 2>&1`.index("No such file or directory") | |
`mkdir -p "#{directory}"` | |
original = song[:location] | |
# byebug | |
cmd = "cp \"#{original}\" #{fullpath}" | |
puts cmd | |
`#{cmd}` | |
ap song | |
end | |
end | |
song = {} | |
songs << song | |
song[:location] = f.readline.strip | |
next | |
elsif line.index(_artist) | |
song[:artist] = line.split(_artist).last.strip | |
elsif line.index(_title) | |
title = line.split(_title).last.strip | |
song[:title] = title.index(".mp3") ? title : "#{title}.mp3" | |
elsif line.index(_album) | |
song[:album] = line.split(_album).last.strip | |
elsif line.index(_track) | |
song[:track] = line.split(_track).last.strip | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment