Here's a cut-down version of the script which omits the parts that actually download the trailers but includes the parts that are causing the issue, the capturing of XML data on a per-movie basis.

You'll have to define the paths at the top of the file appropriate for your system.

SAVEPATH is where movie folders are created and movie data is saved if those lines are uncommented. SCRIPTPATH is the location of this script and the awk cleaner script (included in the attached zip file along with another copy of this main script and the XML data file).

There are some lines commented out right now. The way it is now it will grab the metadata from the XML file into three variables. The TRAILERS variable is composed of select values from the XML file separated by ";field" and then each movie is separated by ";x545hwx1" - this is done so it's easy to pull values for individual movies when looping. If you refer to the original script you can see that the last separator used to be a plain newline, but for testing purposes I've gone to something more specific.

The next variable, recordDATE contains only a single string pulled from the very top of the XML file containing the date the XML file was created.

Then we have the movieFields variable which contains ALL fields for every movie. Individual fields are not separated by special markers, but each movie is separated by "--DIVIDER--" - this is the variable I use to pull the full metadata for each movie which I'd like to save out to a proper XML file, also for each movie (the line of code to do this is below and commented out).

The movie data just mentioned is currently output to the console. If you comment out the echo line and instead enable the one above it, it will instead put the data into files, one per movie folder. You'll also have to enable the line that creates the movie name folders.

This thing will hang for me at random times running this way or running with file creation. When i first started testing today it would complete the whole thing without a problem. I must have done it like 10 times in a row to the console as well as a few times outputting to files. Then it started hanging again at random points. No code was changed during these tests.

Code:
#!/bin/bash

movieRow=0

BEXTENSION=".trailer.mov"

GET1080p=0
GETPOSTER=1
SAVEPATH="v:/Movies/zzztrailertest/"
SCRIPTPATH="d:/AppleTrailers/"


FEEDURL="d:/AppleTrailers/current_720p.xml"


TRAILERS=`xml sel --net -D -T -t -m "/records/movieinfo"\
 -v "@id" -o ";field"\
 -v "info/title" -o ";field"\
 -v "info/postdate" -o ";field"\
 -v "preview/large" -o ";field"\
 -v "poster/xlarge"\
 -o ";x545hwx1"\
 $FEEDURL`

recordDATE=`xml sel --net -D -T -t -m "/records"\
 -v "@date"\
 $FEEDURL`

movieFields=`xml sel --net -I -E utf-8 -t -m "/records/movieinfo"\
 -c "."\
 -o "--DIVIDER--"\
 $FEEDURL`


for movieCOUNTER in `seq 1 86`; do

#sleep 1


MOVIE=`echo $TRAILERS | awk -v line=$movieCOUNTER 'BEGIN { FS = ";x545hwx1" } ; { print $line }'`

MOVIEID=`echo $MOVIE | awk  'BEGIN { FS = ";field" } ; { print $1 }'`

MOVIETITLE=`echo $MOVIE | awk  'BEGIN { FS = ";field" } ; { print $2 }'`
	MOVIETITLEFILE=`echo "$MOVIETITLE" | $SCRIPTPATH/filecleaner.awk`

POSTDATE=`echo $MOVIE | awk 'BEGIN { FS = ";field" } ; { print $3 }'`

NEWPREVIEWNAME="$MOVIETITLEFILE$BEXTENSION"

POSTER=`echo $MOVIE | awk 'BEGIN { FS = ";field" } ; { print $5 }'`
	NEWPOSTERNAME="folder.jpg"

MOVIESAVEPATH="$SAVEPATH$MOVIETITLEFILE"

#mkdir "$MOVIESAVEPATH/"


selectedMovie=`echo $movieFields | awk -v movieRecord=$movieCOUNTER 'BEGIN { FS = "--DIVIDER--" } ; { print $movieRecord }'`

#echo -e "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r<records date=\"$recordDATE\">$selectedMovie</records>" >"$MOVIESAVEPATH/temp.xml"
echo -e "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r<records date=\"$recordDATE\">$selectedMovie</records>"

done


Attachments
AppleTrailers.zip (146 downloads)



Edited by hybrid8 (15/01/2009 17:50)
Edit Reason: adding attachment
_________________________
Bruno
Twisted Melon : Fine Mac OS Software