Based off of http://www.hawkee.com/snippet/9043/
but a lot better
:)
creds to WASTED for helping a bit
dialog youtube {
title "Youtube Profile Stats"
size -1 -1 153 84
option dbu
edit "", 1, 6 4 147 58, read multi return autohs autovs vsbar
button "Get Stats", 2, 85 62 37 12
edit "", 3, 35 63 50 10, autohs autovs
button "", 4, 1 74 151 10
}
alias yt { dialog -m youtube youtube }
Menu channel,nicklist,query {
yt:/dialog -m youtube youtube }
on *:dialog:youtube:sclick:2:{
set %a $did(3).text
sockopen utube. $+ $r(1,9999) www.youtube.com 80
set %ytl http://www.youtube.com/user/ $+ $did(3).text
did -ra youtube 4 %ytl
did -r $dname 3
}
on *:dialog:youtube:sclick:4:{
run %ytl
}
on *:dialog:youtube:close:*:{ unset %a | unset %ytl | unset %nameset }
alias nohtml {
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, ,') | return %x }
on *:sockopen:utube.*:{
did -r youtube 1
if (!$sockerr) {
sockwrite -nt $sockname GET $+(/user/,%a) HTTP/1.1
sockwrite -nt $sockname Connection: close
sockwrite -nt $sockname Host: $+($sock($sockname).addr,$str($crlf,2))
}
else { did -a youtube 1 Socket Error $nopath($script) | sockclose $sockname | halt }
}
on *:sockread:utube.*:{
if (!$sockerr) {
var %ab = did -a youtube 1
var %sockreader | sockread %sockreader
if ($regex(%sockreader,/<div class="profile-info-value fn" id="profile_show_first_name">(.+?)</div>/)) { %ab $+ Name: $nohtml($regml(1)) | set %nameset $true }
if ($regex(%sockreader,/<div class="profile-info-value" id="profile_show_viewed_count">(.+?)</div>/)) {
if (!%nameset) %ab Name: %a
else unset %nameset
%ab $crlf $+ Channel Views: $regml(1)
}
if ($regex(%sockreader,/<div class="profile-info-value" id="profile_show_total_video_views">(.+?)</div>/)) %ab $crlf $+ Total Upload Views: $regml(1)
if ($regex(%sockreader,/<div class="profile-info-value" id="profile_show_age">(.+?)</div>/)) %ab $crlf $+ Age: $regml(1)
if ($regex(%sockreader,/<div class="profile-info-value" id="profile_show_member_since">(.+?)</div>/)) %ab $crlf $+ Joined: $regml(1)
if ($regex(%sockreader,/<div class="profile-info-value" id="profile_show_last_activity">(.+?)</div>/)) %ab $crlf $+ Latest Activity: $regml(1)
if ($regex(%sockreader,/<div class="profile-info-value" id="profile_show_subscriber_count">(.+?)</div>/)) %ab $crlf $+ Subscribers: $regml(1)
}
else { did -a youtube 1 Socket Error $nopath($script) | sockclose $sockname | halt }
}
Just though i'd post a dialog version i made :D
alias youtube {
if ($1) {
if ($sock(youtubed)) sockclose youtubed
dialog -mt youtube youtube
sockopen youtubed www.youtube.com 80
set %youtube $1
}
}
alias nohtml {
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x)
%x = $remove(%x, ,')
return %x
}
menu * {
Youtube Profile:{
dialog $iif($dialog(youtube),-v,-md) $&
youtube youtube
}
}
dialog youtube {
title "Youtube Profile Dialog"
size -1 -1 150 94
option dbu
box "Youtube Profile Info" 1, 5 5 140 84
text "Name:" 2, 10 14 20 10
text "" 8, 100 14 30 10
text "Subscribers:" 3, 10 24 30 10
text "" 10, 100 24 30 10
text "Channel Views:" 4, 10 34 40 10
text "" 9, 100 34 30 10
text "Total Upload Views:" 5, 10 44 50 10
text "" 13, 100 44 40 10
text "Latest Activity:" 6, 10 54 42 10
text "" 12, 100 54 40 10
text "Joined:" 7, 10 64 34 10
text "" 11, 100 64 40 10
}
on *:sockopen:youtubed:{
if ($sockeer) { echo -st Youtube: Connection Error }
else {
sockwrite -nt $sockname GET $+(/user/,%youtube) HTTP/1.1
sockwrite -nt $sockname Connection: close
sockwrite -nt $sockname Host: $+($sock($sockname).addr,$str($crlf,2))
}
}
on *:sockread:youtubed:{
if ($sockerr) { echo -st Youtube: Connection Error }
else {
var %sockreader | sockread %sockreader
if ($regex(%sockreader,/<div class="profile-info-value fn" $&
id="profile_show_first_name">(.+?)</div>/)) {
hadd -m youtube name $nohtml($regml(1))
did -a youtube 8 $hget(youtube,name)
}
if ($regex(%sockreader,/<div class="profile-info-value" $&
id="profile_show_viewed_count">(.+?)</div>/)) {
hadd -m youtube profile_viewed $regml(1)
did -a youtube 9 $hget(youtube,profile_viewed)
}
if ($regex(%sockreader,/<div class="profile-info-value" $&
id="profile_show_subscriber_count">(.+?)</div>/)) {
hadd -m youtube subscriber_count $regml(1)
did -a youtube 10 $hget(youtube,subscriber_count)
}
if ($regex(%sockreader,/<div class="profile-info-value" $&
id="profile_show_member_since">(.+?)</div>/)) {
hadd -m youtube joined $regml(1)
did -a youtube 11 $hget(youtube,joined)
}
if ($regex(%sockreader,/<div class="profile-info-value" $&
id="profile_show_last_activity">(.+?)</div>/)) {
hadd -m youtube activity $regml(1)
did -a youtube 12 $hget(youtube,activity)
}
if ($regex(%sockreader,/<div class="profile-info-value" $&
id="profile_show_total_video_views">(.+?)</div>/)) {
hadd -m youtube total_views $regml(1)
did -a youtube 13 $hget(youtube,total_views)
}
}
}
1 - how do you call it a lot of better when all you did, was put it into a dialog?
2 - if someone closes the dialog before the result, it will return an error
- /did: invalid parameters
3 - no error message in case of the user does not exist
4 - there are no checks to check if $did(3).text is $null, if not, clicking on button 4 it will return
- /run: insufficient parameters
5 - there is no need to set a var like this
set %ytl http://www.youtube.com/user/ $+ $did(3).text
a tip
if ($did == 4) && ($did(3).text != $null) {
url http://www.youtube.com/user/ $+ $did(3).text
}