gnollo Posted September 22, 2019 Share Posted September 22, 2019 Hi there, Just finished converting my 1000+ old dvds to mkvs with makemkv, it placed each file in the VIDEO_TS folder. I would like to find a command that - moves up each mkv to the parent folder Once that is done I want to backup the VIDEO_TS folders to a backup folder retaining the parent folder name. Basically I want to separate the two, so I can add to emby the folders containing the MKV files. Each parent folder also contains the xml file which emby uses to identify the movie, I'd like to keep that too. Thank you guys for your help in advance! Quote Link to comment
JoeUnraidUser Posted September 22, 2019 Share Posted September 22, 2019 (edited) Here is a script that should do what you need. Set "movies" and "backup" to your folders. move_movies.sh #!/bin/bash movies="/mnt/user/test/movies" backup="/mnt/user/test/backup" process() { local movieDir=$1 local backupDir=$2 pushd "$movieDir" >/dev/null find ./ -iname "*.mkv" -exec mv -f {} . \; mkdir -p "$backupDir" mv -f AUDIO_TS VIDEO_TS "$backupDir" popd >/dev/null } ls -1d "$movies"/*/ | sed 's/\/*$//' |\ while read movie do name="$(sed 's/.*\///g' <<< $movie)" back="$backup/$name" printf "$name\n" if [ -d "$movie/DVD1" ] then ls -1d "$movie"/DVD*/ | sed 's/\/*$//' |\ while read dvd do num="$(sed 's/.*\///g' <<< $dvd)" process "$dvd" "$back/$num" done else process "$movie" "$back" fi done Edited September 25, 2019 by JoeUnraidUser Quote Link to comment
gnollo Posted September 22, 2019 Author Share Posted September 22, 2019 Thank you Joe! I checked one more time and it is slightly more complex than what I stated. The program created an additional folder in each VIDEO_TS file, which adds underscores if the folder name has multiple words in it. Examples: \\tower\unraid\dvds\forrest gump\VIDEO_TS\FORREST_GUMP \\tower\unraid\dvds\everything you wanted to ask about sex\VIDEO_TS\EVERYTHING_YOU_WANTED_TO_ASK_ABOUT_SEX Quote Link to comment
JoeUnraidUser Posted September 22, 2019 Share Posted September 22, 2019 (edited) On 9/22/2019 at 6:51 PM, gnollo said: Thank you Joe! I checked one more time and it is slightly more complex than what I stated. The program created an additional folder in each VIDEO_TS file, which adds underscores if the folder name has multiple words in it. Examples: \\tower\unraid\dvds\forrest gump\VIDEO_TS\FORREST_GUMP \\tower\unraid\dvds\everything you wanted to ask about sex\VIDEO_TS\EVERYTHING_YOU_WANTED_TO_ASK_ABOUT_SEX I modified the script to move "mkv" files from anywhere under the movie folder. Edited September 25, 2019 by JoeUnraidUser Quote Link to comment
gnollo Posted September 23, 2019 Author Share Posted September 23, 2019 I've never run a script on unraid before, how do I do that (I mostly still a windows guy)? Quote Link to comment
JoeUnraidUser Posted September 23, 2019 Share Posted September 23, 2019 (edited) 23 hours ago, gnollo said: I've never run a script on unraid before, how do I do that (I mostly still a windows guy)? Install the "CA User Scripts" app. Go to the settings tab and click on the "User Scripts" icon. Click on "ADD NEW SCRIPT". Give the script a name. Click on the name of the script. Select "Edit Script". Paste your script and make any changes. Hit "SAVE CHANGES". To the right of the name click "RUN SCRIPT". Edit: I would test it first on a couple movies. For example: test ├── backup └── movies ├── everything you wanted to ask about sex └── forrest gump Edited September 24, 2019 by JoeUnraidUser Quote Link to comment
gnollo Posted September 23, 2019 Author Share Posted September 23, 2019 Ok, thank you again Joe, I am all set. How do I know that the script will not affect any other folder (containing another 3500 movies) than the one where all the DVDs are set? I moved them to a different location and left a few behind in the DVD folder, to perform a test run. Quote Link to comment
JoeUnraidUser Posted September 23, 2019 Share Posted September 23, 2019 (edited) 52 minutes ago, gnollo said: Ok, thank you again Joe, I am all set. How do I know that the script will not affect any other folder (containing another 3500 movies) than the one where all the DVDs are set? I moved them to a different location and left a few behind in the DVD folder, to perform a test run. It will only affect the folders under the folders you define with the variables "movies" and "backup" Edited September 23, 2019 by JoeUnraidUser Quote Link to comment
gnollo Posted September 23, 2019 Author Share Posted September 23, 2019 So if I create these folders \\tower\test \\tower\test\movies \\tower\test\backup drop some test dvds in the movies folder, I can run the script to test it? Quote Link to comment
JoeUnraidUser Posted September 24, 2019 Share Posted September 24, 2019 (edited) On 9/23/2019 at 6:57 PM, gnollo said: So if I create these folders \\tower\test \\tower\test\movies \\tower\test\backup drop some test dvds in the movies folder, I can run the script to test it? Yes. Note: 1. On Linux, slash / is used for folders instead of the Windows backslash \ 2. On Unraid, the share \\tower\test is represented on Linux as /mnt/user/test 3. Linux folder names are case sensitive. So your folder names in Linux should look like this: movies="/mnt/user/test/movies" backup="/mnt/user/test/backup" Edited September 25, 2019 by JoeUnraidUser Quote Link to comment
gnollo Posted September 24, 2019 Author Share Posted September 24, 2019 Ok, this is the message that appeared during the run. Script location: /tmp/user.scripts/tmpScripts/mkv dvd fixer/script Note that closing this window will abort the execution of this script CATCH_AND_RELEASE Cary Grant, A Class Apart casino royale casino casshern castaway catch me if you can mv: cannot stat 'VIDEO_TS': No such file or directory Quote Link to comment
JoeUnraidUser Posted September 24, 2019 Share Posted September 24, 2019 That looks good except it didn't see a VIDEO_TS folder under "catch me if you can". Was there a folder VIDEO_TS folder under "catch me if you can"? Otherwise how did all the other movies work out? Quote Link to comment
gnollo Posted September 24, 2019 Author Share Posted September 24, 2019 Worked perfectly. One of the folders didn't have a VIDEO_TS folder, which is why it gave the error message. One last thing would be to also move across the AUDIO_TS folder? You are an absolute gem Joe this is going to save me a ton of time! And if anything goes wrong I can always fix it quickly as I have the original files in the backup folder! This is ace! Quote Link to comment
JoeUnraidUser Posted September 24, 2019 Share Posted September 24, 2019 4 minutes ago, gnollo said: Worked perfectly. One of the folders didn't have a VIDEO_TS folder, which is why it gave the error message. One last thing would be to also move across the AUDIO_TS folder? You are an absolute gem Joe this is going to save me a ton of time! And if anything goes wrong I can always fix it quickly as I have the original files in the backup folder! This is ace! I changed the script so it also moves AUDIO_TS to the backup. Quote Link to comment
gnollo Posted September 24, 2019 Author Share Posted September 24, 2019 run it on the same folders Script location: /tmp/user.scripts/tmpScripts/mkv dvd fixer/script Note that closing this window will abort the execution of this script ls: cannot access '/mnt/user/test/movies/*/': No such file or directory Quote Link to comment
JoeUnraidUser Posted September 24, 2019 Share Posted September 24, 2019 1 minute ago, gnollo said: run it on the same folders Script location: /tmp/user.scripts/tmpScripts/mkv dvd fixer/script Note that closing this window will abort the execution of this script ls: cannot access '/mnt/user/test/movies/*/': No such file or directory Are your movies in \\tower\test\movies all lowercase? Quote Link to comment
gnollo Posted September 24, 2019 Author Share Posted September 24, 2019 Also noticed that in one of the folders I had two subfolders (DVD1 and DVD2). The script seems to have copied the two mkv files over each other so I only have one mkv file in that specific movie folder. No biggie, is there is a way to identify which folders have subfolders once the merge is done and I can rectify that manually by recreating the missing mkv. Quote Link to comment
gnollo Posted September 24, 2019 Author Share Posted September 24, 2019 test lowercase Backup and Movies are Capital Quote Link to comment
JoeUnraidUser Posted September 24, 2019 Share Posted September 24, 2019 (edited) 4 minutes ago, gnollo said: test lowercase Backup and Movies are Capital I changed the folders to be all lowercase to match up with \\tower\test\movies \\tower\test\backup Can you change the folders to lowercase or should I change the script back? Edited September 24, 2019 by JoeUnraidUser Quote Link to comment
gnollo Posted September 24, 2019 Author Share Posted September 24, 2019 I can change the script to accommodate for DVD# subfolders. It will take another day to make the changes. What is the structure under the DVD# folders. For example, does it have a VIDEO_TS and AUDIO_TS under DVD1?No need, it will only be a handful, I'll do a search for dvd in the folders adds identify which have subfolders, and fix those first manually moving the mkv files.Sent from my SM-A520F using Tapatalk Quote Link to comment
gnollo Posted September 24, 2019 Author Share Posted September 24, 2019 I changed the folders to be all lowercase to match up with \\tower\test\movies \\tower\test\backup Can you change the folders to lowercase or should I change the script back?I'll change the folders to lowercase when I'm back from work and testSent from my SM-A520F using Tapatalk Quote Link to comment
JoeUnraidUser Posted September 24, 2019 Share Posted September 24, 2019 (edited) Too late. I already changed the script to accommodate for DVD# subfolders. It assumes the structure under each DVD# folder contains VIDEO_TS and AUDIO_TS. Edited September 24, 2019 by JoeUnraidUser Quote Link to comment
gnollo Posted September 24, 2019 Author Share Posted September 24, 2019 Too late. I already changed the script to accommodate for DVD# subfolders. It assumes the structure under each DVD# folder contains VIDEO_TS and AUDIO_TS.Fab. I'll test that too!Sent from my SM-A520F using Tapatalk Quote Link to comment
gnollo Posted September 24, 2019 Author Share Posted September 24, 2019 Run it on the folder, went through all a to z and completed some of the error messages mv: cannot stat 'AUDIO_TS': No such file or directory rev: stdin: Invalid or incomplete multibyte or wide character mv: cannot move 'VIDEO_TS' to '/mnt/user/unraid/dvdbackup/VIDEO_TS': Directory not empty mv: './Charlie And The Chocolate Factory-1.mkv' and './Charlie And The Chocolate Factory-1.mkv' are the same file mv: cannot stat 'VIDEO_TS': No such file or directory I will investigate them one by one tomorrow Quote Link to comment
gnollo Posted September 24, 2019 Author Share Posted September 24, 2019 mv: './Charlie And The Chocolate Factory-1.mkv' and './Charlie And The Chocolate Factory-1.mkv' are the same file I think this happened when the mkv was already in the root of the movie folder as I already manually moved it there (and removed the video ts folder) Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.