portal Michała Hanćkowiaka
Begin main content
lappend auto_path ~/tcl/tdom/bin; package re tdom; package re http; wm withdraw .; wm withdraw .output; wm geom .konsola 868x570+144+139;

## dostep do youtube z poziomy Tcl...
#

# ...

# wyciaganie tytulu filmu na podstawie ID
# + http://www.youtube.com/watch?v=A6mMzI5IZ84&feature=related
#

set h1 [http::geturl "http://gdata.youtube.com/feeds/api/videos/A6mMzI5IZ84"]
set d1 [dom parse -html [http::data $h1]]
  #% domDoc0x8223d78

$d1 delete
http::cleanup $h1

set d2 [$d1 selectNodes {//title}]
$d2 text
  #% Star Trek [2x11] Friday's Child (Part 4 of 5)

set d3 [$d1 selectNodes {//content}]
string map {\r {}} [$d3 text]
  #% Star Trek [2x11] Friday's Child (Part 4 of 5)

SUMMARY (Wikipedia)
The crew of the Enterprise become entangled in a planet's tribal power struggle.

PLOT (official page):
http://www.startrek.com/database_article/fridays-child

Original air date:
1967.12.01

Complete episode playlist:
http://www.youtube.com/view_play_list?p=9786F8B1C5C15126

Complete Star Trek list of episodes playlists:
http://www.facebook.com/note.php?note_id=116147785086064

set d4 [$d1 selectNodes {/entry/*}]
set _ {}
foreach x $d4 {lappend _ [$x nodeName]}
set _
  #% id published updated category category category category category category title content link link link link author

set d5 [$d1 selectNodes {/entry/author/*}]
  #% domNode0x8241d38 domNode0x8241d64
[lindex $d5 0] nodeName
  #% name
[lindex $d5 1] nodeName
  #% uri
[lindex $d5 0] text
  #% completestartrek
[lindex $d5 1] text
  #% http://gdata.youtube.com/feeds/api/users/completestartrek


# ...

# jak znalezc kolejne odcinki Pana Wolodyjowskiego ??? (z. dla PZR420 ?!?!?!?!)
# + problem z utf-8 ?
# + dodac wyszukiwarke yt do mojej strony z filmami ?!?!?!?!
# + docs: https://developers.google.com/youtube/2.0/developers_guide_protocol_api_query_parameters#Searching_for_Videos
#

set h1 [http::geturl "http://gdata.youtube.com/feeds/api/videos?q=Wolodyjowski"]
set d1 [dom parse -html [http::data $h1]]
set d2 [$d1 selectNodes {/feed/entry}]

array unset film
foreach e $d2 {
  set title [[$e selectNodes title] text]
  set title [encoding convertfrom utf-8 $title]
  if {[regexp {^(Pan Wolodyjowski|Pan Wo³odyjowski) *([0-9]+) *$} $title x1 x2 x3]} {
    set url [[$e selectNodes id] text]
    #_puts "$title\n  $url"
    set film($x3) [list $title $url]
  }
}

#array get film
lsort -integer [array names film]
  #% 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

set film(1)
  #% {Pan Wo³odyjowski 1} http://gdata.youtube.com/feeds/api/videos/oY-inJWSB-M
set film(2)
  #% {Pan Wolodyjowski 2} http://gdata.youtube.com/feeds/api/videos/mkaGF1Chh08
set film(3)
  #% {Pan Wolodyjowski 3} http://gdata.youtube.com/feeds/api/videos/ljIZc0ugOog

set x [lindex $film(3) 1]
  #% http://gdata.youtube.com/feeds/api/videos/ljIZc0ugOog
set i [string last / $x]; string range $x [expr {$i+1}] end
  #% ljIZc0ugOog

#http://www.youtube.com/watch?v=ljIZc0ugOog
  # + przez taki url mozna ogladac film !!!

set _ ""
foreach e [lsort -integer [array names film]] {
  set t [lindex $film($e) 0]
  set u [lindex $film($e) 1]
  set i [string last / $u]; set u2 [string range $u [expr {$i+1}] end]
  append _ "<a href=http://www.youtube.com/watch?v=$u2>$e</a>, "
}
set _
  # + mozna to wstawic do mojej strony z filamy yt !!

# ...

# wyszukiwanie info o filmach
# + klopot z powodu braku konsekwencji w tytulach itp...
#

#set q [http::formatQuery q "Woody Allen"]
#set q [http::formatQuery q "Woody Allen Sleeper"]
set q [http::formatQuery q "Woody|Allen Sleeper"]
set h1 [http::geturl "http://gdata.youtube.com/feeds/api/videos?$q"]
set d1 [dom parse -html [http::data $h1]]
set d2 [$d1 selectNodes {/feed/entry}]

wm deiconify .output; .output.t delete 1.0 end
array unset film
foreach e $d2 {
  set title [[$e selectNodes title] text]
  set title [encoding convertfrom utf-8 $title]
  set url [[$e selectNodes id] text]
  #_puts "$title\n  $url"
  if {[regexp {^Sleeper part *([0-9]+) *} $title x1 x2]} {
    _puts "$title ($x2)\n  $url"
    set film($x2) [list $title $url]
  }
}

# ...

uwaga: portal używa ciasteczek tylko do obsługi tzw. sesji...