LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-13-2008, 01:01 PM   #1
frater
Member
 
Registered: Jul 2008
Posts: 121

Rep: Reputation: 23
Script to find VIDEO_TS.IFO and create an ISO


I would like to write a cronjob that will parse the tree of a download directory for the file "VIDEO_TS.IFO" and if it finds one it should make an ISO out of it written to a specific directory.
Sometimes the directory in which VIDEO_TS.IFO resides is called VIDEO_TS (which is valid) but sometimes it's the name of the DVD. The name of the ISO should be <dvdname>.ISO

The file structure could be like this.

/downloaddir/DVD/Some Like it Hot/VIDEO_TS/VIDEO_TS.IFO
/downloaddir/How to Marry a Millionaire/VIDEO_TS.IFO

In the end I want:

/DVD/Some Like it Hot.ISO
/DVD/How to Marry a Millionaire.ISO

and my original files deleted.

Can someone point me into the right direction, so I can make a decent cronjob out if it?

My problem is in getting the automated process right with the appropriate checks. the mkisofs command itself is the least of my problem. It should also check if the files are not being written to at the time the cronjob is running.
 
Old 07-13-2008, 11:28 PM   #2
drewbug01
Member
 
Registered: Aug 2006
Location: Detroit!
Distribution: Ubuntu 7.04
Posts: 182

Rep: Reputation: 30
possibly something like this?
Code:
#!/bin/bash

for ifo_file in /downloaddir/DVD/*/VIDEO_TS/VIDEO_TS.IFO
do
	mkisofs $ifo_file && rm $ifo_file ## blah, i dont know the syntax to convert ifo to iso
done

for ifo_file in /downloaddir/*/VIDEO_TS.IFO
do
	mkisofs $ifo_file && rm $ifo_file ## blah, dont know syntax for mkisofs
done

mv /downloaddir/DVD/*/VIDEO_TS/*.ISO /downloaddir/
mv /downloaddir/*/*.ISO /downloaddir/
rm -Rf /downloaddir/DVD/*
mv /downloaddir/*.ISO /downloaddir/DVD/

As far as checking for the files being written to.... the only thing i can think of is to check for the process that downloads them... to see if its running....

Then you could put something like this right at the start:
Code:
if [ `ps aux | awk '{print $11}' | grep PROCESS` ]
	then exit 0
fi
Substituting PROCESS for whatever process actually downloads....

I would carefully test this bad boy though. :-P My scripting is TERRIBLE.

BTW, a great resource for scripting is : http://www.tldp.org/LDP/abs/html/

--drew
 
Old 07-14-2008, 11:36 AM   #3
frater
Member
 
Registered: Jul 2008
Posts: 121

Original Poster
Rep: Reputation: 23
Hi,

Thanks....
I just peeked in here to see if somebody replied.
However.. In the mean time I think I created my script, so I will post it here..
Maybe someone can make a comment...
About testing if it is being written to, I was thinking about lsof.

But probably it isn't necessary at all. The script that's putting it there has already completed all filewriting and puts it there using a "mv"


#!/bin/sh

DVD_PATH=/shares/internal/PUBLIC/DVD

if [ -z "$1" ] ; then
DOWNLOAD_PATH=/shares/internal/PUBLIC/Torrent/NZB/usenet
else
DOWNLOAD_PATH="`dirname $1`/`basename $1`"
fi

if [ ! -d "$DOWNLOAD_PATH" ]; then
echo "The directory $DOWNLOAD_PATH does not exist!"
exit
fi

#
#
find $DOWNLOAD_PATH -name VIDEO_TS.IFO |
while read f ; do

TS_DIR=`dirname "$f"`

cd "$TS_DIR"

if [ -f "../VIDEO_TS/VIDEO_TS.IFO" ]; then
cd ..
else
mkdir VIDEO_TS
mv * VIDEO_TS
fi
if [ ! -d "AUDIO_TS" ]; then
mkdir AUDIO_TS
fi

thisdir=`pwd`
isofile="$DVD_PATH/${thisdir##/*/}.ISO"

if [ ! -f "$isofile" ]; then
mkisofs -dvd-video -o "$isofile" .
else
echo "$isofile already exists"
fi
done

Last edited by frater; 07-14-2008 at 11:58 AM.
 
Old 07-14-2008, 08:39 PM   #4
drewbug01
Member
 
Registered: Aug 2006
Location: Detroit!
Distribution: Ubuntu 7.04
Posts: 182

Rep: Reputation: 30
Looks more impressive than mine, thats for sure
 
Old 07-16-2008, 02:59 PM   #5
frater
Member
 
Registered: Jul 2008
Posts: 121

Original Poster
Rep: Reputation: 23
I changed the script some more. Besides creating ISO's it now also looks for ISO's.
It also cleans up the name of the files.
If someone knows how to improve it I'm interested.


cat /usr/bin/mkdvd
#!/bin/sh

DVD_PATH=/shares/internal/PUBLIC/DVD

if [ -z "$1" ] ; then
DOWNLOAD_PATH=/shares/internal/PUBLIC/Torrent/NZB/usenet
else
DOWNLOAD_PATH="`dirname $1`/`basename $1`"
fi

if [ ! -d "$DOWNLOAD_PATH" ]; then
logger -s "The directory $DOWNLOAD_PATH does not exist!"
exit
fi

#
#
find $DOWNLOAD_PATH -name VIDEO_TS.IFO |
while read f ; do

TS_DIR=`dirname "$f"`
cd "$TS_DIR"

if [ -f "../VIDEO_TS/VIDEO_TS.IFO" ]; then
cd ..
else
mkdir VIDEO_TS
mv * VIDEO_TS
fi
if [ ! -d "AUDIO_TS" ]; then
mkdir AUDIO_TS
fi

chmod -R 400 .
chown -R www-data:www-data .
chmod 500 AUDIO_TS
chmod 500 VIDEO_TS

thisdir=`pwd`
isofile="${thisdir##/*/}"

# remove brackets and other characters
isofile=`echo "$isofile" | tr -d '{}(),\!' | tr '.' ' ' | tr '_' ' ' | tr '[a-z]' '[A-Z]'`
isofile=`echo "$isofile" | sed 's/XXX//g' | sed 's/DVDRIP//g' | sed 's/DVD//g' | sed 's/WWW.*.COM//g' | sed 's/NTSC//g' | sed 's/PAL//g' | sed 's/AC3//g' | sed 's/DTS//g' | tr -s ' '`
volname=`echo "$isofile" | tr ' ' '_' | tr -d "[]\'" | cut -b-31`

# Turn spaces into dots and turn into lowercase with capitalized first letters.
isofile=`echo "$isofile" | sed 's/\<\(.\)\([^ ]*\)/\u\1\L\2/g'`
# Remove some more words
isofile=`echo "$isofile" | sed 's/ Rip//g' | sed 's/ Nl//g' | sed 's/200[0-9]//g'`
# Change words into complete lowercase as they look awkward otherwise.
isofile=`echo "$isofile" | sed 's/ My/ my/g' | sed 's/ In / in /g' | sed 's/200[0-9]//g' | sed 's/ Or / or /g' | sed 's/ And / and /g'`
isofile=`echo "$isofile" | sed 's/ A / a /g' | sed 's/ An / an /g' | sed 's/ Of / of /g' | sed 's/ Up / up /g' | sed 's/ The / the /g' `
isofile=`echo "$isofile" | sed 's/Cd/CD/g' | sed 's/ Over / over /g' | sed 's/ On / on /g' | sed 's/ Is / is /g' | sed 's/ As / as /g' | sed 's/ It / it /g'`
# Turn spaces into dots, remove repeating dots and remove square brackets with nothing in between.
isofile=`echo "$isofile.iso" | tr ' ' '.' | tr -s '.' | sed 's/\[\]//g'`
isopathfile="$DVD_PATH/$isofile"

if [ ! -f "$isopathfile" ]; then
logger "Creating $isofile in $DVD_PATH"
nice mkisofs -dvd-video -udf -o "$isopathfile" -A "" -sysid "" -V "$volname" .
else
logger -s "$isofile already exists"
fi
done

minsize="4000000000"

logger "Searching for ISO-files in $DOWNLOAD_PATH to move them to $DVD_PATH"

find $DOWNLOAD_PATH -iname \*.iso -type f |
while read f ; do
TS_DIR=`dirname "$f"`
cd "$TS_DIR"
sizeiso=`stat -c%s "$f"`
if test $sizeiso -gt $minsize ; then

isdvd=`isoinfo -l -i "$f" | grep -il "VIDEO_TS.IFO"`
if [ -n "$isdvd" ]; then
isofile=`basename "$f"`
orgfile="$isofile"
isofile=`echo "$isofile" | tr '[a-z]' '[A-Z]' | sed 's/.ISO//g' | tr -d '{}(),\!' | tr '.' ' ' | tr '_' ' '`
isofile=`echo "$isofile" | sed 's/XXX//g' | sed 's/DVDRIP//g' | sed 's/DVD//g' | sed 's/WWW.*.COM//g' | sed 's/NTSC//g' | sed 's/PAL//g' | sed 's/AC3//g' | sed 's/DTS//g' | tr -s ' '`

# Turn spaces into dots and turn into lowercase with capitalized first letters.
isofile=`echo "$isofile" | sed 's/\<\(.\)\([^ ]*\)/\u\1\L\2/g'`
# Remove some more words
isofile=`echo "$isofile" | sed 's/ Rip//g' | sed 's/ Nl//g' | sed 's/200[0-9]//g'`
# Change words into complete lowercase as they look awkward otherwise.
isofile=`echo "$isofile" | sed 's/ My/ my/g' | sed 's/ In / in /g' | sed 's/200[0-9]//g' | sed 's/ Or / or /g' | sed 's/ And / and /g'`
isofile=`echo "$isofile" | sed 's/ A / a /g' | sed 's/ An / an /g' | sed 's/ Of / of /g' | sed 's/ Up / up /g' | sed 's/ The / the /g' `
isofile=`echo "$isofile" | sed 's/Cd/CD/g' | sed 's/ Over / over /g' | sed 's/ On / on /g' | sed 's/ Is / is /g' | sed 's/ As / as /g' | sed 's/ It / it /g'`
# Turn spaces into dots, remove repeating dots and remove square brackets with nothing in between.
isofile=`echo "$isofile.iso" | tr ' ' '.' | tr -s '.' | sed 's/\[\]//g'`

isopathfile="$DVD_PATH/$isofile"

if [ ! -f "$isopathfile" ]; then
logger -s "Moving $f to $isopathfile"
if [ ! "$orgfile" == "$isofile" ]; then
logger -s "I renamed $orgfile to $isofile for better reading"
fi

mv "$f" "$isopathfile"
chmod 400 "$isopathfile"
chown www-data:www-data "$isopathfile"

fi
fi
fi
done
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Invoke the VIDEO_TS from the command line using mplayer lothario Linux - Software 5 12-13-2012 11:33 PM
Bash Script Help - Trying to create a variable inside script when run. webaccounts Linux - Newbie 1 06-09-2008 02:40 PM
How to create CD ISO from Fedora DVD ISO amjadakmal Fedora 2 05-24-2006 01:19 AM
DVD:Rip doesn't create ifo files The_fuzzy_cow Linux - Software 0 12-04-2004 12:50 AM
ogle, xine ... whatever - can't handle VIDEO_TS.VOB neo77777 Linux - Newbie 4 06-30-2002 06:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration