#! /bin/bash # Copyright © 2006 Andrew Wigglesworth. # ecadre@yahoo.co.uk | http://www.andrew-wigglesworth.co.uk # # Modified to make script handle multiple url forms, or direct code. It will also save final file to path relative to directory where script started. # Copyright © 2007 Matthew Flaschen # # Copying and distribution of this file, with or without modification, # is permitted in any medium without royalty provided the copyright # notice and this notice are preserved. # ---------------------------------- # # This line and below are not part of the copyright notice or licence. # # ytplay version 0.2-1 05/02/2008. # # Playing Youtube videos on gNewSense GNU/Linux # # usage: # # To play a Youtube video, go to the page where the video is # on Youtube.com and copy it's URL. # # ytplay http://www.youtube.com/watch?v=code_from_youtube # # to save the Youtube video to your desktop, use the following # # ytplay http://www.youtube.com/watch?v=code_from_youtube -o file_type file_name # # File type is either flv or theora. File name is what you # would like to call the downloaded file. You do not need to # add the .flv or .ogg extentions as these will be added automatically. # # The Youtube web pages may change their format at any time meaning that # this script will have to be adapted. # # see http://www.ecadre.co.uk for more information. mkdir ~/.ytplay # clear up any old temporary files. This is just housekeeping, not security. rm -rf ~/.ytplay/ytplay.* # create a random temporary directory. Script will exit if directory already exists. tmp="`mktemp -d -p ~/.ytplay "ytplay.XXXXXXXX"`" || exit 1 # preserve original directory origDir=$(pwd) cd $tmp baseUrl="http://www.youtube.com/watch?v=" #Assume code given directly if [[ $(expr match $1 'http') -eq 0 ]]; then url=$baseUrl$1 else #This form of url is used for embedded flash objects embedId=$(expr match $1 'http\:\/\/www\.youtube\.com\/v\/') if [[ $embedId -gt 0 ]]; then url=$baseUrl${1:$embedId} else url=$1 fi fi wget $url -O yt-extract.txt grep /watch_fullscreen?fs yt-extract.txt >> yt-extract2.txt sed -e 's/var fs = window.open(//g' -e 's/watch_fullscreen//g' -e 's/ //g' -e 's/ //g' -e 's/"//g' yt-extract2.txt >> yt-extract3.txt read ytdownload