Script to move all files under the movie folder

Come up with a useful post-processing script? Share it here!
Post Reply
mrgoolie
Newbie
Newbie
Posts: 4
Joined: December 23rd, 2013, 12:30 pm

Script to move all files under the movie folder

Post by mrgoolie »

Hi all,

I've found a release group that posts good movies but when they are automaticly extracted via sabnzbd it looks like:
\\nas\movies\The Kings of Summer\TKoS1318pBRDSHQBRNLS-NLU002\The Kings of Summer (2013) 1080p BluRay DTS HQ-BR NL Subs.mkv
I want it like:
\\nas\movies\The Kings of Summer\The Kings of Summer (2013) 1080p BluRay DTS HQ-BR NL Subs.mkv

So in fact I need to move the .mkv file a folder up.

Most of my other downloads are extracted the correct way.

The reason why I ask this is because my xbmc doesn't find folder/folder/movie.mkv but only folder/movie.mkv

Is this possible via a script?
User avatar
sander
Release Testers
Release Testers
Posts: 9261
Joined: January 22nd, 2008, 2:22 pm

Re: Script to move all files under the movie folder

Post by sander »

Yes, this is possible via a script.

pseudo-code:

Code: Select all

cd /nas/movies/The Kings of Summer/
mv */*.mkv .
The above is for Linux / *IX / OSX. I don't know about Windows.

EDIT: manual example:

Code: Select all

sander@flappie:~$ cd Movie1/
sander@flappie:~/Movie1$ ls -al
total 12
drwxr-xr-x  3 sander sander 4096 dec 23 19:37 .
drwxr-xr-x 65 sander sander 4096 dec 23 19:37 ..
drwxr-xr-x  2 sander sander 4096 dec 23 19:37 some-sub-dir
sander@flappie:~/Movie1$ 
sander@flappie:~/Movie1$ 
sander@flappie:~/Movie1$ mv */*.mkv .
sander@flappie:~/Movie1$ 
sander@flappie:~/Movie1$ ls -al
total 12
drwxr-xr-x  3 sander sander 4096 dec 23 19:38 .
drwxr-xr-x 65 sander sander 4096 dec 23 19:37 ..
-rw-r--r--  1 sander sander    0 dec 23 19:37 some-movie.mkv
drwxr-xr-x  2 sander sander 4096 dec 23 19:38 some-sub-dir
sander@flappie:~/Movie1$ 
mrgoolie
Newbie
Newbie
Posts: 4
Joined: December 23rd, 2013, 12:30 pm

Re: Script to move all files under the movie folder

Post by mrgoolie »

In fact i'm looking for a code that is usable for every movie I download.
for example:
\\nas\movies\test\test\test.mkv -> \\nas\movies\test\test.mkv

but also: \\nas\movies\test\test.mkv -> \\nas\movies\test\test.mkv (stays the same)

So maybe it is possible to build a check in the script?
sander wrote:Yes, this is possible via a script.

pseudo-code:

Code: Select all

cd /nas/movies/The Kings of Summer/
mv */*.mkv .
The above is for Linux / *IX / OSX. I don't know about Windows.

EDIT: manual example:

Code: Select all

sander@flappie:~$ cd Movie1/
sander@flappie:~/Movie1$ ls -al
total 12
drwxr-xr-x  3 sander sander 4096 dec 23 19:37 .
drwxr-xr-x 65 sander sander 4096 dec 23 19:37 ..
drwxr-xr-x  2 sander sander 4096 dec 23 19:37 some-sub-dir
sander@flappie:~/Movie1$ 
sander@flappie:~/Movie1$ 
sander@flappie:~/Movie1$ mv */*.mkv .
sander@flappie:~/Movie1$ 
sander@flappie:~/Movie1$ ls -al
total 12
drwxr-xr-x  3 sander sander 4096 dec 23 19:38 .
drwxr-xr-x 65 sander sander 4096 dec 23 19:37 ..
-rw-r--r--  1 sander sander    0 dec 23 19:37 some-movie.mkv
drwxr-xr-x  2 sander sander 4096 dec 23 19:38 some-sub-dir
sander@flappie:~/Movie1$ 
User avatar
sander
Release Testers
Release Testers
Posts: 9261
Joined: January 22nd, 2008, 2:22 pm

Re: Script to move all files under the movie folder

Post by sander »

The pseudo-code I gave you does take care of that. You can try that for yourself.
mrgoolie
Newbie
Newbie
Posts: 4
Joined: December 23rd, 2013, 12:30 pm

Re: Script to move all files under the movie folder

Post by mrgoolie »

But the code

Code: Select all

cd /nas/movies/The Kings of Summer/
mv */*.mkv 
isn't applicable for every movie :)
Ectholian
Newbie
Newbie
Posts: 1
Joined: January 9th, 2014, 2:20 am

Re: Script to move all files under the movie folder

Post by Ectholian »

find "$1" -mindepth 2 -type f -exec mv "{}" "$1" \;

$1 is the full path to the directory where the movie is downloaded (the folder where you want your .mkv)
-mindepth 2 is needed so the command don't execute for the current dir, which would make an endless loop
-type f takes care of only files
and the exec just does a mv 'foundfile' 'moviedirectory'

Something like this should work.

Edit: this one should be a little more efficient, since it only uses one single mv call:
find "$1" -mindepth 2 -type f -exec mv -t "$1" "{}" +

My script i use does a couple things:
- move all files to the main directory
- delete all subdirectories (which should contain no files anymore)
- delete all non-movie files (*.jpg, url, html etc. etc.)
- append a ' - DVD', ' - Bluray' or a ' - ISO' to the name of the folder if it contains a dvd, bluray or iso
- clean xbmc library
- scan xbmc library
mrgoolie
Newbie
Newbie
Posts: 4
Joined: December 23rd, 2013, 12:30 pm

Re: Script to move all files under the movie folder

Post by mrgoolie »

Can you share your script? :)
Post Reply