| ggg/batchy/ggg |
| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2006 Antoine 'NaPs' Millet <antoine@inaps.org> |
| 4 | # Copyright 2006 Nicolas 'Batchy' |
| 5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by |
| 8 | # the Free Software Foundation; either version 3 of the License, or |
| 9 | # (at your option) any later version. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License |
| 17 | # along with this program; if not, write to the Free Software |
| 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 19 | # MA 02110-1301, USA. |
| 20 | # |
| 21 | |
| 22 | # Configuration : |
| 23 | |
| 24 | OUTPUT_DIR=~/video/Guignols |
| 25 | TMP_DIR=/tmp |
| 26 | |
| 27 | # Fin de la configuration |
| 28 | |
| 29 | SCRIPT_VERSION=0.2.2 |
| 30 | |
| 31 | |
| 32 | usage () { |
| 33 | echo "Usage: ggg [-hvql] [AAMMJJ | today | yesterday] [Fichier de" \ |
| 34 | "sortie]" |
| 35 | echo "Telecharger, et reencoder dans un format compatible avec les" \ |
| 36 | "tablettes Nokia," |
| 37 | echo "un episode des guignols suivant son jour de diffusion." |
| 38 | echo "" |
| 39 | echo " -h, --help affiche cette page d'aide" |
| 40 | echo " -v, --version affiche la version et quitte" |
| 41 | echo " -q, --high-quality encode avec une haute qualite" |
| 42 | echo " Recommande pour le Nokia N800" |
| 43 | echo " -l, --low-quality encode avec une basse qualite" |
| 44 | echo " Recommande pour le Nokia 770" |
| 45 | echo " --download-only" |
| 46 | echo " N'encode pas le fichier apres telechargement." |
| 47 | echo " --encode-only" |
| 48 | echo " Encode le fichier deja telecharge avec" \ |
| 49 | "--download-only" |
| 50 | echo "" |
| 51 | echo "Par defaut, le script utilise l'option --high-quality." |
| 52 | echo "Si -q et -l sont utilisees en meme temps, la derniere" |
| 53 | echo "selectionnee sera prise en compte." |
| 54 | } |
| 55 | |
| 56 | version () { |
| 57 | echo "ggg (Get GuiGnols) $SCRIPT_VERSION" |
| 58 | echo "Ecrit par Antoine 'NaPs' Millet avec quelques contributions" |
| 59 | echo "This is free software; see the source for copying conditions." \ |
| 60 | "There is NO" |
| 61 | echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A" \ |
| 62 | "PARTICULAR PURPOSE." |
| 63 | } |
| 64 | |
| 65 | quality='low' |
| 66 | encode='yes' |
| 67 | download='yes' |
| 68 | |
| 69 | while getopts ":vh-:" opt ; do |
| 70 | case $opt in |
| 71 | h ) usage ; exit ;; |
| 72 | v ) version ; exit ;; |
| 73 | |
| 74 | q ) quality="high" ;; |
| 75 | l ) quality="low" ;; |
| 76 | - ) case $OPTARG in |
| 77 | help ) usage ; exit ;; |
| 78 | version ) version ; exit ;; |
| 79 | |
| 80 | high-quality ) quality="high" ;; |
| 81 | low-quality ) quality="low" ;; |
| 82 | download-only ) encode="no" ;; |
| 83 | encode-only ) download="no" ;; |
| 84 | * ) |
| 85 | echo "Option illegale --$OPTARG" |
| 86 | exit 1 |
| 87 | ;; |
| 88 | esac ;; |
| 89 | ? ) |
| 90 | echo "Option illegale -$OPTARG" |
| 91 | exit 1 |
| 92 | ;; |
| 93 | esac |
| 94 | done |
| 95 | shift $(($OPTIND -1)) |
| 96 | |
| 97 | # Ceci constitue les choix par defaut |
| 98 | date=${1:-yesterday} |
| 99 | |
| 100 | if [ $encode = "no" -a $download = "no" ] ; then |
| 101 | echo "Options contradictoires : --download-only --encode-only" |
| 102 | exit 1 |
| 103 | fi |
| 104 | |
| 105 | case $date in |
| 106 | today ) gdate=$(date +%y%m%d) ;; |
| 107 | yesterday ) gdate=$(date --date 'yesterday' +%y%m%d) ;; |
| 108 | * ) gdate=$date;; |
| 109 | esac |
| 110 | |
| 111 | if [ ! -d $OUTPUT_DIR ] ; then |
| 112 | mkdir -p $OUTPUT_DIR |
| 113 | fi |
| 114 | output=${2:-"$OUTPUT_DIR/Guignol-$gdate.avi"} |
| 115 | |
| 116 | dumpfile=$TMP_DIR/guignols_$gdate.dump |
| 117 | |
| 118 | if [ ! -d $TMP_DIR ] ; then |
| 119 | echo "Impossible de localiser le repertoire temporaire" |
| 120 | echo "Editez ggg et remplacez la variable TMP_DIR" |
| 121 | exit 2 |
| 122 | fi |
| 123 | |
| 124 | if [ $download = "yes" ] ; then |
| 125 | |
| 126 | # determine the URL |
| 127 | |
| 128 | listoutput=`mktemp` |
| 129 | |
| 130 | # get the video number from the list |
| 131 | |
| 132 | # the link http://www.canalplus.fr/c-humour/pid1784-c-les-guignols.html |
| 133 | # redirects there |
| 134 | |
| 135 | wget -q "http://www.canalplus.fr/index.php?pid=1784" -O $listoutput |
| 136 | if [ ! -s $listoutput ]; then |
| 137 | echo "Impossible de telecharger la liste de video" |
| 138 | exit 1; |
| 139 | fi |
| 140 | |
| 141 | descriptiondate="`echo $gdate | |
| 142 | sed -r "s@([0-9]{2})([0-9]{2})([0-9]{2})@\3/\2/\1@" `" |
| 143 | if [ ! "$descriptiondate" ]; then |
| 144 | echo "Format de date invalide." |
| 145 | rm -f $listoutput |
| 146 | exit 1; |
| 147 | fi |
| 148 | |
| 149 | video_id=`sed -r -n -e "\\%\\['CONTENT_ID'\\] = %N" \ |
| 150 | -e "s%^.+\"([0-9]+)\".+\\n.+title=\"[^\"]*$descriptiondate[^\"]*\".*\$%\1%p" \ |
| 151 | < $listoutput ` |
| 152 | |
| 153 | if [ ! "$video_id" ]; then |
| 154 | echo "Impossible de trouver l'emission du $descriptiondate" |
| 155 | rm -f $listoutput |
| 156 | exit 1 |
| 157 | fi |
| 158 | |
| 159 | # now let's get the data and retrieve the url. |
| 160 | wget -q --post-data="video_id=$video_id" -O $listoutput \ |
| 161 | "http://www.canalplus.fr/flash/xml/module/embed-video-player/embed-video-player.php" |
| 162 | |
| 163 | if [ ! -s "$listoutput" ]; then |
| 164 | echo "Impossible de telecharger des informations sur la video." |
| 165 | rm -f $listoutput |
| 166 | exit 1 |
| 167 | fi |
| 168 | |
| 169 | url="`sed -n -r -e "/<hi>/s/^.*(http:.+)\\]\\].+$/\1/p" < $listoutput`" |
| 170 | |
| 171 | rm -r $listoutput |
| 172 | if [ ! "$url" ]; then |
| 173 | echo "Impossible de recuperer l'URL de la video" |
| 174 | exit 1 |
| 175 | fi |
| 176 | |
| 177 | echo "Telechargement du stream..." |
| 178 | echo "(Cela prend une dizaine de minutes)" |
| 179 | rm -f $dumpfile |
| 180 | wget $url -O $dumpfile |
| 181 | if [ ! -s $dumpfile ] ; then |
| 182 | echo "Impossible de capturer le stream !" |
| 183 | rm -f $dumpfile |
| 184 | exit 1 |
| 185 | fi |
| 186 | fi |
| 187 | |
| 188 | |
| 189 | |
| 190 | if [ $encode = "yes" ] ; then |
| 191 | |
| 192 | if [ ! -r $dumpfile ] ; then |
| 193 | echo "Le fichier $dumpfile n'a pas ete telecharge." |
| 194 | echo "Impossible d'encoder" |
| 195 | exit 1 |
| 196 | fi |
| 197 | |
| 198 | echo "Re-encodage du fichier..." |
| 199 | echo "(Cela peut prendre du temps selon la vitesse du processeur)" |
| 200 | case $quality in |
| 201 | low ) |
| 202 | mencoder $dumpfile -o $output -oac mp3lame -idx -ffourcc DIVX \ |
| 203 | -ofps 25.0 -lameopts abr:br=64:vol=1 -af volnorm -ovc lavc \ |
| 204 | -lavcopts vcodec=mpeg4:dark_mask=0.15:aspect=15/9:vbitrate=256:trell=yes:v4mv=yes:vpass=1 -vf crop=506:304,scale=288:208,eq2=1.4:1.2:0.0:1.4 \ |
| 205 | 2>&1 > /dev/null |
| 206 | |
| 207 | mencoder $dumpfile -o $output -oac mp3lame -idx -ffourcc DIVX \ |
| 208 | -ofps 25.0 -lameopts abr:br=64:vol=1 -af volnorm -ovc lavc \ |
| 209 | -lavcopts vcodec=mpeg4:dark_mask=0.15:aspect=15/9:vbitrate=256:trell=yes:v4mv=yes:vpass=2 -vf crop=506:304,scale=288:208,eq2=1.4:1.2:0.0:1.4 \ |
| 210 | 2>&1 > /dev/null |
| 211 | ;; |
| 212 | high ) |
| 213 | mencoder $dumpfile -o $output -oac mp3lame -idx -ffourcc DIVX \ |
| 214 | -ofps 25.0 -lameopts abr:br=64:vol=1 -af volnorm -ovc lavc \ |
| 215 | -lavcopts vcodec=mpeg4:dark_mask=0.15:aspect=15/9:vbitrate=512:trell=yes:v4mv=yes:vpass=1 -vf crop=506:304,scale=352:288,eq2=1.4:1.2:0.0:1.4 \ |
| 216 | 2>&1 > /dev/null |
| 217 | mencoder $dumpfile -o $output -oac mp3lame -idx -ffourcc DIVX \ |
| 218 | -ofps 25.0 -lameopts abr:br=64:vol=1 -af volnorm -ovc lavc \ |
| 219 | -lavcopts vcodec=mpeg4:dark_mask=0.15:aspect=15/9:vbitrate=512:trell=yes:v4mv=yes:vpass=2 -vf crop=506:304,scale=352:288,eq2=1.4:1.2:0.0:1.4 \ |
| 220 | 2>&1 > /dev/null |
| 221 | ;; |
| 222 | esac |
| 223 | if [ -e $output ] ; then |
| 224 | echo "L'episode a ete correctement telecharge et encode dans le" |
| 225 | echo "fichier $output :-)" |
| 226 | else |
| 227 | echo "Damned, l'encodage n'a pas reussi :-(" |
| 228 | exit 1 |
| 229 | fi |
| 230 | else |
| 231 | echo "Stream telecharge dans le fichier $dumpfile." |
| 232 | fi |
| ggg/ggg |
| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2006 Antoine 'NaPs' Millet <antoine@inaps.org> |
| 4 | # Copyright 2006 Nicolas 'Batchy' |
| 5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by |
| 8 | # the Free Software Foundation; either version 2 of the License, or |
| 9 | # (at your option) any later version. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License |
| 17 | # along with this program; if not, write to the Free Software |
| 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | # |
| 20 | |
| 21 | # Configuration : |
| 22 | |
| 23 | OUTPUT_DIR=~/video/Guignols |
| 24 | TMP_DIR=/tmp/ |
| 25 | |
| 26 | # Fin de la configuration |
| 27 | |
| 28 | SCRIPT_VERSION=0.2.2 |
| 29 | |
| 30 | |
| 31 | usage () { |
| 32 | echo "Usage: ggg [-hvql] [AAMMJJ | today | yesterday] [Fichier de sortie]" |
| 33 | echo "Telecharger, et reencoder dans un format compatible avec les tablettes Nokia," |
| 34 | echo "un episode des guignols suivant son jour de diffusion." |
| 35 | echo "" |
| 36 | echo " -h, --help affiche cette page d'aide" |
| 37 | echo " -v, --version affiche la version et quitte" |
| 38 | echo " -q, --high-quality encode avec une haute qualite" |
| 39 | echo " Recommande pour le Nokia N800" |
| 40 | echo " -l, --low-quality encode avec une basse qualite" |
| 41 | echo " Recommande pour le Nokia 770" |
| 42 | echo " --download-only" |
| 43 | echo " N'encode pas le fichier apres telechargement." |
| 44 | echo " --encode-only" |
| 45 | echo " Encode le fichier deja telecharge avec --download-only" |
| 46 | echo "" |
| 47 | echo "Par defaut, le script utilise l'option --high-quality." |
| 48 | echo "Si -q et -l sont utilisees en meme temps, la derniere selectionnee" |
| 49 | echo "sera prise en compte." |
| 50 | } |
| 51 | |
| 52 | version () { |
| 53 | echo "ggg (Get GuiGnols) $SCRIPT_VERSION" |
| 54 | echo "Ecrit par Antoine 'NaPs' Millet avec quelques contributions" |
| 55 | echo "This is free software; see the source for copying conditions. There is NO" |
| 56 | echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." |
| 57 | } |
| 58 | |
| 59 | |
| 60 | while getopts ":vh-:" opt ; do |
| 61 | case $opt in |
| 62 | h ) usage ; exit ;; |
| 63 | v ) version ; exit ;; |
| 64 | |
| 65 | q ) quality="high" ;; |
| 66 | l ) quality="low" ;; |
| 67 | - ) case $OPTARG in |
| 68 | help ) usage ; exit ;; |
| 69 | version ) version ; exit ;; |
| 70 | |
| 71 | high-quality ) quality="high" ;; |
| 72 | low-quality ) quality="low" ;; |
| 73 | download-only ) encode="no" ;; |
| 74 | encode-only ) download="no" ;; |
| 75 | * ) echo "Option illegale --$OPTARG" ;; |
| 76 | esac ;; |
| 77 | ? ) echo "Option illegale -$OPTARG" ;; |
| 78 | esac |
| 79 | done |
| 80 | shift $(($OPTIND -1)) |
| 81 | |
| 82 | # Ceci constitue les choix par defaut |
| 83 | date=${1:-yesterday} |
| 84 | quality=${quality:-"low"} |
| 85 | encode=${encode:-"yes"} |
| 86 | download=${download:-"yes"} |
| 87 | |
| 88 | if [ $encode = "no" -a $download = "no" ] ; then |
| 89 | echo "Options contradictoires : --download-only --encode-only" |
| 90 | exit 1 |
| 91 | fi |
| 92 | |
| 93 | case $date in |
| 94 | today ) gdate=$(date +%y%m%d) ;; |
| 95 | yesterday ) gdate=$(date --date 'yesterday' +%y%m%d) ;; |
| 96 | * ) gdate=$date;; |
| 97 | esac |
| 98 | |
| 99 | if [ ! -d $OUTPUT_DIR ] ; then |
| 100 | mkdir -p $OUTPUT_DIR |
| 101 | fi |
| 102 | output=${2:-"$OUTPUT_DIR/Guignol-$gdate.avi"} |
| 103 | |
| 104 | url=http://vipmms.canalplus.fr/canalplus/guignols_"$gdate"_a.wmv?MSWMExt=.asf |
| 105 | dumpfile=$TMP_DIR/guignols_$gdate.dump |
| 106 | |
| 107 | if [ -d $TMP_DIR ] ; then |
| 108 | if [ $download = "yes" ] ; then |
| 109 | echo "Telechargement du stream..." |
| 110 | echo "(Cela prend une dizaine de minutes)" |
| 111 | rm -f $dumpfile |
| 112 | mplayer -cache 2000 -dumpstream -dumpfile $dumpfile $url > /dev/null |
| 113 | if [ ! -s $dumpfile ] ; then |
| 114 | echo "Impossible de capturer le stream !" |
| 115 | rm -f $dumpfile |
| 116 | exit 1 |
| 117 | fi |
| 118 | else |
| 119 | if [ ! -r $dumpfile ] ; then |
| 120 | echo "Le fichier $dumpfile n'a pas ete telecharge. Impossible d'encoder" |
| 121 | exit 1 |
| 122 | fi |
| 123 | fi |
| 124 | |
| 125 | |
| 126 | |
| 127 | if [ $encode = "yes" ] ; then |
| 128 | |
| 129 | echo "Re-encodage du fichier..." |
| 130 | echo "(Cela peut prendre un peu de temps selon la vitesse du processeur)" |
| 131 | case $quality in |
| 132 | low ) $(mencoder $dumpfile -oac mp3lame -lameopts abr:br=64:vol=1 -af volnorm -ovc lavc -lavcopts vcodec=mpeg4:dark_mask=0.15:aspect=15/9:vbitrate=256:trell=yes:v4mv=yes:vpass=1 -vf crop=506:304,scale=288:208,eq2=1.4:1.2:0.0:1.4 -idx -ffourcc DIVX -ofps 25.0 -o $output > /dev/null) |
| 133 | $(mencoder $dumpfile -oac mp3lame -lameopts abr:br=64:vol=1 -af volnorm -ovc lavc -lavcopts vcodec=mpeg4:dark_mask=0.15:aspect=15/9:vbitrate=256:trell=yes:v4mv=yes:vpass=2 -vf crop=506:304,scale=288:208,eq2=1.4:1.2:0.0:1.4 -idx -ffourcc DIVX -ofps 25.0 -o $output > /dev/null) ;; |
| 134 | high ) $(mencoder $dumpfile -oac mp3lame -lameopts abr:br=64:vol=1 -af volnorm -ovc lavc -lavcopts vcodec=mpeg4:dark_mask=0.15:aspect=15/9:vbitrate=512:trell=yes:v4mv=yes:vpass=1 -vf crop=506:304,scale=352:288,eq2=1.4:1.2:0.0:1.4 -idx -ffourcc DIVX -ofps 25.0 -o $output > /dev/null) |
| 135 | $(mencoder $dumpfile -oac mp3lame -lameopts abr:br=64:vol=1 -af volnorm -ovc lavc -lavcopts vcodec=mpeg4:dark_mask=0.15:aspect=15/9:vbitrate=512:trell=yes:v4mv=yes:vpass=2 -vf crop=506:304,scale=352:288,eq2=1.4:1.2:0.0:1.4 -idx -ffourcc DIVX -ofps 25.0 -o $output > /dev/null) ;; |
| 136 | esac |
| 137 | if [ -e $output ] ; then |
| 138 | echo "L'episode a ete correctement telecharge et encode dans le fichier $output :-)" |
| 139 | else |
| 140 | echo "Damned, l'encodage n'a pas reussi :-(" |
| 141 | exit 1 |
| 142 | fi |
| 143 | else |
| 144 | echo "Stream telecharge dans le fichier $dumpfile " |
| 145 | fi |
| 146 | else |
| 147 | echo "Impossible de localiser le repertoire temporaire" |
| 148 | echo "Editez ggg et remplacez la variable TMP_DIR" |
| 149 | exit 2 |
| 150 | fi |