Find the answer to your Linux question:
Results 1 to 2 of 2
From time to time, I browsed Stage6 to watch some videos but what always bothered me was that I was unable to select only those videos I was interested in. ...
  1. #1
    Just Joined!
    Join Date
    Nov 2004
    Posts
    18

    Post Bash script: create your personal video list with videos from Stage6

    From time to time, I browsed Stage6 to watch some videos but what always bothered me was that I was unable to select only those videos I was interested in.

    E.g. if you want to find only newly added music videos you'll have to sort the available videos by date and then look through them page after page. When Stage6 wasn't that popular it wasn't a problem 'cause there weren't that many videos. Now too many videos are added in a day or week to find something without spending too much time searching for it.

    Therefore I wrote the script called st6v which can function as a personal filter for the Stage6 content and offers some useful options.

    Code:
    #!/bin/sh
    # 
    # Script name: st6v
    # -----------------
    #
    # Abstract:
    # ---------
    # This script creates a HTML page with selected videos from Stage6 
    # (http://www.stage6.com/videos/). 
    #
    # Description:
    # ------------
    # It functions as a filter for all available videos: they can be selected 
    # by length, order (rating, hotness, quality, length, date) and position 
    # within the current Stage6 video list.
    #
    # Changelog: 
    # --------
    # Version 0.1 initial release (2007-12-10) 
    #
    #
    # Copyright (C) 2007 patch_linams@yahoo.com
    #
    # Permission is hereby granted, free of charge, to any person obtaining 
    # a copy of this software (the "Software"), to deal in the Software 
    # without restriction, including without limitation the rights to use, 
    # copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
    # of the Software, and to permit persons to whom the Software is furnished 
    # to do so, subject to the following conditions:
    #
    # The above copyright notice and this permission notice shall be included in 
    # all copies or substantial portions of the Software. 
    #
    # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED 
    # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
    # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
    # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY 
    # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ARISING 
    # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE.
    #
    
    # switches (bold and colors)
    BLD="\033[1m"
    RED="\033[31m"
    BLU="\033[34m"
    END="\033[0m"
    
    # script name
    SCRIPT="${0##*/}"
    
    # needed programs
    PGS="wget cat sed awk tr"
    
    # minimal video length in minutes
    declare -i MIN_VL=0
    
    # maximum video length in minutes (-1 for any video length)
    declare -i MAX_VL=-1
    
    # process videos of all time (y) or the last two weeks (n)
    ALLTIME="n"
    
    # period of time (the last two weeks or all time)
    test "$ALLTIME" = "n" && PERIOD="the last two weeks" ||  
    test "$ALLTIME" = "y" && PERIOD="all time"
    
    # number of pages to process (-1 for all)
    declare -i PAGES=-1
    
    # number of pages to skip
    declare -i SKIP=0
    
    # order by which videos are selected
    # (r-ating, h-otness, q-uality, l-ength, d-ate)
    ORD="d"
    
    # created HTML file with selected videos
    VLIST="/tmp/$SCRIPT.html"
    
    # how many videos in a row
    declare -i COUNT=3
    
    # how many videos already selected
    declare -i VCOUNT=0
    
    TMP=$(mktemp $VLIST.XXXXXXXXXX) || $TMP="$VLIST.$$"
    
    NO_OPTIONS="\n When $SCRIPT is called without any options it will process ALL\n
                Stage6 videos of $PERIOD. This can take a LONG time\n
                depending on your computer and your internet connection.\n
                Do you wish to proceed (y|n) [default: n]?\033[1C"
    
    WG="wget -q -k --read-timeout=80 -t inf -O $TMP"
    URL="http://www.stage6.com/videos/order:"
    
    BRD="0"
    BCOL="#FFFFFF"
    HEADER="<html><head><meta http-equiv=\"Content-Type\" 
            content=\"text/html; charset=utf-8\" />
            <title>Stage6 - Personal Video List</title></head><body><center>
            <table border=\"$BRD\" cellspacing=\"1\" cellpadding=\"0.5\"
            bgcolor=\"$BCOL\" align=\"center\"><tr><td>
            <table border=\"1\" cellspacing=\"1\" cellpadding=\"0.5\" 
            bgcolor=\"#9C9DA9\" align=\"center\">"
    FOOTER="</table></td></tr></table></center></body></html>"
    
    help() {
       cat <<EOF
    
     $SCRIPT creates a HTML page with selected videos from Stage6
    
     Usage: $SCRIPT [options ...]
    
     Where options are:
     -h                  print this text
     -m MINUTES          videos have to be at least MINUTES long [default: $MIN_VL]
     -x MINUTES          videos have to be at most MINUTES long
                         (-1 for any video length) [default: $MAX_VL]
     -p NUMBER_OF_PAGES  how many pages to process (-1 for all) [default: $PAGES]
     -s NUMBER_OF_PAGES  how many pages to skip [default: $SKIP]
     -o ORDER            order videos by ORDER
                         (r-ating, h-otness, q-uality, l-ength, d-ate) [default: $ORD]
     -a [y|n]            process videos of all time. If set to "n" only videos
                         of the last two weeks will be processed [default: $ALLTIME]
    
    EOF
       exit 0
    }
    
    out() {
        echo -ne "$@"
    }
    
    warn() {
        out "\n${RED}$@${END}\n"
    }
    
    error() {
        warn "$@"
        help
    }
    
    check_programs() {
        for PRG in "$@"; do
    	if [ ! -x "$(which "$PRG" | grep bin)" ]; then
    	warn "\n \"$PRG\" is needed for the execution of this script!\n
                  Please, install \"$PRG\" first."
    	exit 1
    	fi
        done
    }
    
    append() {
        out "$@" >> $VLIST
    }
    
    add_video() {
        # get attributes of a video
        local LENGTH="$(echo "$@" | awk -F\<\/div\> '{print $1}')"
        local IMG="$(echo "$@" |  
                    awk -F\<div\ class=\'video-title\'\> '{print $1}' |  
                    awk -F\<\/div\> '{print $2}')"
        local TITLE="$(echo "$@" |  
                     awk -F\<div\ class=\'video-title\'\> '{print $2}' |   
                     awk -F\<\/div\> '{print $1}')"
    
        let VCMOD=$(expr $VCOUNT &#37; $COUNT)
    
        # add attributes to the table with selected videos
        if [ -n "$LENGTH" -o -n "$IMG" -o -n "$TITLE" ]; then
    	if [ $VCOUNT -eq 0 ];then 
    	    append "<tr>"
    	else
    	    if [ $VCOUNT -ge $COUNT -a $VCMOD -eq 0 ]; then
    		append "</tr><tr>"
    	    fi
    	fi
    	append "<td align=\"center\" height=\"100%\" width=\"33%\">
                    <table height=\"100%\"  width=\"100%\" cellspacing=\"1\" 
                    cellpadding=\"0.5\" border=\"$BRD\" bgcolor=\"$BCOL\">
                    <tr><td align=\"center\">$IMG</td></tr>
                    <tr><td align=\"center\">$LENGTH</td></tr>
                    <tr><td align=\"center\" rowspan=\"2\">$TITLE</td></tr>
                    <tr><td><br><br></td></tr></table></td>"
    	let VCOUNT=$VCOUNT+1
        fi
    }
    
    set_order() {
        case "$@" in 
    	r)
    	    ORD="rating"
    	    ;;
    	h)
    	    ORD="hotness"
    	    ;;
    	q)
    	    ORD="quality"
    	    ;;
    	l)
    	    ORD="length"
    	    ;;
    	d)
    	    ORD="date"
    	    ;;
    	*)
    	    error " $ORD is not a valid order!"
    	    ;;
        esac
    }
    
    is_arg_int() {
        # $1 - option, $2 -argument value
        case "$2" in
    	""|+|-|[!0-9+-]*|[0-9+-]*[!0-9]*)
                error  " $2 is not a valid argument value for \"-"$1\""!"
    	    ;;
        esac
    }
    
    cleanup() {
        $(which rm) -f $TMP 
        test -n "$WAITING" && kill -TERM $WAITING &> /dev/null
        echo -ne "${END}"
        exit 0
    }
    
    main() {
        check_programs $PGS
    
        # read options
        if [ "$#" -eq 0 ]; then 
    	out $NO_OPTIONS
    	read PROCEED
    	case "$PROCEED" in
    	    y|Y)
    		out "\n"
    		;;
    	    *)
    		help
    		;;
    	esac
        fi
        while getopts ":hm:x:a:p:s:o:" OPT; do
    	case "$OPT" in
    	    "h")
    	        help
    		;;
    	    "m" )
    		is_arg_int "$OPT" "$OPTARG"
                    let MIN_VL=$OPTARG
    		test $MIN_VL -ge 0 \
                    || error " $MIN_VL is not a valid minimal video length!"
    		;;
    	    "x")
    		is_arg_int "$OPT" "$OPTARG"
    	        let MAX_VL=$OPTARG
    		test $MAX_VL -ge -1 \
                    || error " $MAX_VL is not a valid maximum video length!"
    		;;
    	    "p")
    		is_arg_int "$OPT" "$OPTARG"
    	        let PAGES=$OPTARG
    		test $PAGES -ge 1 -o $PAGES -eq -1 \
                    || error " $PAGES is not a valid number of pages to process!"
    		;;
    	    "s")
    		is_arg_int "$OPT" "$OPTARG"
    	        let SKIP=$OPTARG
    		test $SKIP -ge 0 \
                    || error " $SKIP is not a valid number of pages to skip!"
    		;;
    	    "o")
    	        ORD="$OPTARG"
    		;;
    	    "a")
    	        ALLTIME="$OPTARG"
    		test "$ALLTIME" = "y" -o "$ALLTIME" = "n" \
                    || error " $ALLTIME is not a valid argument value for -a!"
    		;;
    	    "?")
    	        error " \"-"$OPTARG"\" is an unknown option!"
    		;;
    	    ":")
    	        error " No argument value for option \"-"$OPTARG\""!"
    		;;
    	    *)
    	        error " Unknown error occurred!"
    		;;
    
    	esac
        done
        shift $(($OPTIND - 1))
        set_order $ORD
        trap cleanup HUP INT QUIT ABRT TERM EXIT
    
        out "${BLU}Processing..."
        WAITING=""
    
        # indication that this script is running (if "waiting" is available)
        if [ -x "$(which waiting)" ]; then 
    	nice -n 19 waiting &
    	WAITING="$!"
        fi
    
        let TIME=$(date +%s)
        out $HEADER > $VLIST
        declare -a IDS
        
        # current page
        let CP=$SKIP+1
        
        if [ $ALLTIME = "y" ]; then
    	URL=$URL$ORD"/show:all?page="
        else
    	URL=$URL$ORD"?page="
        fi
    
        # if all pages are to be processed 
        # determine how many pages in total there are
        if [ $PAGES -eq -1 ]; then
    	${WG} "$URL"1
    	PAGES="$(cat $TMP | tr -d '\n' | awk -Fdetail-paging\'\> '{print $2}' | 
                    awk -F\<\/div\> '{print $1}' | awk -F\<\/span\> '{print $1}' | 
                    awk '{print $NF}' | sed -e 's/,//g')"
    	let SKIP=0
        fi
    
        let PAGES=$SKIP+$PAGES+1
        while [ $CP -ne $PAGES ]; do
    	${WG} "$URL"$CP
    	for VN in {2..19}; do
    	    
    	    # extract video entry
    	    local VID="$(cat $TMP | 
                            sed -e 's/<[/]\?\(acronym\|img\ style\)[^>]*>//g' |
                   awk -F\<div\ class=\'video-overlay\'\> '{print $var}' var=$VN)"
    	    if [ -n "$VID" ]; then
    		
    		# remove duplicates
    		local HREF="$(echo $VID | 
                            awk -Fhref=\' '{print $2}' | awk -F\'\> '{print $1}')"
    		local ADDED="n"
    		for ID in "${IDS[@]}"; do
    		    if [ "$ID" = "$HREF" ]; then
    			ADDED="y"
    			break
    		    fi
    		done
    		
    		# add new video
    		if [ "$ADDED" = "n" ]; then
    		    IDS[$VCOUNT]="$HREF"
    		    if [ $MAX_VL -eq -1 ]; then
    			add_video $VID
    		    else
    			let VL=$(echo $VID | awk -F: '{print $1}')
    			if [ $VL -ge $MIN_VL -a $VL -le $MAX_VL ]; then
    			    add_video $VID
    			fi
    		    fi
    		fi
    	    fi
    	done
            let CP=$CP+1
        done
        SV="$VCOUNT videos selected" 
        
        # if needed add empty table cells to finish out 
        # the table with selected videos
        let VCMOD=$(expr $VCOUNT % $COUNT)
        while [ $VCOUNT -ge $COUNT -a $VCMOD -ne 0 ]; do
    	append "<td height=\"100%\" width=\"33%\" bgcolor=\"$BCOL\"></td>"
    	let VCOUNT=$VCOUNT+1
    	let VCMOD=$(expr $VCOUNT % $COUNT)
        done
        if  [ $VCOUNT -ge $COUNT -a $VCMOD -eq 0 ]; then
    	append "</tr>"
        fi
        
        # add creation date
        append "<tr><td align=\"center\" width=\"100%\" colspan=\"$COUNT\">
                <table width=\"100%\" border=\"$BRD\" bgcolor=\"$BCOL\">
                <tr><td align=\"center\">Creation date: $(date +%x\ %X\ %Z)</td></tr>
                </table></td></tr> $FOOTER"
        
        let TIME=$(date +%s)-$TIME
        DONE="\n$SV within $TIME seconds.\nYou can view the
               created HTML page \"file://$VLIST\" in your browser.${END}\n"
        out $DONE
    }
    
    # execute script with input options
    main "$@"
    #EOF
    E.g. now you can choose some newly added music videos (whose length usually varies between 3 and 6 minutes) by calling:
    Code:
    st6v -m 3 -x 6 -p 30
    That will process 30 Stage6 pages (about 540 videos sorted by date) and add only videos with length between 3 and 6 minutes to your personal video list in the default file "/tmp/st6v.html" which you can view in your favorite browser.

    Here is a short script for Firefox:
    Code:
    #!/bin/sh
    #
    # Script name: view_in_firefox
    #
    FIREFOX="$(which firefox)"
    
    test -z "$(${FIREFOX} -remote 'ping()' 2>&1 | grep Error -)" && \ 
    ARGS="-new-tab $1" || ARGS="$1"
    
    ${FIREFOX} "$ARGS" & &> /dev/null
    #EOF
    If you watch mostly music videos you can create something like this:
    Code:
    #!/bin/sh
    #
    # Script name: st6
    #
    # $1 - number of pages to process
    # $2 - number of pages to skip
    #
    
    st6v -m 3 -x 6 -p "$1" -s "$2"
    view_in_firefox /tmp/st6v.html
    #EOF
    Then you can simply call:
    Code:
    st6 30 0
    to process the first 30 pages or
    Code:
    st6 30 30
    to process the next 30 pages if you want to find more videos.

    Additionally, you might want to install another script of mine to display an indication of waiting while Stage6 pages are being processed by st6v. Here is the corresponding post.

    Enjoy the scripts!

    Comments are welcome.

  2. #2
    Just Joined!
    Join Date
    Nov 2004
    Posts
    18

    Post Minor update

    Here is an update of the script.

    Code:
    #!/bin/sh
    # 
    # Script name: st6v
    # -----------------
    #
    # Abstract:
    # ---------
    # This script creates a HTML page with selected videos from Stage6 
    # (http://www.stage6.com/videos/). 
    #
    # Description:
    # ------------
    # It functions as a filter for all available videos: they can be selected 
    # by length, order (rating, hotness, quality, length, date) and position 
    # within the current Stage6 video list.
    #
    # Changelog: 
    # --------
    # Version 0.1 initial release (2007-12-10) 
    # Version 0.2 additional checking of the input data (2007-12-17) 
    #
    #
    # Copyright (C) 2007 patch_linams@yahoo.com
    #
    # Permission is hereby granted, free of charge, to any person obtaining 
    # a copy of this software (the "Software"), to deal in the Software 
    # without restriction, including without limitation the rights to use, 
    # copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
    # of the Software, and to permit persons to whom the Software is furnished 
    # to do so, subject to the following conditions:
    #
    # The above copyright notice and this permission notice shall be included in 
    # all copies or substantial portions of the Software. 
    #
    # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED 
    # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
    # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
    # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY 
    # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ARISING 
    # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE.
    #
    
    # switches (bold and colors)
    BLD="\033[1m"
    RED="\033[31m"
    BLU="\033[34m"
    END="\033[0m"
    
    # script name
    SCRIPT="${0##*/}"
    
    # needed programs
    PGS="wget cat sed awk tr"
    
    # minimal video length in minutes
    declare -i MIN_VL=0
    
    # maximum video length in minutes (-1 for any video length)
    declare -i MAX_VL=-1
    
    # process videos of all time (y) or the last two weeks (n)
    ALLTIME="n"
    
    # period of time (the last two weeks or all time)
    test "$ALLTIME" = "n" && PERIOD="the last two weeks" ||  
    test "$ALLTIME" = "y" && PERIOD="all time"
    
    # number of pages to process (-1 for all)
    declare -i PAGES=-1
    
    # number of pages to skip
    declare -i SKIP=0
    
    # order by which videos are selected
    # (r-ating, h-otness, q-uality, l-ength, d-ate)
    ORD="d"
    
    # created HTML file with selected videos
    VLIST="/tmp/$SCRIPT.html"
    
    # how many videos in a row
    declare -i COUNT=3
    
    # how many videos already selected
    declare -i VCOUNT=0
    
    TMP=$(mktemp $VLIST.XXXXXXXXXX) || $TMP="$VLIST.$$"
    
    NO_OPTIONS="\n When $SCRIPT is called without any options it will process ALL\n
                Stage6 videos of $PERIOD. This can take a LONG time\n
                depending on your computer and your internet connection.\n
                Do you wish to proceed (y|n) [default: n]?\033[1C"
    
    WG="wget -q -k --read-timeout=80 -t inf -O $TMP"
    URL="http://www.stage6.com/videos/order:"
    
    BRD="0"
    BCOL="#FFFFFF"
    HEADER="<html><head><meta http-equiv=\"Content-Type\" 
            content=\"text/html; charset=utf-8\" />
            <title>Stage6 - Personal Video List</title></head><body><center>
            <table border=\"$BRD\" cellspacing=\"1\" cellpadding=\"0.5\"
            bgcolor=\"$BCOL\" align=\"center\"><tr><td>
            <table border=\"1\" cellspacing=\"1\" cellpadding=\"0.5\" 
            bgcolor=\"#9C9DA9\" align=\"center\">"
    FOOTER="</table></td></tr></table></center></body></html>"
    
    help() {
       cat <<EOF
    
     $SCRIPT creates a HTML page with selected videos from Stage6
    
     Usage: $SCRIPT [options ...]
    
     Where options are:
     -h                  print this text
     -m MINUTES          videos have to be at least MINUTES long [default: $MIN_VL]
     -x MINUTES          videos have to be at most MINUTES long
                         (-1 for any video length) [default: $MAX_VL]
     -p NUMBER_OF_PAGES  how many pages to process (-1 for all) [default: $PAGES]
     -s NUMBER_OF_PAGES  how many pages to skip [default: $SKIP]
     -o ORDER            order videos by ORDER
                         (r-ating, h-otness, q-uality, l-ength, d-ate) [default: $ORD]
     -a [y|n]            process videos of all time. If set to "n" only videos
                         of the last two weeks will be processed [default: $ALLTIME]
    
    EOF
       exit 0
    }
    
    out() {
        echo -ne "$@"
    }
    
    warn() {
        out "\n${RED}$@${END}\n"
    }
    
    error() {
        warn "$@"
        help
    }
    
    check_programs() {
        for PRG in "$@"; do
    	if [ ! -x "$(which "$PRG" | grep bin)" ]; then
    	warn "\n \"$PRG\" is needed for the execution of this script!\n
                  Please, install \"$PRG\" first."
    	exit 1
    	fi
        done
    }
    
    append() {
        out "$@" >> $VLIST
    }
    
    add_video() {
        # get attributes of a video
        local LENGTH="$(echo "$@" | awk -F\<\/div\> '{print $1}')"
        local IMG="$(echo "$@" |  
                    awk -F\<div\ class=\'video-title\'\> '{print $1}' |  
                    awk -F\<\/div\> '{print $2}')"
        local TITLE="$(echo "$@" |  
                     awk -F\<div\ class=\'video-title\'\> '{print $2}' |   
                     awk -F\<\/div\> '{print $1}')"
    
        let VCMOD=$(expr $VCOUNT &#37; $COUNT)
    
        # add attributes to the table with selected videos
        if [ -n "$LENGTH" -o -n "$IMG" -o -n "$TITLE" ]; then
    	if [ $VCOUNT -eq 0 ];then 
    	    append "<tr>"
    	else
    	    if [ $VCOUNT -ge $COUNT -a $VCMOD -eq 0 ]; then
    		append "</tr><tr>"
    	    fi
    	fi
    	append "<td align=\"center\" height=\"100%\" width=\"33%\">
                    <table height=\"100%\"  width=\"100%\" cellspacing=\"1\" 
                    cellpadding=\"0.5\" border=\"$BRD\" bgcolor=\"$BCOL\">
                    <tr><td align=\"center\">$IMG</td></tr>
                    <tr><td align=\"center\">$LENGTH</td></tr>
                    <tr><td align=\"center\" rowspan=\"2\">$TITLE</td></tr>
                    <tr><td><br><br></td></tr></table></td>"
    	let VCOUNT=$VCOUNT+1
        fi
    }
    
    set_order() {
        case "$@" in 
    	r)
    	    ORD="rating"
    	    ;;
    	h)
    	    ORD="hotness"
    	    ;;
    	q)
    	    ORD="quality"
    	    ;;
    	l)
    	    ORD="length"
    	    ;;
    	d)
    	    ORD="date"
    	    ;;
    	*)
    	    error " $ORD is not a valid order!"
    	    ;;
        esac
    }
    
    is_arg_int() {
        # $1 - option, $2 -argument value
        case "$2" in
    	""|+|-|[!0-9+-]*|[0-9+-]*[!0-9]*)
                error  " $2 is not a valid argument value for \"-"$1\""!"
    	    ;;
        esac
    }
    
    remove_opt() {
        for i in "$@"; do
    	OPTS=$(echo ${OPTS#"$i"})
        done
    }
    
    cleanup() {
        $(which rm) -f $TMP 
        test -n "$WAITING" && kill -TERM $WAITING &> /dev/null
        echo -ne "${END}"
        exit 0
    }
    
    main() {
        check_programs $PGS
    
        # read options
        if [ "$#" -eq 0 ]; then 
    	out $NO_OPTIONS
    	read PROCEED
    	case "$PROCEED" in
    	    y|Y)
    		out "\n"
    		;;
    	    *)
    		help
    		;;
    	esac
        fi
        OPTS="$@"
        while getopts ":hm:x:a:p:s:o:" OPT; do
    	case "$OPT" in
    	    "h")
    	        help
    		;;
    	    "m" )
    		is_arg_int "$OPT" "$OPTARG"
                    let MIN_VL=$OPTARG
    		test $MIN_VL -ge 0 \
                    || error " $MIN_VL is not a valid minimal video length!"
    		remove_opt "-$OPT" "$OPTARG"
    		;;
    	    "x")
    		is_arg_int "$OPT" "$OPTARG"
    	        let MAX_VL=$OPTARG
    		test $MAX_VL -ge -1 \
                    || error " $MAX_VL is not a valid maximum video length!"
    		remove_opt "-$OPT" "$OPTARG"
    		;;
    	    "p")
    		is_arg_int "$OPT" "$OPTARG"
    	        let PAGES=$OPTARG
    		test $PAGES -ge 1 -o $PAGES -eq -1 \
                    || error " $PAGES is not a valid number of pages to process!"
    		remove_opt "-$OPT" "$OPTARG"
    		;;
    	    "s")
    		is_arg_int "$OPT" "$OPTARG"
    	        let SKIP=$OPTARG
    		test $SKIP -ge 0 \
                    || error " $SKIP is not a valid number of pages to skip!"
    		remove_opt "-$OPT" "$OPTARG"
    		;;
    	    "o")
    	        ORD="$OPTARG"
    		remove_opt "-$OPT" "$OPTARG"
    		;;
    	    "a")
    	        ALLTIME="$OPTARG"
    		test "$ALLTIME" = "y" -o "$ALLTIME" = "n" \
                    || error " $ALLTIME is not a valid argument value for -a!"
    		remove_opt "-$OPT" "$OPTARG"
    		;;
    	    "?")
    	        error " \"-"$OPTARG"\" is an unknown option!"
    		;;
    	    ":")
    	        error " No argument value for option \"-"$OPTARG\""!"
    		;;
    	    *)
    	        error " Unknown error occurred!"
    		;;
    
    	esac
        done
        shift $(($OPTIND - 1))
        test -n "$OPTS" && error " Invalid options or argument values: \"$OPTS\"!"
        set_order $ORD
        trap cleanup HUP INT QUIT ABRT TERM EXIT
    
        out "${BLU}Processing..."
        WAITING=""
    
        # indication that this script is running (if "waiting" is available)
        if [ -x "$(which waiting)" ]; then 
    	nice -n 19 waiting &
    	WAITING="$!"
        fi
    
        let TIME=$(date +%s)
        out $HEADER > $VLIST
        declare -a IDS
        
        # current page
        let CP=$SKIP+1
        
        if [ $ALLTIME = "y" ]; then
    	URL=$URL$ORD"/show:all?page="
        else
    	URL=$URL$ORD"?page="
        fi
    
        # if all pages are to be processed 
        # determine how many pages in total there are
        if [ $PAGES -eq -1 ]; then
    	${WG} "$URL"1
    	PAGES="$(cat $TMP | tr -d '\n' | awk -Fdetail-paging\'\> '{print $2}' | 
                    awk -F\<\/div\> '{print $1}' | awk -F\<\/span\> '{print $1}' | 
                    awk '{print $NF}' | sed -e 's/,//g')"
    	let SKIP=0
        fi
    
        let PAGES=$SKIP+$PAGES+1
        while [ $CP -ne $PAGES ]; do
    	${WG} "$URL"$CP
    	for VN in {2..19}; do
    	    
    	    # extract video entry
    	    local VID="$(cat $TMP | 
                            sed -e 's/<[/]\?\(acronym\|img\ style\)[^>]*>//g' |
                   awk -F\<div\ class=\'video-overlay\'\> '{print $var}' var=$VN)"
    	    if [ -n "$VID" ]; then
    		
    		# remove duplicates
    		local HREF="$(echo $VID | 
                            awk -Fhref=\' '{print $2}' | awk -F\'\> '{print $1}')"
    		local ADDED="n"
    		for ID in "${IDS[@]}"; do
    		    if [ "$ID" = "$HREF" ]; then
    			ADDED="y"
    			break
    		    fi
    		done
    		
    		# add new video
    		if [ "$ADDED" = "n" ]; then
    		    IDS[$VCOUNT]="$HREF"
    		    if [ $MAX_VL -eq -1 ]; then
    			add_video $VID
    		    else
    			let VL=$(echo $VID | awk -F: '{print $1}')
    			if [ $VL -ge $MIN_VL -a $VL -le $MAX_VL ]; then
    			    add_video $VID
    			fi
    		    fi
    		fi
    	    fi
    	done
            let CP=$CP+1
        done
        SV="$VCOUNT videos selected" 
        
        # if needed add empty table cells to finish out 
        # the table with selected videos
        let VCMOD=$(expr $VCOUNT % $COUNT)
        while [ $VCOUNT -ge $COUNT -a $VCMOD -ne 0 ]; do
    	append "<td height=\"100%\" width=\"33%\" bgcolor=\"$BCOL\"></td>"
    	let VCOUNT=$VCOUNT+1
    	let VCMOD=$(expr $VCOUNT % $COUNT)
        done
        if  [ $VCOUNT -ge $COUNT -a $VCMOD -eq 0 ]; then
    	append "</tr>"
        fi
        
        # add creation date
        append "<tr><td align=\"center\" width=\"100%\" colspan=\"$COUNT\">
                <table width=\"100%\" border=\"$BRD\" bgcolor=\"$BCOL\">
                <tr><td align=\"center\">Creation date: $(date +%x\ %X\ %Z)</td></tr>
                </table></td></tr> $FOOTER"
        
        let TIME=$(date +%s)-$TIME
        DONE="\n$SV within $TIME seconds.\nYou can view the
               created HTML page \"file://$VLIST\" in your browser.${END}\n"
        out $DONE
    }
    
    # execute script with input data
    main "$@"
    #EOF

Posting Permissions

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