This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Youtube tcl - duration option

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
e
ege
Voice
Posts: 6
Joined: Thu Jul 25, 2013 10:23 pm

Youtube tcl - duration option

Post by ege »

hello,

i have this script by Ford_Lawnmower

https://pastee.org/ht3t7

how to add youtube video duration time spec into it ?

thank you.
W
WazzaUK
Voice
Posts: 19
Joined: Sun Jul 02, 2006 5:03 pm

youtube video duration

Post by WazzaUK »

This should help:

$youtubevar is the current line of http data

Code: Select all

set youtubeduration ""
if {[regexp -nocase {<meta itemprop=\"duration\" content=\"(.*?)\">.*} $youtubevar match youtubeduration]} {
  set youtubeduration "Duration: $youtubeduration"
  set youtubeduration [string map [list {PT} {} {M} {:} {S} {}] $youtubeduration]
}
I know this works.
W
WazzaUK
Voice
Posts: 19
Joined: Sun Jul 02, 2006 5:03 pm

Post by WazzaUK »

Heres an improved version... i know the code is a touch messy... Previous code wasnt 100% depending on the data from youtube...

Code: Select all

if {[regexp -nocase {<meta itemprop=\"duration\" content=\"(.*?)\">.*} $youtubevar match youtubeduration]} {
  set youtubelength $youtubeduration
  if {[regexp {M(.*?)S} $youtubevar match youtubeduration]} {
    set videosecs $youtubeduration
  }
  set youtubeduration $youtubelength
  if {[regexp {PT(.*?)M} $youtubevar match youtubeduration]} {
    set videomins $youtubeduration
  }
  set totalseconds [expr {($videomins * 60) + $videosecs}] 			
  set youtubeduration [clock format $totalseconds -format {%H:%M:%S}]
}
Ive re-written most of original code - has much more info and functionality...

YouTube URL check v1.01 by WazzaUK - based on v.0.01 by Ford_Lawnmower
W
WazzaUK
Voice
Posts: 19
Joined: Sun Jul 02, 2006 5:03 pm

Duration for Youtube

Post by WazzaUK »

Only just realised the previous code i provided doesnt work. Get invalid variable type for use with expr and +.

$data is http data, after proc completes $duration contains the duration.

Im sure the following code works, i use it in my youtube script.

Code: Select all

	if {[regexp -nocase {<meta itemprop=\"duration\" content=\"(.*?)\">.*} $data match duration]} {
  		set youtubelength $duration 
  		if {[regexp {M(.*?)S} $duration match duration]} { 
    			set videosecs $duration
  		} 
  		set duration $youtubelength 
  		if {[regexp {PT(.*?)M} $duration match duration]} { 
    			set videomins $duration
  		} 
		set totalseconds [expr {($videomins * 60) + $videosecs}]           
		set duration [clock format $totalseconds -format {%H:%M:%S}] 
	}
S
SoUkSoU
Voice
Posts: 13
Joined: Sat Jan 11, 2014 1:35 pm

Hey

Post by SoUkSoU »

Can you provide the full tcl with the duration in it ?

Regards,
W
WazzaUK
Voice
Posts: 19
Joined: Sun Jul 02, 2006 5:03 pm

Full tcl script with duration...

Post by WazzaUK »

User avatar
bunnybump
Voice
Posts: 9
Joined: Fri Aug 17, 2012 2:32 am
Contact:

Re: Full tcl script with duration...

Post by bunnybump »

regarding to WazzUK posted, i got this error when i tried to run it on my eggdrop. i've try this tcl but it keeps telling me that there's an error with the script. here what i got:

Code: Select all

 can't read "maxlen": no such variable
    while executing
"string is integer -strict $maxlen"
    invoked from within
"if  {[string is integer -strict $maxlen]} {
           if {($maxlen == "") || ($maxlen < 1)} {set maxlen 100}
        } else { set maxlen "100" }"
    (file "scripts/you.tcl" line 50)
what should i do to fix it? thank you in advance for the help.
In the Beginning... Was the Command Line
Post Reply