bin-utils/arte7-dl.sh
2015-05-30 18:42:42 +02:00

247 lines
8.1 KiB
Bash
Executable File

#!/bin/bash
# arte7-dl.sh - Download Arte+7 videos
# Version: 0.3.2
# Creation date: Sun, 26 Apr 2009 00:27:18 +0200
# Last update: Sun, 22 Nov 2009 21:35:34 +0100
# Author: CSM 'illovae' Seldon <druuna@dud-t.org>
# Copyleft 2009
# Helpers/Debuggers/Contributors:
# This script is a fork of an original idea by beubeud : Arte+7 Recorder
# http://codingteam.net/project/arte7recorder
# FREE ADVERTISE: http://u-classroom.net FTW!!
# arte7-dl.sh --help for help
# Dependancies: bash, mimms, wget, coreutils (echo, awk, grep, etc)
# arte7-dl.sh is distributed by license: Dual Beer-Ware/WTFPLv2
# THE BEER-WARE LICENSE:
# As long as you retain this notice you can do whatever you want with this
# stuff. If we meet some day, and you think this stuff is worth it, you can
# buy me a beer in return.
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
# Copies of this license document, and changing it is allowed as long
# as the name is changed.
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
# 0. You just DO WHAT THE FUCK YOU WANT TO.
# NOTE for the video quality --
# With Arte7 you can download Medium Quality videos or High Quality videos.
# For the moment, this script haven't option to let you choose what video
# quality you want. The video quality is defined in this script in the $VQ
# variable below and use by default Medium Quality (MQ). Feel free to
# edit this variable at your convenience.
# BUG with mimms 3.2 --
# The original mimms 3.2 which can be downloaded from the project website
# http://savannah.nongnu.org/projects/mimms/ have a know bug : you cannot
# use the filename you want while downloading the stream. This is a function
# used by this script, so we invite you to use an other mimms version, or you
# can use a patched version. For example in debian, mimms have been patched to
# mimms 3.2.1, by debian devels, which is working properly.
# AND KNOW WE CAN BEGIN!
# Variables
# Name by which this script was invoked.
PROGNAME=$(basename $0)
VERSION="0.3.2"
# Video Quality
VQ=MQ # HQ == High Quality ; MQ = Medium Quality
# Others variables
USAGE="Usage: $PROGNAME {option}
NB: The [VALUES] are required.
Options are:
-h, --help You're looking at it
-l, --list List all availables shows
-i, --infos [VIDEO_ID] Get informations for a show using VIDEO_ID
-d, --download [VIDEO_ID] Download a file using VIDEO_ID
-v, --version Version and license
"
CASE=help
# To prevent hairy quoting and escaping later.
bq='`'
eq="'"
# The functions
# We want to get the list of available shows
function getlist
{
XMLLINK="http://plus7.arte.tv$(wget -q -O - http://plus7.arte.tv/ | \
grep xmlURL | awk -F'"' '{print $4}')"
wget -q -O - $XMLLINK | grep -F "<index>
<bigTitle>
<startDate>
<offlineDate>
<targetURL>" | sed -e 's/<index>/-- VIDEO #/g' \
-e 's/<bigTitle>/Title: /g' \
-e 's/<startDate>/Since: /g' \
-e 's/<offlineDate>/To: /g' \
-e 's/<targetURL>/Video ID: /g' \
-e 's/http[^>]*,CmC=//g' \
-e 's/,schedu[^>]*html/\n/g' | \
sed -e 's/^\s*//' | sed 's/<[^>]*>//g'
}
# We want informations from a show
function getinfos
{
# We get the stuffs
XMLLINK="http://plus7.arte.tv$(wget -q -O - http://plus7.arte.tv/ | \
grep xmlURL | awk -F'"' '{print $4}')"
GETXML=$(wget -q -O - "$XMLLINK" | grep -B 6 "$VIDEO_ID")
VIDEOURL=$(echo "$GETXML" | grep "<targetURL>" | sed -e "s/^\s*//" | \
sed "s/<[^>]*>//g")
if [ ! -z "$VIDEOURL" ]; then
# We want the name and date of the video and the HTML content
VIDEOTITLE=$(echo "$GETXML" | grep "<bigTitle>" | sed -e "s/^\s*//" | \
sed "s/<[^>]*>//g")
VIDEODATE=$(echo "$GETXML" | grep "<startDate>" | sed -e "s/^\s*//" | \
sed "s/<[^>]*>//g" | cut -d"T" -f1)
VIDEOHTML=$(wget -q -O - "$VIDEOURL")
# First we get the information
HEADLINE=$(echo "$VIDEOHTML" | grep -A 2 '<p class="headline">' | \
sed 's/<[^>]*>//g' | sed -e 's/^\s*//')
SYNOPSIS=$(echo "$VIDEOHTML" | grep -A 2 '<p class="text">' | \
sed 's/<[^>]*>//g' | sed -e 's/^\s*//')
INFOS=$(echo "$VIDEOHTML" | grep -A 2 '<p class="info">' | \
sed 's/<[^>]*>//g' | sed -e 's/^\s*//' | \
sed 's/(//' | sed 's/)/./')
# And finally we can display them
echo -e "Informations for "$bq$VIDEOTITLE$eq" ("$VIDEODATE"):\n"
echo -e "Headline --"$HEADLINE"\n"
echo -e "Synopsis --"$SYNOPSIS"\n"
echo -e "Others --"$INFOS
else
echo "$PROGNAME: there's no show whith the ID $bq$VIDEO_ID$eq"
echo "$PROGNAME: please check the show list to get a right ID"
echo "$PROGNAME: if your're sure of your ID, then this script might be deprecated"
echo "$PROGNAME: or the site may be broken..."
exit 1
fi
}
# Finally we want to download the wmv file
function getfile
{
# We get the stuffs + we define CONV for a good file renaming
XMLLINK="http://plus7.arte.tv$(wget -q -O - http://plus7.arte.tv/ | \
grep xmlURL | awk -F'"' '{print $4}')"
GETXML=$(wget -q -O - "$XMLLINK" | grep -B 6 "$VIDEO_ID")
CONV="y/abcdefghijklmnopqrstuvwxyzéèêçàù/ABCDEFGHIJKLMNOPQRSTUVWXYZEEECAU/"
if [ ! -z "$GETXML" ]; then
# We want the name and date of the video ; putting them together
VIDEOTITLE=$(echo "$GETXML" | grep "<bigTitle>" | sed -e "s/^\s*//" | \
sed "s/<[^>]*>//g" | sed -e $CONV | \
tr "[:blank:]" "_")
VIDEODATE=$(echo "$GETXML" | grep "<startDate>" | sed -e "s/^\s*//" | \
sed "s/<[^>]*>//g" | cut -d"T" -f1)
FILERENAME=$VIDEOTITLE"_"$VIDEODATE
# Now we want the mms link and the original filename
VIDEOURL=$(echo "$GETXML" | grep "<targetURL>" | sed -e "s/^\s*//" | \
sed "s/<[^>]*>//g")
VIDEOLINK=$(wget -q -O - "$VIDEOURL" | grep wmv | grep $VQ | cut -d"\"" -f4)
FILEORINAME=$(echo "$VIDEOLINK" | cut -d"/" -f8 | cut -d"." -f1)
MMSLINK=$(wget -q -O - "$VIDEOLINK" | grep mms | cut -d"\"" -f2)
# All stuff ok, we can proceed
mimms -r $MMSLINK $FILERENAME"_"$FILEORINAME".wmv"
else
echo "$PROGNAME: there's no show whith the ID $bq$VIDEO_ID$eq"
echo "$PROGNAME: please check the show list to get a right ID"
echo "$PROGNAME: if your're sure of your ID, then this script might be deprecated"
echo "$PROGNAME: or the site may be broken..."
exit 1
fi
}
# OK here we go now!
# Parse command line arguments.
while test $# != 0; do
case "$1" in
-h|--help)
CASE=help
shift
;;
-l|--list)
CASE=list
shift
;;
-i|--infos)
CASE=infos
shift
;;
-d|--download)
CASE=download
shift
;;
-v|--version)
echo "$PROGNAME ($VERSION) distributed under Dual Beer-Ware/WTFPLv2"
exit 0
;;
-- ) # Stop option processing
shift
break
;;
-? | --* )
case "$1" in
--*=* ) arg=`echo "$1" | sed -e 's/=.*//'` ;;
*) arg="$1" ;;
esac
exec 1>&2
echo "$PROGNAME: unknown or ambiguous option $bq$arg$eq"
echo "$PROGNAME: Use $bq--help$eq for a list of options."
exit 1
;;
*)
break
;;
esac
done
# for every case, do something!
case "$CASE" in
help)
echo "$USAGE" 1>&2
exit 0
;;
list)
getlist
;;
infos)
VIDEO_ID=$1
getinfos
;;
download)
VIDEO_ID=$1
getfile
;;
esac
exit 0