# Rename Music Files with Missing File Extensions

I've been experimenting with a couple of various music gamers lately and also saw that some (a whole lot) of my music would certainly be missing out on from the collection. It ends up that at some time, a myriad of my music documents shed their.mp3/. ogg/. flac documents expansions. I'm truthfully not exactly sure just how this took place, yet I'm certain it was something I did erroneously (or possibly I assumed it would not matter given that documents expansions are primarily aesthetic anyhow).

So I require to get these documents expansions back. I've checked into pyrenamer, yet I can not identify just how to match it to documents without an expansion and afterwards inform it to add the proper documents expansion relying on the real sort of the documents.

I've additionally considered EasyTag. Nonetheless, it additionally identifies music documents based totally on their documents expansions. So the music I intend to deal with does not also show up. Great.

Any kind of ideas on just how to do this? I absolutely do not mind some command line, I'm simply not exactly sure which devices would certainly be best and also I additionally draw at regex.

0
2019-05-18 20:50:14
Source Share

This celebration manuscript can suffice:

#! /bin/bash

find ~/Music -type f | (while read path; do
case file -i "$path" in *audio/mp3*|*audio/mpeg*) ext='.mp3' ;; *application/ogg*) ext='.ogg' ;; *flac*) ext='.flac' ;; *) continue;; # ignore unknown files esac newname="$(dirname "$path")/$(basename "$path" "$ext").$ext" if [ "$path" != "$newname" ]; then mv -v "$path" "$newname" fi done)  The manuscript makes use of file -i to read the MIME sort of a documents ; I have no FLAC documents below, so you could intend to examine what the MIME type for FLAC is by running file -i a_file.flac (and also perhaps readjusting the manuscript resource). You can add an alternative -i to mv if you intend to be asked verification prior to any kind of documents relabel. It could be an excellent suggestion to change mv -v by echo mv -v and also doing a. trial run prior to attempting the real relabels - - the echo mv will. print out the mv regulates that would certainly be implemented by the manuscript. 0 2019-05-21 03:48:12 Source Here is a celebration manuscript that relabels the documents passed to it based upon their presumed layout. It calls file to identify the layout by considering particular patterns in the first couple of bytes. file -i prints lines like /path/to/file: type/subtype where type/subtype is a MIME type. The manuscript after that links expansions to well-known kinds and also relabels the documents to have the expansion. Documents that currently have the expansion are laid off. Documents that have an unknown type are laid off. The manuscript will certainly motivate prior to overwriting a target documents. #!/bin/bash # usage: # fixmime ./{**/,}* file --mime-type "[email protected]" | while read -r line; do file=${line%:*}
type=${line##* } case$type in

#Audio
audio/x-flac) ext=flac;;
audio/mpeg) ext=mp3;;
application/ogg) ext=ogg;;

#Video
video/mp4) ext=mp4;;
video/x-flv) ext=flv;;
application/octet-stream) ext=webm;;
application/x-shockwave-flash) ext=swf;;

#Images
image/png) ext=png;;
image/jpeg) ext=jpg;;
image/gif) ext=gif;;
image/x-ico) ext=ico;;

#Text
text/plain) ext=md;; #markup your notes, even when they are plain
text/html) ext=html;;
text/x-pascal) ext=py;;
text/x-c++) ext=js;; #conflicts with .cpp, so use prefered
text/x-c) ext=scss;; #usualy it is .c
text/x-shellscript) ext=sh;;
application/pdf) ext=pdf;;

#Fonts
application/x-font-ttf) ext=ttf;;
application/vnd.ms-opentype) ext=otf;;

#Archive
application/x-gzip) ext=tar.gz;;
application/x-bzip2) ext=tar.bz;;

*) continue;;
esac
[[ $file = *.$ext ]] || mv -i -- "$file" "$file.\$ext"
done


Save the manuscript as ~/bin/rename-based-on-content-type (or whatever you like) and also make it executable (chmod +x ~/bin/rename-based-on-content-type). Pass the names of the documents you intend to relabel to the manuscript on the command line. If you have a directory site tree /path/to/music/directory that you intend to go across recursively, invoke the manuscript as

~/bin/rename-based-on-content-type /path/to/music/directory/{**/,}*

0
2019-05-21 02:18:27
Source