Version 0 of iTube

Updated 2013-09-04 11:46:19 by suchenwi

Richard Suchenwirth 2013-09-04 - YouTube is a popular provider of streaming videos. With a tool like youtube-dl we can also download such a video to a file, just in case internet connection is slow, or a video might disappear in the future.

Operation is easy enough:

 1. right-click the YT title, select "Copy link target" from menu
 2. in a terminal, type: youtube-dl -o "%(stitle)s.%(ext)s" 
 3. after that, paste the URL into the terminal, Return

However, I wanted it even easier. The following little script brings up a text window, and checks the clipboard every second. If its contents look like a YouTube URL, it does steps 2. and 3., and logs the video title in its window. The output of youtube-dl is logged in the terminal (on my Lubuntu system at least), so you can see the details.

 #!/usr/bin/env tclsh
 package require Tk 8.5

 proc main argv {
    global g
    array set g {urls {} text .t}
    pack [text $g(text) -wrap word] -fill both -expand 1
    $g(text) insert end "Youtube downloads from clipboard:\n\n"

    every 1000 check_clipboard
 }
 proc every {ms body} {eval $body; after $ms [info level 0]}

 proc check_clipboard {} {
    global g
    if [catch {selection get} cb] return
    if [regexp youtube.com/watch $cb] {
        if {$cb ne "" && $cb ni $g(urls)} {
            set title [exec youtube-dl -e -o %(stitle)s.%(ext)s $cb]
            $g(text) insert end $title\n
            $g(text) see end
            exec youtube-dl  -o %(stitle)s.%(ext)s $cb &
            lappend g(urls) $cb
    }
 }

 main $argv

====