Results 1 to 6 of 6

Thread: move video files to another folder IF they have subtitles

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default move video files to another folder IF they have subtitles

    First of all, hello everyone! First post here, partial newbie here, hope someone will take charge of this lil problem:

    My current situation:

    I made a script that downloads automatically, on a 15 minutes basis, new video files on a local folder, from a http server I own where video files are updated constantly during the day.

    Another script checks the web for subtitles for each specific video file, and downloads the subs when they are found, giving these subtitle files the same name as the video file, but a different extension (sub, srt, etc).

    Starting situation for the new script I want to create is that I have a folder with these various video files, mostly mkv but also avi, mp4 and other extensions. Subtitle files have the same name as the original video files, but extension mostly srt, but also sometimes sub, smi, ass, etc.

    What I need is a cron-able script that checks the folder, identifies the video files according to a number of extensions we can previously decide, check if they have a subtitle associated to them, and in this case do something, like moving the file to another folder.

    I've been struggling with this issue for a couple of weeks now, I'm sure the solution is quite dumb, but my scripting experience is just too weak...

    Thanks :)

  2. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    458
    Thanks
    0
    Thanked 62 Times in 58 Posts
    Rep Power
    10

    Default

    hi,

    if I understand correctly, every subtitle file has a corresponding movie file, right ?

    sh parameter expansion can remove extension, see man <yourshell>.
    a simple iteration on subtitle files
    first to remove extension from subtitle filename into a variable
    next to move movieFile.* and subtitleFile whereever you want
    end of iteration.
    A problem clearly stated is a problem half solved.

  3. #3
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    486
    Thanks
    10
    Thanked 50 Times in 47 Posts
    Rep Power
    8

    Default

    So what have you tried yet so far ??
    Show the code, if you are facing any issue .. we will try to resolve that ..
    Rahul Patil <http://www.linuxian.com>

  4. #4
    Junior Member
    Join Date
    Aug 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Quote Originally Posted by Watael View Post
    hi,

    if I understand correctly, every subtitle file has a corresponding movie file, right ?

    sh parameter expansion can remove extension, see man <yourshell>.
    a simple iteration on subtitle files
    first to remove extension from subtitle filename into a variable
    next to move movieFile.* and subtitleFile whereever you want
    end of iteration.
    Sorry for late reply, just got back to work after summer holidays and it's been a bit hectic.

    Every subtitle file has a corresponding movie file, because subtitle files are automatically downloaded only for existing movie files, but some movie files might not have subtitles yet (because they will be released later on) and they must not be moved until the subtitle file "appears".

    This is what stops me. I haven't started to put down a concrete script yet, because I'm still stuck at thinking what the logic behind the script should be... I really don't understand how to apply a filter like "if the avi/mp4/mkv/whatever file has no srt/sub/smi/whatever associated, then leave it alone".

    I say it again, solution must be really simple but I'm a freaking noob, maximum I can do is a if then else in sh :P

  5. #5
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    486
    Thanks
    10
    Thanked 50 Times in 47 Posts
    Rep Power
    8

    Default

    at least give us output of
    Code:
    ls -lrt /path/of/file
    and let us know what should be desire output
    Rahul Patil <http://www.linuxian.com>

  6. #6
    Junior Member
    Join Date
    Aug 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    So, to give you an idea of my EXTREMELY ADVANCED shell scripting skills, here's what I wrote today. It works, but it's TERRIBLY unelegant.
    Basically it lists the subtitle files and sends the output into a txt file, then it creates avi, mkv, mp4 lists of files according to the original filenames of the subtitles, and then it moves all the content of the final list to another folder.

    Problem 1: if a subtitle exists, but not the corresponding video file, the subtitle file gets moved. It's not a big issue, since I almost never have subs in that folder without a video files to go with them, but it may happen from time to time. If problem is not solvable, I can just save my temp subs somewhere else, but as I said above, it's not an elegant solution.

    Problem 2: this script creates a theoretic list of all possible filenames with all possible video extensions (in this case mp4, mkv and avi), despite the fact that these files may or may not exist, and then tries to move the files to the destination directory. Not a biggie, since files that do not exist in source dir are just ignored when the "move" command is given, but as per above problem, this solution is not elegant too.

    Heaven would be something that sees the subtitle files, checks for corresponding filenames with certain other video extensions, creates a global filelist and moves files according to that list.

    P.S. if you see any non-standard uses of some commands below, please don't kill me. I'm on OSX 10.8.4. For example, I could not get "ls" to list files into a single column with no other details, so I used "find".

    Here it goes:

    Code:
    #remove tmp files from last execution of script
    
    rm -rf sublist*
    rm -rf filecopy.sh
    
    
    #list all subtitle files and output into a txt file
    
    
    find *.srt >> sublist.txt
    find *.smi >> sublist.txt
    find *.sub >> sublist.txt
    
    
    /usr/bin/sed -i.bak 's/ /\\ /g' sublist.txt
    
    
    #make copies of the sublist file for avi, mkv and mp4
    
    
    cp sublist.txt sublistavi.txt
    cp sublist.txt sublistmkv.txt
    cp sublist.txt sublistmp4.txt
    
    
    #replace subtitle extension from filenames with video extension, avi, mkv, mp4
    
    
    /usr/bin/sed -i.bak 's/.srt/.avi/g' /Users/XXXUSERXXX/Downloads/sublistavi.txt
    /usr/bin/sed -i.bak 's/.sub/.avi/g' /Users/XXXUSERXXX/Downloads/sublistavi.txt
    /usr/bin/sed -i.bak 's/.smi/.avi/g' /Users/XXXUSERXXX/Downloads/sublistavi.txt
    
    
    /usr/bin/sed -i.bak 's/.srt/.mkv/g' /Users/XXXUSERXXX/Downloads/sublistmkv.txt
    /usr/bin/sed -i.bak 's/.sub/.mkv/g' /Users/XXXUSERXXX/Downloads/sublistmkv.txt
    /usr/bin/sed -i.bak 's/.smi/.mkv/g' /Users/XXXUSERXXX/Downloads/sublistmkv.txt
    
    
    /usr/bin/sed -i.bak 's/.srt/.mp4/g' /Users/XXXUSERXXX/Downloads/sublistmp4.txt
    /usr/bin/sed -i.bak 's/.sub/.mp4/g' /Users/XXXUSERXXX/Downloads/sublistmp4.txt
    /usr/bin/sed -i.bak 's/.smi/.mp4/g' /Users/XXXUSERXXX/Downloads/sublistmp4.txt
    
    
    #create shell script to move video and subtitle files
    
    
    cat sublist.txt sublistavi.txt sublistmkv.txt sublistmp4.txt > sublist2.txt
    
    
    /bin/cat /Users/XXXUSERXXX/Downloads/sublist2.txt  | while read line; do /bin/echo "mv /Users/XXXUSERXXX/Downloads/""$line" "/Users/XXXUSERXXX/Downloads/to.sort/" ; done>/Users/XXXUSERXXX/Downloads/sublist3.txt
    
    
    /usr/bin/sed -i.bak 's/ /\\ /g' /Users/XXXUSERXXX/Downloads/sublist3.txt
    
    
    /usr/bin/sed -i.bak 's/\\ \/Users/ \/Users/g' /Users/XXXUSERXXX/Downloads/sublist3.txt
    
    
    mv sublist3.txt filecopy.sh
    chmod +x filecopy.sh
    
    
    #execute shell script to move video and subtitle files
    
    
    ./filecopy.sh
    Last edited by godbacon; 4th September 2013 at 04:24 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. creating ZIP files and move it another folder
    By tjbgopal in forum Linux software
    Replies: 3
    Last Post: 11th December 2013, 04:49 PM
  2. move all except one or more files in Linux
    By forumbala88 in forum CentOS / RHEL / Fedora
    Replies: 1
    Last Post: 26th April 2013, 02:53 PM
  3. Video player to play .wmv video files in ubuntu Linux 11.10
    By chandrasekhar439 in forum Ubuntu / Debian
    Replies: 1
    Last Post: 22nd November 2011, 06:38 PM
  4. Linux play or extract .bin/.cue video files
    By chandrasekhar439 in forum CentOS / RHEL / Fedora
    Replies: 1
    Last Post: 24th September 2011, 05:26 PM
  5. Replies: 1
    Last Post: 25th October 2007, 02:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •