Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 07/09/2009, à 23:06

thurston

Script rip DVD en ligne commande

Bonjour,

Voila, j'ai pondu ce script (écriture pas très lechée) pour ripper mes DVDs. Le but est
1. un script qui me trouve la plus longue piste du DVD,
2. me trouve la piste en ac3 francaise (sans sous titre)
3. me délivre (rip) un gros fichier .mpg avec le nom du DVD en nom de fichier
4. je peux éteindre automatiquement le PC en fin de rip

J'ai testé sur quelques DVDs, cela semble fonctionner (testé sur 4 DVDs, mais j'en attends 5 autres pour continuer le test du soft).
Je trouve des softs comme DVD:rip très bien, mais ce sont des usines à gaz pour moi. Ici un lancement de script + un controle d'une fenetre (info correctes) et zou, on obtient le .mpg.
Je prends ce .mpg que je passe à la moulinette du script ici (http://forum.ubuntu-fr.org/viewtopic.php?id=211930&p=3), est re-zou, un xvid ac3 de bonne qualité.
Attention, je partage simplement ce script qui me convient, sans aucune prétention, car je pense qu'il en existe pas mal d'autres déjà écrit sur le sujet.
Amitiés.
Thurston

#!/bin/bash
#########################################
# Script de Thurston / Ubuntu
# 
#########################################
# Nautilus script
# 
# Mplayer, zenity
#########################################
# Script Version: 00
# Revision date:  2009-09-04
#
# Log
# *********************************************
# 00.0: 

# Variables initialisation
#******************************************************************************************


# Control of argument presence
#******************************************************************************************

# Handle options
#******************************************************************************************
while getopts "h" opt
do
   case $opt in
      h) # Help
         clear
         echo "usage: $0                              => sudo  if shutdown required"
         echo "usage: $0 [-h]                         => help"    
         echo "   *)Using Acidrip"
         echo "     -copy mode for Audio & Video"
         echo "     -Output= .mpg"
         echo "   *)Using DVD::Rip"
         echo "     -DVD Extraction"
         echo "     -Merge operation: cat 1.vob 2.vob > DVD.mpg"
         echo "   *)Using Command Line in a terminal"
         echo "     -DVD Info: lsdvd /dev/dvd"
         echo "     -Check correct file number x: mplayer dvd://x"
         echo "     -DVD Rip: mplayer dvd://x -dumpstream -dumpfile DVD.mpg or if n DVD players"
         echo "     -DVD Rip: mplayer dvd://x -dvd-device /dev/cdrom1 -dumpstream -dumpfile DVD.mpg"
         echo "   *)Using vobcopy"
         echo "     -vobcopy -m"
         echo "     -Note that sometimes, playing with -F (Fast) mode can help"
         echo "     -vobcopy -m -F x, with x in range [1..64]"
         echo ""
         echo "Notes:"
         echo "   *)mplayer, mencoder, libdvdcss, zenity proposed for auto-installation"
         echo "   *)a log file is created at the end of process"
         echo "   *)if launched using a ssh connexion:"
         echo "     - use ssh -X name@address, install xauth on remote computer"
         echo "     - use -ssh option when launching this script. It will removes the graphic"
         echo "       which makes the application to be auto-killed when closing ssh + screen"
         exit 1
         ;;
    esac

    # Remove option

    shift $((OPTIND - 1))
    OPTIND=1
done


#******************************************************************************************
# Control of minimum software requirements correctly installed
test -x /usr/bin/mplayer || sudo apt-get install mplayer -y
test -x /usr/bin/zenity || sudo apt-get install zenity -y
test -x /usr/bin/lsdvd || sudo apt-get install lsdvd -y

# Control of additionnal software correctly installed
#******************************************************************************************

if [ `test -x /usr/share/doc/libdvdcss2` ];
then
   echo "Do you want to proceed with libdvdcss2 installation (Hardy Only)? (y/n)"
   read answer
   if [ $answer = y ];
   then
      echo "##Dépôt Medibuntu" | sudo tee -a /etc/apt/sources.list
      echo "deb http://fr.packages.medibuntu.org/ hardy free non-free" | sudo tee -a /etc/apt/sources.list
      wget -q http://fr.packages.medibuntu.org/medibuntu-key.gpg
      sudo apt-key add medibuntu-key.gpg
      sudo apt-get update
      sudo apt-get install libdvdcss2
      sudo rm -rf medibuntu-key.gpg
   fi
fi

#******************************************************************************************
function track_rip()
{
# $1: physical optical disk
media_info=`lsdvd -q /dev/$1 2>/dev/null`
longest_track=`echo $media_info | grep "Longest track: "| awk -F ": " '{print $NF}'`
title_dvd=`echo $media_info | awk -F ":" '{print $2}'| awk -F " " '{print $1}'`
dvd_track_length=`mplayer -vo null -ao null -frames 0 -identify dvd://$longest_track -dvd-device /dev/$1 2>/dev/null | grep "ID_LENGTH=" | awk -F "=" '{print $NF}' | awk -F "." '{print $1}'`
dvd_track_lenght_min=$(( dvd_track_length / 60 ))
dvd_track_audio=`mplayer -vo null -ao null -frames 0 -identify dvd://$longest_track -dvd-device /dev/$1  2>/dev/null | grep "language: fr" | grep "audio"`
atrack=`mplayer -vo null -ao null -frames 0 -identify dvd://$longest_track -dvd-device /dev/$1  2>/dev/null | grep "language: fr" | grep "audio" | grep "ac3" | awk -F " " '{print $NF}' | awk -F "." '{print $1}'`

zenity --question --title="QUESTION" \
       --text="\nDVD Name:$title_dvd\nLongest Track:  $longest_track\nVideo Length:   $dvd_track_lenght_min min\n\nAudio ID-Track: $atrack\n($dvd_track_audio)\n\nSettings correct?\n(If No, help: $0 -h)"


if [  $? = 0 ];
then
   if [ -e $title_dvd-$language_ID.mpg ];
      then
      zenity --question --title="QUESTION" \
                        --text=" Overwrite already existing file? \n"
      if [  $? = 0 ];
      then
         mplayer dvd://$longest_track -aid $atrack -dvd-device /dev/$1 -dumpstream -dumpfile $title_dvd-$atrack.mpg
      else
         exit
      fi
   else
      mplayer dvd://$longest_track -aid $atrack -dvd-device /dev/$1 -dumpstream -dumpfile $title_dvd-$atrack.mpg
   fi
fi
}

#******************************************************************************************
function drive_selection()
#
{
# Choice Box (between different drives (up to 3)
drive=`zenity  --title="Drive Selection" \
                --text="Choose correct Drive to use" \
                --list \
                --radiolist \
                --height="250" \
                --width="400" \
                --column="Selection" \
                --column="Drive" \
                --column="Description" \
                TRUE "dvd" "default"\
                FALSE "dvd1" "if exists"\
                FALSE "dvd2" "if exists"\
                | sed 's/ max//g'`

# case of cancel action
if [ "$drive" = "" ];
then
   exit
fi
}

#******************************************************************************************
function postshutdown()
{
# Shutdown at the end of process Choice Box
end_action=`zenity  --title="End Of Process Action" \
                    --text="Select If PC enter shutdown at the end of encoding" \
                    --list \
                    --radiolist \
                    --height="250" \
                    --width="500" \
                    --column="Selection" \
                    --column="Action" \
                    --column="descriptif" \
                    FALSE "Shutdown" "Shutdown at End Of Encoding Process (sudo only)" \
                    TRUE "No-Shutdown" "PC Stays On at End Of Encoding Process" \
                    | sed 's/ max//g'`

if [ "$end_action" = "Shutdown" ];
then
   zenity --question --title="INFO" \
                     --text="You must be sudo for requesting a end process shutdown"
   if [ $? = 1 ];
   then
      exit
   fi
else
   if [ "$end_action" = "" ];
   then
      exit
   fi

fi	
}

#******************************************************************************************
function duration()
{
# $1= Stop date
# $2= Start date
# $3 = log file
# date +%s gives duration between 1-01-1970 in seconds. Then easy for duration calculation
difference=$(( $1-$2 ))
hour=$(( difference/3600 ))
min=$(( (( difference/60 ))-$(( hour*60 )) ))                     
sec=$(( (( difference ))-$(( hour*3600 + min*60 )) ))          
echo "Process Duration = $hour hour $min minutes $sec seconds" >> "$3"
}

#******************************************************************************************

#******************************************************************************************
#************************* Main Program ***************************************************
#******************************************************************************************

#******************************************************************************************
# 1th step: what to be done end of global processing: shutdown or not
postshutdown

#******************************************************************************************
# 2nd step: collect drive info
drive_selection

#******************************************************************************************
# 3rd step: process
date_in=$(date +%s)
track_rip $drive
date_out=$(date +%s)

#******************************************************************************************
# 4rd step: report
log_encode_file="$title_dvd-$atrack-Rip.log"
echo $(date) > "$log_encode_file"
duration $date_out $date_in $log_encode_file


#******************************************************************************************
# 5th step: set final encoding action
# need to modify /etc/sudoers to get rights to shutdown PC though a script   

if [ "$end_action" = "Shutdown" ];
then
   sudo /sbin/shutdown -h now
fi
exit

Dernière modification par thurston (Le 09/09/2009, à 22:25)

Hors ligne

#2 Le 08/09/2009, à 14:36

twocats

Re : Script rip DVD en ligne commande

Voici un fonction qui permet de détecter automatiquement la présence de dvd dans le lecteur. Je pense qu'elle pourrait être facilement adaptée à ton script.

FindDVD()
{
if [[ -r /proc/sys/dev/cdrom/info ]]
then
	local DRIVE_LIST=($(awk -F: '/drive name/ {gsub(/\t/, " "); gsub(/ +/, " "); print $2}' /proc/sys/dev/cdrom/info ))
	local CAN_READ_DVD=($(awk -F: '/Can read DVD/ {gsub(/\t/, " "); gsub(/ +/, " "); print $2}' /proc/sys/dev/cdrom/info ))
	local DRIVE_LIST_LEN=$[${#DRIVE_LIST[@]}-1]
	for (( i=0; i<=${DRIVE_LIST_LEN} ; i++ ))
	do
		[[ ${CAN_READ_DVD[$i]} -eq 1 ]] && DVD_DEV_LIST="${DVD_DEV_LIST} /dev/${DRIVE_LIST[$i]}"
	done
fi

if [[ "${DVD_DEV_LIST}x" = "x" ]]
then
	local DEV_DV=$(ls /dev/dvd? 2>/dev/null)
	local DEV_HD=$(ls /dev/hd? 2> /dev/null)
	local DEV_SR=$(ls /dev/sr? 2> /dev/null)
	local DEV_SC=$(ls /dev/scd? 2> /dev/null)
	for DEV in ${DEV_DV} ${DEV_HD} ${DEV_SR} ${DEV_SC}
	do
		local DEV_LNK=$(ls -ls ${DEV} | awk -F'->' '{print $2}')
		if [[ "${DEV_LNK}x" != "x" ]]
		then
			local DVD_DEV_LIST="${DVD_DEV_LIST} ${DEV_LNK}"
		else
			local DVD_DEV_LIST="${DVD_DEV_LIST} ${DEV}"
		fi
	done
fi
DVD_DEV_LIST=${DVD_DEV_LIST# }
DVD_DEV_LIST=$(echo "${DVD_DEV_LIST}" | tr ' ' '\n' | grep -F "/dev/" | sort | uniq | tr '\n' ' ')

for DEV in ${DVD_DEV_LIST}
do
	[[ "$(lsdvd "${DEV}" 2>/dev/null)" ]] && DEVICE_ID="${DEV}"
done
}

P.S.: Je n'en suis pas l'auteur.


La réponse est 42

Hors ligne

#3 Le 08/09/2009, à 18:40

thurston

Re : Script rip DVD en ligne commande

@ twocats

Trop cool, je l'ai pas mal cherchée cette fonction.
merci
A+
T

Hors ligne

#4 Le 08/09/2009, à 19:34

al_boon

Re : Script rip DVD en ligne commande

bon je préfère répondre ici.
il fonctionne a merveille, je l ai testé sur 4 dvd et il selectionne bien la bonne piste video et audio, mais pour le peu que je te connais je sais que tu peux l améliorer, un chose essentielle qui manque c est une option qui lancerai ton autre script a la fin du rip (je sais que tu encode plusieur dvd a la suite mais ca pourrait etre bien)
et peut etre un barre de progression ? meme juste un % dans la console ?
sinon un truc qui me plairai directement a moi c est  qu'il y est lors du choix du lecteur dvd, un choix ou l on pourrait renseigner un chemin vers un dossier.
ca me permettrai de me passer totalement d acidrip qui bloque mon son lorsque je l utilise.

sinon il est tres bien et c est bien plus rapide qu avec acidrip.

ps : je vais peut etre avoir un petit arret maladie, je m y collerai peut etre (j aime bien bidouiller ^^)


viva ubuntu ^^ et deux personnes converties !!

ps: il est pas beau mon fils ? (cf mon avatar)

Hors ligne

#5 Le 08/09/2009, à 20:46

thurston

Re : Script rip DVD en ligne commande

Salut al_boon,

- lancement de l'autre script fin rip.
=> oui mais le rip est tellement long que je me demande si ca a un intéret. Je peux le rajouter en option avant le lancement du rip, mais quand je multiplie les possibilités, ca fait plein de questions à laquelle répondre et ca rallonge l'opération. A ce propos, je vais sans doute re travailler sur l'autre script pour quasi tout automatiser, avec un controle unique du crop + langue.

- barre de progression
ouais, assez d'accord car pour vérifier que le script fonctionne, faut aller espionner la taille du mpg qui grossit et ca c'est pas top, à retravailler donc

- choix dossier
oui aussi pourquoi pas à l'occas.

En définitif, assez d'accord sauf le 1er point je dirais, qui me parait litige
A voir la suite si les momes me laissent un peu de temps
A+
T

Hors ligne

#6 Le 10/09/2009, à 20:29

al_boon

Re : Script rip DVD en ligne commande

oui après cela dépend de l utilisation qu on en a wink

pour le premier point j essayerai d y jeter un oeil, j ai eu un arret de 3 semaines

pour le script d encodage si on peu gagner un étape c est encore mieux wink


viva ubuntu ^^ et deux personnes converties !!

ps: il est pas beau mon fils ? (cf mon avatar)

Hors ligne

#7 Le 21/11/2009, à 19:54

thurston

Re : Script rip DVD en ligne commande

Bon, une nouvelle version qui traite mieux les multi-track de même language.
J'avais des soucis avec les DVD francais et le fait que quand plusieurs pistes étaient en Francais, le script perdait les pédales.
C'est - je crois - mieux maintenant.

#!/bin/bash
#########################################
# Script de Thurston / Ubuntu
# 
#########################################
# Nautilus script
# 
# Mplayer, zenity
#########################################
# Script Version: 01
# Revision date:  2009-11-20
#
# Log
# *********************************************
# 01: Better management of different same language tracks, with a 2nd step to choose correct one
# 00: Initial Version

# Variables initialisation
#******************************************************************************************


# Control of argument presence
#******************************************************************************************

# Handle options
#******************************************************************************************
while getopts "h" opt
do
   case $opt in
      h) # Help
         clear
         echo "usage: $0                              => sudo  if shutdown required"
         echo "usage: $0 [-h]                         => help"    
         echo "   *)Using Acidrip"
         echo "     -copy mode for Audio & Video"
         echo "     -Output= .mpg"
         echo "   *)Using DVD::Rip"
         echo "     -DVD Extraction"
         echo "     -Merge operation: cat 1.vob 2.vob > DVD.mpg"
         echo "   *)Using Command Line in a terminal"
         echo "     -DVD Info: lsdvd /dev/dvd"
         echo "     -Check correct file number x: mplayer dvd://x"
         echo "     -DVD Rip: mplayer dvd://x -dumpstream -dumpfile DVD.mpg or if n DVD players"
         echo "     -DVD Rip: mplayer dvd://x -dvd-device /dev/cdrom1 -dumpstream -dumpfile DVD.mpg"
         echo "   *)Using vobcopy"
         echo "     -vobcopy -m"
         echo "     -Note that sometimes, playing with -F (Fast) mode can help"
         echo "     -vobcopy -m -F x, with x in range [1..64]"
         echo ""
         echo "Notes:"
         echo "   *)mplayer, mencoder, libdvdcss, zenity proposed for auto-installation"
         echo "   *)a log file is created at the end of process"
         echo "   *)if launched using a ssh connexion:"
         echo "     - use ssh -X name@address, install xauth on remote computer"
         echo "     - use -ssh option when launching this script. It will removes the graphic"
         echo "       which makes the application to be auto-killed when closing ssh + screen"
         exit 1
         ;;
    esac

    # Remove option

    shift $((OPTIND - 1))
    OPTIND=1
done


#******************************************************************************************
# Control of minimum software requirements correctly installed
test -x /usr/bin/mplayer || sudo apt-get install mplayer -y
test -x /usr/bin/zenity || sudo apt-get install zenity -y
test -x /usr/bin/lsdvd || sudo apt-get install lsdvd -y

# Control of additionnal software correctly installed
#******************************************************************************************

if [ `test -x /usr/share/doc/libdvdcss2` ];
then
   echo "Do you want to proceed with libdvdcss2 installation? (y/n)"
   read answer
   if [ $answer = y ];
   then
      echo "##Dépôt Medibuntu" | sudo tee -a /etc/apt/sources.list
      echo "deb http://fr.packages.medibuntu.org/ hardy free non-free" | sudo tee -a /etc/apt/sources.list
      wget -q http://fr.packages.medibuntu.org/medibuntu-key.gpg
      sudo apt-key add medibuntu-key.gpg
      sudo apt-get update
      sudo apt-get install libdvdcss2
      sudo rm -rf medibuntu-key.gpg
   fi
fi

#******************************************************************************************
function track_rip()
{
# $1: physical optical disk
media_info=`lsdvd -q /dev/$1 2>/dev/null`
longest_track=`echo $media_info | grep "Longest track: "| awk -F ": " '{print $NF}'`
title_dvd=`echo $media_info | awk -F ":" '{print $2}'| awk -F " " '{print $1}'`
dvd_track_length=`mplayer -vo null -ao null -frames 0 -identify dvd://$longest_track -dvd-device /dev/$1 2>/dev/null | grep "ID_LENGTH=" | awk -F "=" '{print $NF}' | awk -F "." '{print $1}'`
dvd_track_lenght_min=$(( dvd_track_length / 60 ))
dvd_track_audio=`mplayer -vo null -ao null -frames 0 -identify dvd://$longest_track -dvd-device /dev/$1  2>/dev/null | grep "language: fr" | grep "audio"`
atrack=`mplayer -vo null -ao null -frames 0 -identify dvd://$longest_track -dvd-device /dev/$1  2>/dev/null | grep "language: fr" | grep "audio" | grep "ac3" | awk -F " " '{print $NF}' | awk -F "." '{print $1}'`

atrack_nb=`echo "$atrack" | wc -w`
if [ ! $atrack_nb = 1 ];
then
   atrack0=`echo $atrack` # supress \n for nice zenity look
   zenity --question --title="QUESTION" \
          --text="\nDVD Name:$title_dvd\nLongest Track:  $longest_track\nVideo Length:   $dvd_track_lenght_min min\n\nAudio ID-Track: Determined Next Step\n\nSettings except Audio (next step) correct?\n(If No, help: $0 -h)"
else
   zenity --question --title="QUESTION" \
          --text="\nDVD Name:$title_dvd\nLongest Track:  $longest_track\nVideo Length:   $dvd_track_lenght_min min\n\nAudio ID-Track: $atrack\n($dvd_track_audio)\n\nSettings correct?\n(If No, help: $0 -h)"
fi

if [  $? = 0 ];
then
   if [ ! $atrack_nb = 1 ];
   then
      atrack=`zenity --entry --title="INPUTS" \
                             --text="More than 1 Audio Track found, please select one in this list:\n$dvd_track_audio\n\nSettings correct?\n(If No, help: $0 -h)" --entry-text="$atrack0" 2>&1`
   fi

   if [  $? = 0 ];
   then
      if [ -e $title_dvd-$language_ID.mpg ];
         then
         zenity --question --title="QUESTION" \
                           --text=" Overwrite already existing file? \n"
         if [  $? = 0 ];
         then
            mplayer dvd://$longest_track -aid $atrack -dvd-device /dev/$1 -dumpstream -dumpfile $title_dvd-$atrack.mpg
         else
            exit
         fi
      else
         mplayer dvd://$longest_track -aid $atrack -dvd-device /dev/$1 -dumpstream -dumpfile $title_dvd-$atrack.mpg
      fi 
   else
      exit
   fi
fi
}

#******************************************************************************************
function drive_selection()
#
{
# Choice Box (between different drives (up to 3)
drive=`zenity  --title="Drive Selection" \
                --text="Choose correct Drive to use" \
                --list \
                --radiolist \
                --height="250" \
                --width="400" \
                --column="Selection" \
                --column="Drive" \
                --column="Description" \
                TRUE "dvd" "default"\
                FALSE "dvd1" "if exists"\
                FALSE "dvd2" "if exists"\
                | sed 's/ max//g'`

# case of cancel action
if [ "$drive" = "" ];
then
   exit
fi
}

#******************************************************************************************
function postshutdown()
{
# Shutdown at the end of process Choice Box
end_action=`zenity  --title="End Of Process Action" \
                    --text="Select If PC enter shutdown at the end of encoding" \
                    --list \
                    --radiolist \
                    --height="250" \
                    --width="500" \
                    --column="Selection" \
                    --column="Action" \
                    --column="descriptif" \
                    FALSE "Shutdown" "Shutdown at End Of Encoding Process (sudo only)" \
                    TRUE "No-Shutdown" "PC Stays On at End Of Encoding Process" \
                    | sed 's/ max//g'`

if [ "$end_action" = "Shutdown" ];
then
   zenity --question --title="INFO" \
                     --text="You must be sudo for requesting a end process shutdown"
   if [ $? = 1 ];
   then
      exit
   fi
else
   if [ "$end_action" = "" ];
   then
      exit
   fi

fi	
}

#******************************************************************************************
function duration()
{
# $1= Stop date
# $2= Start date
# $3 = log file
# date +%s gives duration between 1-01-1970 in seconds. Then easy for duration calculation
difference=$(( $1-$2 ))
hour=$(( difference/3600 ))
min=$(( (( difference/60 ))-$(( hour*60 )) ))                     
sec=$(( (( difference ))-$(( hour*3600 + min*60 )) ))          
echo "Process Duration = $hour hour $min minutes $sec seconds" >> "$3"
}

#******************************************************************************************

#******************************************************************************************
#************************* Main Program ***************************************************
#******************************************************************************************

#******************************************************************************************
# 1th step: what to be done end of global processing: shutdown or not
postshutdown

#******************************************************************************************
# 2nd step: collect drive info
drive_selection

#******************************************************************************************
# 3rd step: process
date_in=$(date +%s)
track_rip $drive
date_out=$(date +%s)

#******************************************************************************************
# 4rd step: report
log_encode_file="$title_dvd-$atrack-Rip.log"
echo $(date) > "$log_encode_file"
duration $date_out $date_in $log_encode_file


#******************************************************************************************
# 5th step: set final encoding action
# need to modify /etc/sudoers to get rights to shutdown PC though a script   

if [ "$end_action" = "Shutdown" ];
then
   sudo /sbin/shutdown -h now
fi
exit

Hors ligne

#8 Le 20/12/2011, à 23:37

thurston

Re : Script rip DVD en ligne commande

A noter que les protections de type A-R-C-C-O-S se gèrent comme ceci:
1. lecture VLC pour détermination de la bonne piste sur les 99 en général présentes
2. mplayer dvdnav://$correct_track -dvd-device /dev/cdrom -dumpstream -dumpfile DVD.mpg

Je joins une version en travail ci dessous...

#!/bin/bash
#########################################
# Script de Thurston / Ubuntu
# 
#########################################
# Nautilus script
# 
# Mplayer, zenity
#########################################
# Script Version: 02 (beta)
# Revision date:  2011-12-20
#
# Log
# *********************************************
# 02: Manage A-R-C-C-O-S in 2 possible ways: VLC + mplayer, or VLC + handbrake (to be installed both)
# 01: Better management of different same language tracks, with a 2nd step to choose correct one
# 00: Initial Version

# Variables initialisation
#******************************************************************************************

#help determining cd
#eject /dev/dvd
#sleep 15; eject /dev/cdrom; sleep 3; eject /dev/cdrom1; sleep 3; eject /dev/cdrom2; sleep 3; eject /dev/cdrom3; sleep 3; eject /dev/cdrom4; sleep 3; eject /dev/cdrom5

# ARCCOS protection: ./mplayer dvdnav://15
# Control of argument presence
#******************************************************************************************

# Handle options
#******************************************************************************************
while getopts "h" opt
do
   case $opt in
      h) # Help
         clear
         echo "usage: $0                              => sudo  if shutdown required"
         echo "usage: $0 [-h]                         => help"    
         echo "   *)Using Acidrip"
         echo "     -copy mode for Audio & Video"
         echo "     -Output= .mpg"
         echo "   *)Using DVD::Rip"
         echo "     -DVD Extraction"
         echo "     -Merge operation: cat 1.vob 2.vob > DVD.mpg"
         echo "   *)Using Command Line in a terminal"
         echo "     -DVD Info: lsdvd /dev/dvd"
         echo "     -Check correct file number x: mplayer dvd://x"
         echo "     -DVD Rip: mplayer dvd://x -dumpstream -dumpfile DVD.mpg or if n DVD players"
         echo "     -DVD Rip: mplayer dvd://x -dvd-device /dev/cdrom1 -dumpstream -dumpfile DVD.mpg"
         echo "   *)Using vobcopy"
         echo "     -vobcopy -m"
         echo "     -Note that sometimes, playing with -F (Fast) mode can help"
         echo "     -vobcopy -m -F x, with x in range [1..64]"
         echo ""
         echo "Notes:"
         echo "   *)mplayer, mencoder, libdvdcss, zenity proposed for auto-installation"
         echo "   *)a log file is created at the end of process"
         echo "   *)if launched using a ssh connexion:"
         echo "     - use ssh -X name@address, install xauth on remote computer"
         echo "     - use -ssh option when launching this script. It will removes the graphic"
         echo "       which makes the application to be auto-killed when closing ssh + screen"
         exit 1
         ;;
    esac

    # Remove option

    shift $((OPTIND - 1))
    OPTIND=1
done


#******************************************************************************************
# Control of minimum software requirements correctly installed
test -x /usr/bin/mplayer || sudo apt-get install mplayer -y
test -x /usr/bin/zenity || sudo apt-get install zenity -y
test -x /usr/bin/lsdvd || sudo apt-get install lsdvd -y

# Control of additionnal software correctly installed
#******************************************************************************************

if [ `test -x /usr/share/doc/libdvdcss2` ];
then
   echo "Do you want to proceed with libdvdcss2 installation? (y/n)"
   read answer
   if [ $answer = y ];
   then
      echo "##Dépôt Medibuntu" | sudo tee -a /etc/apt/sources.list
      echo "deb http://fr.packages.medibuntu.org/ hardy free non-free" | sudo tee -a /etc/apt/sources.list
      wget -q http://fr.packages.medibuntu.org/medibuntu-key.gpg
      sudo apt-key add medibuntu-key.gpg
      sudo apt-get update
      sudo apt-get install libdvdcss2
      sudo rm -rf medibuntu-key.gpg
   fi
fi


#******************************************************************************************
function track_rip()
{
# $1: physical optical disk
media_info=`lsdvd -q /dev/$1 2>/dev/null`
title_dvd=`echo $media_info | awk -F ":" '{print $2}'| awk -F " " '{print $1}'`


#anti_copy_sign=`echo $media_info | grep "Title: 99,"`
#if [ $anti_copy_sign = 0 ];
echo $media_info | grep -q "Title: 99,"
if [ $? = 0 ];
then
   zenity --question --title="INFO" \
                     --text="DVD highly protected (ARCCOS), it seems. VLC + Mplayer (recommended) process. Continue?"
   if [ $? = 0 ];
   then
      vlc /dev/$1
      correct_track=`zenity --entry --title="INPUTS" \
                            --text="VLC played ID track\n" 2>&1`
      mplayer dvdnav://$correct_track -dvd-device /dev/$1 -dumpstream -dumpfile $title_dvd.mpg
      audio_track=`zenity --entry --title="INPUTS" \
                            --text="Audio ID?\n" 2>&1`
      mv $title_dvd.mpg $title_dvd-$audio_track.mpg
      exit
   else
      zenity --question --title="INFO" \
                        --text="DVD highly protected (ARCCOS), it seems. VLC + Handbrake (last chance) process . Continue?"
      if [ $? = 0 ];
      then
         vlc /dev/$1
         correct_track=`zenity --entry --title="INPUTS" \
                               --text="VLC played ID track\n" 2>&1`
         ghb /dev/$1
         exit
      fi  
   fi
fi

longest_track=`echo $media_info | grep "Longest track: "| awk -F ": " '{print $NF}'`

dvd_track_length=`mplayer -vo null -ao null -frames 0 -identify dvd://$longest_track -dvd-device /dev/$1 2>/dev/null | grep "ID_LENGTH=" | awk -F "=" '{print $NF}' | awk -F "." '{print $1}'`
dvd_track_lenght_min=$(( dvd_track_length / 60 ))
dvd_track_audio=`mplayer -vo null -ao null -frames 0 -identify dvd://$longest_track -dvd-device /dev/$1  2>/dev/null | grep "language: fr" | grep "audio"`
atrack=`mplayer -vo null -ao null -frames 0 -identify dvd://$longest_track -dvd-device /dev/$1  2>/dev/null | grep "language: fr" | grep "audio" | grep "ac3" | awk -F " " '{print $NF}' | awk -F "." '{print $1}'`

atrack_nb=`echo "$atrack" | wc -w`
if [ ! $atrack_nb = 1 ];
then
   atrack0=`echo $atrack` # supress \n for nice zenity look
   zenity --question --title="QUESTION" \
          --text="\nDVD Name:$title_dvd\nLongest Track:  $longest_track\nVideo Length:   $dvd_track_lenght_min min\n\nAudio ID-Track: Determined Next Step\n\nSettings except Audio (next step) correct?\n(If No, help: $0 -h)"
else
   zenity --question --title="QUESTION" \
          --text="\nDVD Name:$title_dvd\nLongest Track:  $longest_track\nVideo Length:   $dvd_track_lenght_min min\n\nAudio ID-Track: $atrack\n($dvd_track_audio)\n\nSettings correct?\n(If No, help: $0 -h)"
fi

if [  $? = 0 ];
then
   if [ ! $atrack_nb = 1 ];
   then
      atrack=`zenity --entry --title="INPUTS" \
                             --text="More than 1 Audio Track found, please select one in this list:\n$dvd_track_audio\n\nSettings correct?\n(If No, help: $0 -h)" --entry-text="$atrack0" 2>&1`
   fi

   if [  $? = 0 ];
   then
      if [ -e $title_dvd-$language_ID.mpg ];
         then
         zenity --question --title="QUESTION" \
                           --text=" Overwrite already existing file? \n"
         if [  $? = 0 ];
         then
            mplayer dvd://$longest_track -aid $atrack -dvd-device /dev/$1 -dumpstream -dumpfile $title_dvd-$atrack.mpg
         else
            exit
         fi
      else
         mplayer dvd://$longest_track -aid $atrack -dvd-device /dev/$1 -dumpstream -dumpfile $title_dvd-$atrack.mpg
      fi 
   else
      exit
   fi
fi
}

#******************************************************************************************
function drive_selection()
#
{
# Choice Box (between different drives (up to 6)
drive=`zenity  --title="Drive Selection" \
                --text="Choose correct Drive to use" \
                --list \
                --radiolist \
                --height="300" \
                --width="400" \
                --column="Selection" \
                --column="Drive" \
                --column="Description" \
                TRUE "cdrom3" "Left-Top"\
                FALSE "cdrom" "Left-Middle"\
                FALSE "cdrom4" "Left-Bottom"\
                FALSE "cdrom2" "Right-Top"\
                FALSE "cdrom1" "Right-Middle"\
                FALSE "cdrom5" "Right-Bottom"\
                | sed 's/ max//g'`

# case of cancel action
if [ "$drive" = "" ];
then
   exit
fi
}

#******************************************************************************************
function postshutdown()
{
# Shutdown at the end of process Choice Box
end_action=`zenity  --title="End Of Process Action" \
                    --text="Select If PC enter shutdown at the end of encoding" \
                    --list \
                    --radiolist \
                    --height="250" \
                    --width="500" \
                    --column="Selection" \
                    --column="Action" \
                    --column="descriptif" \
                    FALSE "Shutdown" "Shutdown at End Of Encoding Process (sudo only)" \
                    TRUE "No-Shutdown" "PC Stays On at End Of Encoding Process" \
                    | sed 's/ max//g'`

if [ "$end_action" = "Shutdown" ];
then
   zenity --question --title="INFO" \
                     --text="You must be sudo for requesting a end process shutdown"
   if [ $? = 1 ];
   then
      exit
   fi
else
   if [ "$end_action" = "" ];
   then
      exit
   fi

fi    
}

#******************************************************************************************
function duration()
{
# $1= Stop date
# $2= Start date
# $3 = log file
# date +%s gives duration between 1-01-1970 in seconds. Then easy for duration calculation
difference=$(( $1-$2 ))
hour=$(( difference/3600 ))
min=$(( (( difference/60 ))-$(( hour*60 )) ))                     
sec=$(( (( difference ))-$(( hour*3600 + min*60 )) ))          
echo "Process Duration = $hour hour $min minutes $sec seconds" >> "$3"
}

#******************************************************************************************

#******************************************************************************************
#************************* Main Program ***************************************************
#******************************************************************************************

#******************************************************************************************
# 1th step: what to be done end of global processing: shutdown or not
postshutdown

#******************************************************************************************
# 2nd step: collect drive info
drive_selection

#******************************************************************************************
# 3rd step: process
date_in=$(date +%s)
track_rip $drive
date_out=$(date +%s)

#******************************************************************************************
# 4rd step: report
log_encode_file="$title_dvd-$atrack-Rip.log"
echo $(date) > "$log_encode_file"
duration $date_out $date_in $log_encode_file


#******************************************************************************************
# 5th step: set final encoding action
# need to modify /etc/sudoers to get rights to shutdown PC though a script   

if [ "$end_action" = "Shutdown" ];
then
   sudo /sbin/shutdown -h now
fi
exit

Dernière modification par thurston (Le 20/12/2011, à 23:57)

Hors ligne