#!/bin/bash # moviejoin: Gnome Nautilus script for joining avi and mpeg movie clips # partial movie clips get moved to Trash after successful completion # version: 1.0beta # depends on: avimerge, mpgtx (mpgjoin), file, [gdialog] # author: Fernando Fernandez Pedraza, http://www.fpedraza.com # license: GPL, see http://www.gnu.org/copyleft/gpl.html # to-do: process more file formats with some extra conversion utilities # options: edit the appropriate variables below to change options. # askfilename : asks user for outputfilename or not. if not, the # output filename is the first filename with the 'suffix' # appended to basename # usegdialog : uses gdialog or not. (can be used from command line and/or # non-graphical mode. # suffix: see 'askfilename' above. # # order of file joining: uses order in Nautilus screen, you might need # to experiment a little for getting correct results. askfilename=1 usegdialog=1 suffix="-joined" shopt -s nullglob i=1 error=0 list="" filebase="" fileext="" function printerror { # $1=error type # $2=use gdialog or not errorstring[1]="error: file types differ" errorstring[2]="error: file type not supported" if [[ $2 = 0 ]] ; then echo ${errorstring[$1]} else gdialog --title "moviejoin" --msgbox "${errorstring[$1]}" 100 100 fi } # get info about files for file in $@ do pat=`file -b "$file"` filetype[$i]=${pat:0:4} if [[ $i = 1 ]] ; then firstfilename=$file filebase=${file%%.*} fileext=${file#*.} fi # compare all file types with type of file no. 1 if [[ ${filetype[i]} = ${filetype[1]} ]] ; then list=`echo \"${file}\" ${list}` else error=1 break [2] fi ((i++)) done # join files if [[ $error != 1 ]] ; then if [[ $askfilename = 1 ]] ; then outputfile=`gdialog --title "moviejoin" --inputbox "Output filename:" 100 100 2>&1` else outputfile=`echo ${filebase}${suffix}.${fileext}` fi if [[ ${filetype[1]} = RIFF ]] ; then command="avimerge -i ${list} -o ${outputfile}" elif [[ ${filetype[1]} = MPEG ]] ; then command="mpgjoin -o ${outputfile} ${list}" else command="printerror 2 $usegdialog" fi #gdialog --msgbox "${list}" eval $command # if outputfile exists and nonzero move input files to trash if [[ -s ${outputfile} ]] ; then eval "mv ${list} ${HOME}/.Trash/" ; fi else printerror 1 $usegdialog fi