Youtube Video Search/Downloader

Moderator: GeekShed.Net Staff

Youtube Video Search/Downloader

Postby Ford » Thu Feb 04, 2010 3:39 am

Image
This script will search Youtube and return the results to the dialog along with information about them and a preview image. At this point you can select either High Download or Low Download
to download the selected video with your default browser.
Alternately, if you know the link for a video you want, you can enter it in the search box and when you click [Search / Get] Your browser will download the video.
Example:
Put this in the search box and click [Search / Get] to download at high quality.
Code: Select all
http://www.youtube.com/watch?v=YgH5W-h00NQ

If you want to view the video information first only enter the video id.
Code: Select all
YgH5W-h00NQ


Getting started:
Load the script into remotes.
Right click the screen or any menu and select Youtube Video Downloader.
Enter some words in the search box and click search.
Click Play to Play the selected video.
Click Download to download.
Select the format you want to download in from the dropdown menu.
Your browser will be opened and you will be prompted to enter a filename.
**Note that you may have to add the file extension to the filename. ie. 3gp, flv or mp4.
**This will depend on the file type you selected from the download prompt.
Code: Select all
;Youtube Video Downloader by Ford_Lawnmower irc.GeekShed.net #Script-Help
menu * {
  Youtube Video Downloader: dialog $iif($dialog(Y_V_D),-v,-md) Y_V_D Y_V_D
}
alias -l YoutubeSearch {
  if ($sock(YoutubeSearch)) { sockclose YoutubeSearch }
  sockopen YoutubeSearch www.youtube.com 80
  sockmark YoutubeSearch $+(/results?search_type=&search_sort=video_avg_rating&aq=f&search_query=,$replace($1-,$chr(32),+))
}
On *:sockopen:YoutubeSearch: {
  if (!$sockerr) {
    did -r Y_V_D 3,13,17-20
    sockwrite -nt $sockname GET $sock($sockname).mark HTTP/1.0
    sockwrite -n $sockname Host: www.youtube.com
    sockwrite -n $sockname $crlf
  }
  else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
}
On *:sockread:YoutubeSearch: {
  if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  else {
    var %Youtube | sockread %Youtube
    if (No video results isin %Youtube) {
      did -a Y_V_D 3,13 No results were found for your search!
      hfree $sockname
      sockclose $sockname
    }
    elseif ($regex(%Youtube,/<h3><a href="\/watch\?v=([^"]*)" title="([^"]*)"/i)) {
      hadd -m $sockname id $regml(1)     
      hadd -m $sockname title $fix($regml(2))
    }
    elseif ($regex(%Youtube,/<a href="\/watch\?v=([^"]*)".*title="([^"]*)"/i)) {
      hadd -m $sockname id $regml(1)   
      hadd -m $sockname title $fix($regml(2))
    }
    elseif ($regex(%Youtube,/"video-long-title-([^"]*)".*title="([^"]*)"/i)) {
      hadd -m $sockname id $regml(1)   
      hadd -m $sockname title $fix($regml(2))
    }
    elseif ($regex(%Youtube,/<span class="username-prepend">.*<a href="\/user\/([^"]*)">/i)) hadd -m $sockname user $regml(1)
    elseif ($regex(%Youtube,/<span class="date-added">([^<]*)<\/span>/i)) hadd -m $sockname date $regml(1)
    elseif ($regex(%Youtube,/<span class="viewcount">([^<]*) views<\/span>/i)) {
      var %s $sockname
      GetThumb i3.ytimg.com $+(/vi/,$hget(%s,id),/default.jpg) YouTubeThumbs $+($calc($did(Y_V_D,13).lines + 1),.jpg)
      did -a Y_V_D 3,13 $hget(%s,title)
      did -a Y_V_D 19 $hget(%s,user)
      did -a Y_V_D 17 $regml(1)
      did -a Y_V_D 18 $hget(%s,date)
      did -a Y_V_D 20 $hget(%s,id)
    }
    elseif (</body> isin %youtube) {
      did -c Y_V_D 3,13,17-20 1
      hfree $sockname
      sockclose $sockname
      .timer 1 3 did -g Y_V_D 5 youtubethumbs/1.jpg
    }
  }
}
alias -l fix { return $regsubex($remove($replace($1-,&amp;,&,&quot;,"),amp;),/&#([0-9]{2});/gi,$chr(\t)) }
dialog Y_V_D {
  title "Youtube Video Downloader"
  size -1 -1 231 238
  option dbu
  edit "", 1, 4 11 173 10, autohs
  button "Search / Get", 2, 181 9 46 12
  combo 3, 2 40 90 9
  text "Results", 4, 100 31 127 8, center
  icon 5, 7 55 79 69
  text "Views:", 9, 4 134 25 8, right
  text "Added:", 10, 4 149 25 8, right
  text "User:", 11, 4 163 25 8, right
  text "Video ID:", 12, 4 177 25 8, right
  list 13, 100 40 126 175
  combo 17, 33 133 60 9
  combo 18, 33 148 60 9
  combo 19, 33 162 60 9
  combo 20, 33 176 60 9
  button "Download", 22, 144 219 39 12
  button "Play", 23, 188 219 39 12
  text "Video Title", 24, 2 31 90 8, center
}
On *:dialog:Y_V_D:Sclick:2,13,21-23: {
  if ($did == 2) && ($did($dname,1).text) {
    tokenize 32 $v1
    if ($regex($1,/.*youtube\.com\/watch\?v=[\S]{11}/Si)) { GetYoutubeGetLinks $left($gettok($1,2,61),11) }
    else { YoutubeSearch $1- }
  }
  elseif ($did == 13) {
    did -c $dname 3,17-20 $did(Y_V_D,13).sel
    did -g $dname 5 $+(youtubethumbs/,$did(Y_V_D,13).sel,.jpg)
  }
  elseif ($did == 22) && ($did(20)) { GetYoutubeGetLinks $v1 }
  elseif ($did == 23) { url -an $+(http://www.youtube.com/watch?v=,$did($dname,20).seltext) }
}
alias -l GetYoutubeGetLinks {
  var %sockname $+(Y.outubeGetLinks,yvdd,$ticks)
  sockopen %sockname www.youtube.com 80
  sockmark %sockname $+(/watch?v=,$1)
}
On *:sockopen:Y.outubeGetLinks*: {
  if (!$sockerr) {
    sockwrite -nt $sockname GET $sock($sockname).mark HTTP/1.0
    sockwrite -n $sockname Host: www.youtube.com
    sockwrite -n $sockname $crlf
  }
  else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
}
On *:sockread:Y.outubeGetLinks*: {
  if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  else {
    var %YoutubeGetLinks | sockread %YoutubeGetLinks
    if ($regex(%YoutubeGetLinks,/fmt_url_map=(.*?)&/)) {
      tokenize 44 $urldecode($regml(1))
      dialog $iif($dialog(Y_V_D_D),-v,-m Y_V_D_D) Y_V_D_D
      QualityCheck $*
      sockclose $sockname
    }
  }
}
alias -l urldecode return $regsubex($1-,/%([a-f\d]{1,2})/gi,$chr($base(\t,16,10)))
alias -l QualityCheck {
  if (*|http://* iswm $1) {
    var %quality $gettok($1,1,124), %link $gettok($1,2,124)
    if (%quality == 13) %quality = 3gp Low Quality:
    elseif (%quality == 17) %quality = 3gp Medium Quality:
    elseif (%quality == 36) %quality = 3gp High Quality:
    elseif (%quality == 5) %quality = flv Low Quality:
    elseif (%quality == 6) %quality = flv Low Quality:
    elseif (%quality == 34) %quality = flv High Quality (320p):
    elseif (%quality == 35) %quality = flv High Quality (480p):
    elseif (%quality == 18) %quality = mp4 High Quality (480p):
    elseif (%quality == 22) %quality = mp4 High Quality (720p):
    elseif (%quality == 37) %quality = mp4 High Quality (1080p):
    did -a Y_V_D_D 1 %quality %link
  }
  if ($dialog(Y_V_D_D)) did -c $v1 1 1
}
dialog Y_V_D_D {
  title "Youtube Download Selection"
  size -1 -1 162 66
  option dbu
  combo 1, 4 12 156 11, drop
  button "Download", 2, 66 51 37 12
  button "Close", 3, 114 51 37 12, cancel
}
On *:dialog:Y_V_D_D:Sclick:2: {
  if ($did(1)) url -an $gettok($v1,2-,58)
  dialog -x $dname
}
alias -l GetThumb {
  if ($isfile($qt($+($3,\,$4)))) { .remove $qt($+($3,\,$4)) }
  var %sockname $+(GetThumb,$ticks,$r(1,$ticks))
  if (!$isdir($qt($3))) { mkdir $qt($3) }
  sockopen %sockname $1 80
  sockmark %sockname $1-
}
On *:sockopen:GetThumb*:{
  sockwrite -nt $sockname GET $gettok($sock($sockname).mark,2,32) HTTP/1.0
  sockwrite -n $sockname Host: $gettok($sock($sockname).mark,1,32) $+ $crlf $+ $crlf
}
On *:sockread:GetThumb*:{
  if (!$gettok($sock($sockname).mark,5,32)) {
    var %GetThumb | sockread %GetThumb
    if (!%GetThumb) { sockmark $sockname $addtok($sock($sockname).mark,1,32) }
  }
  else {
    sockread &GetThumb
    bwrite -s $qt($+($gettok($sock($sockname).mark,3,32),\,$gettok($sock($sockname).mark,4,32))) -1 -1 &GetThumb
  }
}
Last edited by Ford on Sun May 01, 2011 8:09 pm, edited 1 time in total.
Ford
 
Posts: 48
Joined: Wed Oct 28, 2009 1:01 am

Re: Youtube Video Search/Downloader

Postby edgy » Sun Feb 07, 2010 2:30 pm

Nice script!

Have you posted this on Hawkee.com yet?
Image
Follow me on Twitter: http://twitter.com/edgy360
User avatar
edgy
 
Posts: 37
Joined: Sun Dec 27, 2009 11:29 am
Location: United Kingdom

Re: Youtube Video Search/Downloader

Postby Ford » Sun May 01, 2011 8:10 pm

Updated and working again.
Ford
 
Posts: 48
Joined: Wed Oct 28, 2009 1:01 am

Re: Youtube Video Search/Downloader

Postby Sumer » Sat Mar 21, 2015 5:38 am

I have updated the code above, Please have a look at it and let me know what you think.

Many thanks,
Sumer
 
Posts: 1
Joined: Sat Mar 21, 2015 5:26 am


Return to Script help

Who is online

Users browsing this forum: No registered users and 2 guests