psubuntu logo
It is currently Tue Sep 07, 2010 1:34 pm
Register


Post new topic Reply to topic  [ 3 posts ] 
Author Message
Offline
 Post subject: [SCRIPT] YoutubeD - batch download
PostPosted: Wed Oct 07, 2009 11:44 pm 
User avatar
 Profile

Joined: Mon Sep 15, 2008 3:00 am
Posts: 356
Location: Japan
Image
> A script for downloading youtube videos with youtube-dl.
> A youtube video will download automatically if its url is copied to clipboard.
> Batch files must be saved as .txt file and must contain one url per line.

Pros
- Download straight from the clipboard (ctrl+c youtube_url + start_script)
- Batch download (loads youtube urls saved in a .txt file)
Cons
- FLV = Low res

Install

Install these if you don't already have them
Code:
sudo apt-get install curl xclip youtube-dl


Just copy YoutubeD code bellow, save it in a txt file (as youtubed.sh for instance) then open a terminal in the same folder and type
Code:
chmod a+x ./youtubed.sh
sudo cp ./youtubed.sh /usr/local/bin/


Have fun ;)

Cheers

YoutubeD Code
Code:
#!/bin/bash
#
# A script for downloading youtube videos with youtube-dl
# A youtube video will download automatically if its url is copied to clipboard
# Batch files must be saved as .txt file and must contain one url per line.
# Have fun ;)
#
# By defpy

IFS=$'\t\n'
AUTO_LOAD=${HOME}/.youtubed_load
LOG_FILE=${HOME}/.youtubed_log
LOG_BACKUP=${HOME}/.youtubed_log_bk
LOG_NOW=${HOME}/.youtubed_now
BATCH_CONFIG=${HOME}/.youtubed_batch

get_youtube()
{
   if [ "$#" -lt 1 ]; then
      echo "YouTube"
      FILE=$(xclip -o -selection clipboard);
      if [ "$(xclip -o -selection clipboard | awk '{ print index($0,"/v/") }')" != "0" ]; then
         FILE=$(xclip -o -selection clipboard | sed 's/\/v\//\/watch?v=/g');
      fi
   else
      echo "YouTube batch"
      FILE=$@
      if [ "$@ | awk '{ print index($0,"/v/") }')" != "0" ]; then
         FILE=$(echo "$FILE" | sed 's/\/v\//\/watch?v=/g');
      fi
   fi
   echo "$FILE"
   check_log
   TITLE=$(curl $FILE | awk '/<title>/' | cut -d '>' -f 2 | cut -d '<' -f 1);
   if [ -e "$LOG_NOW" ] && [ "$(head $LOG_NOW)" == "$TITLE" ]; then
      interface
   else    
      echo "$TITLE" >> $LOG_FILE
      echo "$TITLE" > $LOG_NOW
      if [ "$#" -lt 1 ]; then
         zenity --title="YoutubeD - Downloading video" --text="$TITLE"  --info --timeout 1
      fi
      youtube-dl -l $FILE && keep_log
   fi
}

start_check()
{
   if [ -e "$LOG_BACKUP" ] && [ "$(head $LOG_BACKUP)" == "finished" ]; then
      echo "Start"
      echo "" > $LOG_FILE
      echo "" > $LOG_BACKUP
      echo "" > $LOG_NOW
   fi
   auto_load "n"
}

auto_load()
{
   if [ $@ == "change" ]; then
      if [ "$(head $AUTO_LOAD)" == "on" ]; then
         echo "off" > $AUTO_LOAD
         zenity --title="YoutubeD - Settings" --text="Click'n'load - OFF"  --info --timeout 1
      elif [ "$(head $AUTO_LOAD)" == "off" ]; then
         echo "on" > $AUTO_LOAD
         zenity --title="YoutubeD - Settings" --text="Click'n'load - ON"  --info --timeout 1
      fi
      interface
   else
      if [ -e "$AUTO_LOAD" ] && [ "$(head $AUTO_LOAD)" == "on" ]; then
         start_youtubed
      elif [ -e "$AUTO_LOAD" ] && [ "$(head $AUTO_LOAD)" == "off" ]; then
         interface
      else
         echo "off" > $AUTO_LOAD
         interface
      fi
   fi
}

check_log()
{
   if [ -e "$LOG_FILE" ]; then
      echo "Log found"
   else
      echo "" > $LOG_FILE
   fi
}

batch_download()
{
   echo -e "\n" >> $BATCH_FILE
   while read LINK
      do
      TITLE=$(curl $LINK | awk '/<title>/' | cut -d '>' -f 2 | cut -d '<' -f 1);
      echo "$TITLE" >> $LOG_FILE
   done <$BATCH_FILE
   zenity --title="YoutubeD - Downloading batch" --text="Downloading youtube URLs from: $BATCH_FILE"  --info --timeout 1
   while read LINK
      do
      get_youtube $LINK   
   done <$BATCH_FILE
}

set_file()
{
   if [ -e "$BATCH_CONFIG" ]; then
      BATCH_FILE=$(head $BATCH_CONFIG);
   fi
   batch_download &
}

define_file()
{
   IFS=$'\t\n'
   echo "Batch text file"
   FILE_PATH=`zenity --file-selection --file-filter=*.txt  --title="Select a batch file"`
   case $? in
      0) echo "$FILE_PATH" > $BATCH_CONFIG && set_file;;
      1) zenity --warning --timeout 2 --text "YoutubeD\n\nFile selection cancelled" && interface;;
      -1) zenity --warning --timeout 2 --text "YoutubeD\n\nFile selection cancelled" && interface;;
   esac
   
}

keep_log()
{
   echo "" > $LOG_BACKUP
   while read LINE
      do
         if [ "$LINE" == "$TITLE" ]; then
            echo $LINE
         else
            echo "$LINE" >> $LOG_BACKUP
         fi
   done <$LOG_FILE
   grep -v '^$' $LOG_BACKUP > $LOG_FILE
   if [ "$(stat -c %s $LOG_FILE)" -lt 2 ]; then
      zenity --warning --timeout 2 --text "$TITLE \n download finished\n\n\nAll files downloaded"
      echo "finished" > $LOG_BACKUP
   else
      zenity --text-info --filename=$LOG_FILE --width=450 --height=200 --title="$TITLE download finished - Remaining files..." --timeout 2
   fi
}

interface()
{
   KEEP="$(zenity  --title "YoutubeD" --width=220 --height=275 --list  --text "YoutubeD\n\t\tA script for downloading Youtube videos with youtube-dl. \n\t\tVideos will download automatically if copied to clipboard.\n"  --radiolist --column " Option  " --column "    " TRUE "Youtube URL" FALSE "Select batch file" FALSE "Download queue" FALSE "Settings")"
   
   if [ "$KEEP" == "Youtube URL" ]; then
      while [ "${PIPESTATUS}" = "0" ]; do
         get_youtube
      done
   elif [ "$KEEP" == "Select batch file" ]; then
      define_file
   elif [ "$KEEP" == "Download queue" ]; then
      check_log
      if [ "$(stat -c %s $LOG_FILE)" -lt 2 ]; then
         zenity --warning --timeout 2 --text "All files downloaded"
         interface
      else
         zenity --text-info --filename=$LOG_FILE --width=450 --height=200 --title="YoutubeD - Remaining videos..."
         interface
      fi
   elif [ "$KEEP" == "Settings" ]; then
      auto_load "change"
   fi
exit 0;
}

start_youtubed()
{
LINK_HEAD="$(xclip -o -selection clipboard | awk '{ print substr( $0, 0, 5 ) }')"
LINK_DOMAIN="$(xclip -o -selection clipboard | awk '{ print index($0,"youtube.c") }')"
LINK="$(xclip -o -selection clipboard | awk '{ print index($0,"watch?v=") }')"
LINK_ALT="$(xclip -o -selection clipboard | awk '{ print index($0,"/v/") }')"
if [ "$LINK_ALT" != "0" ] && [ "$LINK_DOMAIN" != "0" ] && [ "$LINK_HEAD" = "http" ]; then
   get_youtube
elif [ "$LINK" != "0" ] && [ "$LINK_DOMAIN" != "0" ] && [ "$LINK_HEAD" = "http" ]; then
   get_youtube
else
   interface
fi
}
start_check

_________________
YoutubeD - batch download
FFPlayer [YouTube / Radio / Stream support included]
Little Tweaks[Update]


Top
 

Offline
 Post subject: and I when what is
PostPosted: Sat Aug 07, 2010 4:50 am 
 Profile

Joined: Thu Jul 15, 2010 2:10 am
Posts: 218
Lin smiled: "You see at him this wow gold line. generally sent before the children transmitted to us, you put him to alter it not refrain affect? Comin brought Baba's own, and I when what is buy wow gold new and the germinal or was he. Zhenzhen you are derisory. "The Personage laughed:" You right cheap wow gold upset it! this sanity I say it, everyone who comments a scuttlebutt unoriented. to displace you something, that is, to the
poorness to speak came play wow power leveling with a face, naturally, is to broadcast the girls to pair, and if something with them, which was gear told I originate, it is that a female, that is that a lover, that makes the wow account grouping rise to realize also hot, then author confused.


Top
 

Offline
 Post subject: cool!!!!!!
PostPosted: Thu Aug 12, 2010 7:53 pm 
 WWW  ICQ  Profile

Joined: Tue Aug 03, 2010 4:53 am
Posts: 89
cheap nike air
air max 1
air max 2009
air max 95


Top
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group  
Design By Poker Bandits