Command to move all mkv files up a folder


gnollo

Recommended Posts

Quote

mv: cannot stat 'AUDIO_TS': No such file or directory

mv: cannot stat 'VIDEO_TS': No such file or directory

The mv will give an error if AUDIO_TS or VIDEO_TS do not exist.  I left the error in there so you could see if either directory wasn't present.  I can suppress the error if you want.

 

Quote

rev: stdin: Invalid or incomplete multibyte or wide character

mv: cannot move 'VIDEO_TS' to '/mnt/user/unraid/dvdbackup/VIDEO_TS': Directory not empty

I believe the reason the mv failed may be because of the rev error.

I modified the script to use sed instead of rev.  It may fix the error.

 

Link to comment

I just run a search for VIDEO_TS and AUDIO_TS and DVD in the subfolders, they are all gone, so that's worked!

To double check, how do I find which folder does NOT contain

*.mkv
or
movie.xml

That will basically tell me if anything was wrong in the first place with a movie folder in the conversion or tagging process I run previously.
I think this would complete first pass, and I could add the directory to emby

Link to comment
Do you want the script to move "movie.xml" to the parent directory like the mkv file?
 
I could modify the script so that at the time of processing it checks if an mkv file exists, if not print a message.
Or I could make a separate script to check if the files exist.
I did many random checks they all seem to be there, I already run the other script, so a separate script that just checks that the two files are there and gives an error message when they are not, like the VIDEO_TS error messages, would be fantastic! Thank you so much for your help on this!

Sent from my SM-A520F using Tapatalk

Link to comment

Check for movie.xml and mkv files in each movie folder.

check_movies.sh

#!/bin/bash

movies="/mnt/user/test/movies"

process()
{
    local movieDir=$1
    
    local mkv="$(find "$movieDir" -iname '*.mkv')"
    local xml="$(find "$movieDir" -iname 'movie.xml')"

    if [ -z "$mkv" ] || [ -z "$xml" ]
    then
        printf "$movieDir\n"
        [ -z "$mkv" ] && printf "\tmkv: file not found\n"
        [ -z "$xml" ] && printf "\tmovie.xml: file not found\n"
    fi
}

ls -1d "$movies"/*/ | sed 's/\/*$//' |\
while read movie
do
    if [ -d "$movie/DVD1" ]
    then
        ls -1d "$movie"/DVD*/ | sed 's/\/*$//' |\
        while read dvd
        do
            process "$dvd"
        done
    else
        process "$movie"
    fi
done

 

Edited by JoeUnraidUser
Link to comment
Check for movie.xml and mkv files in each movie folder.
check_movies.sh
#!/bin/bashmovies="/mnt/user/test/movies"process(){   local movieDir=$1      mkv="$(find "$movieDir" -iname '*.mkv' -print -quit)"   xml="$(find "$movieDir" -iname 'movie.xml' -print -quit)"   if [ -z "$mkv" ] || [ -z "$xml" ]   then       printf "$movieDir\n"   fi      if [ -z "$mkv" ]   then       printf "\tmkv: file not found\n"   fi   if [ -z "$xml" ]   then       printf "\tmovie.xml: file not found\n"   fi}ls -1d "$movies"/*/ | sed 's/\/*$//' |\while read moviedo   if [ -d "$movie/DVD1" ]   then       ls -1d "$movie"/DVD*/ | sed 's/\/*$//' |\       while read dvd       do           process "$dvd"       done   else       process "$movie"   fidone

 

Awesome will test tonight

Sent from my SM-A520F using Tapatalk

Link to comment
  • 2 months later...
  • 3 weeks later...
On 1/17/2020 at 1:57 AM, gnollo said:

It worked indeed! Thank you for that Joe. Now I need to identify which folder in my /mnt/user/test/movies contains subfolders. Need to get rid of them as emby does not deal well with them.

 

The following script will show the subfolders for each movie.

 

 

To remove the subfolders; uncomment the following line:

#rm -rf "$dir"

to

rm -rf "$dir"

 

movies_subdirs.sh

#!/bin/bash

movies="/mnt/user/test/movies"

process()
{
    local movieDir=$1

    readarray -t dirs < <(find "$movieDir" -mindepth 1 -maxdepth 1 -type d -print 2>/dev/null)

    if [ ${#dirs[@]} != 0 ]
    then
        printf "$movieDir\n"
        
        for dir in "${dirs[@]}"
        do
            printf "$dir\n"    

            #rm -rf "$dir"
                
        done
    fi
}

ls -1d "$movies"/*/ | sed 's/\/*$//' |\
while read movie
do
    if [ -d "$movie/DVD1" ]
    then
        ls -1d "$movie"/DVD*/ | sed 's/\/*$//' |\
        while read dvd
        do
            process "$dvd"
        done
    else
        process "$movie"
    fi
done

 

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.