I'm re-aligning my media on my server due to a change in content delivery software. The new program wants some stuff different - the key piece being the title of a movie should be followed by a space then the year in which it was released parenthetically. I.e., what previously was "13 Assassins" should now be "13 Assassins (2011)"
These movies are stored in individual subfolders to allow use of poster and fan art .jpg's as icon and background. I was able to extract the year for each movie from the movie info file (no longer being used by the new software) and put it into a file names year (containing the four number year and nothing else) within the folder and use that file to rename all the subfolders like this:
OIFS="$IFS"; IFS=$'\n'; for subdir in *; do mv $subdir $subdir" (`cat $subdir/year`)" ; done; IFS="$OIFS";
The $IFS manipulation was done to allow for names with spaces in them. Not all the movies had info files but that just created an empty year file so the result would look like "13 Assassins ()" which is fine - I can manually fix those few out of the 400+ folders/movies.
Now on to renaming the movies. Here's the catch: They are of different file types: mp4, m4v, avi, mkv, and maybe a couple others. I want to do something similar to the above for the files. I would accept a solution that requires it to be run once for each type, but a really neat and tidy single run would be very cool. Also, there are other files in most of the subfolders like poster.jpg, fanart.jpg, and subtitles of various formats so all other types - with or without extensions - must be ignored.
Here's an example folder and it's contents:
/media/videos/Movies
Some will have an additional nested folder named /SRT with subtitles and others have additional fun movie stuff in them.
Any ideas?
These movies are stored in individual subfolders to allow use of poster and fan art .jpg's as icon and background. I was able to extract the year for each movie from the movie info file (no longer being used by the new software) and put it into a file names year (containing the four number year and nothing else) within the folder and use that file to rename all the subfolders like this:
OIFS="$IFS"; IFS=$'\n'; for subdir in *; do mv $subdir $subdir" (`cat $subdir/year`)" ; done; IFS="$OIFS";
The $IFS manipulation was done to allow for names with spaces in them. Not all the movies had info files but that just created an empty year file so the result would look like "13 Assassins ()" which is fine - I can manually fix those few out of the 400+ folders/movies.
Now on to renaming the movies. Here's the catch: They are of different file types: mp4, m4v, avi, mkv, and maybe a couple others. I want to do something similar to the above for the files. I would accept a solution that requires it to be run once for each type, but a really neat and tidy single run would be very cool. Also, there are other files in most of the subfolders like poster.jpg, fanart.jpg, and subtitles of various formats so all other types - with or without extensions - must be ignored.
Here's an example folder and it's contents:
/media/videos/Movies
/13 Assassins (2011)
13 Assassins.mp4
poster.jpg
fanart.jpg
year
poster.jpg
fanart.jpg
year
Some will have an additional nested folder named /SRT with subtitles and others have additional fun movie stuff in them.
Any ideas?
Comment