Cecil Westerhof <
Ce...@decebal.nl> wrote:
> At the moment I have two scripts where I do something with a YouTube
> URL: in one I play the video with mpv in the other I download it with
> youtube-dl.
>
> For this I wrote the following proc:
> proc ::dcblUtilities::getYouTubeURL {URL} {
> # for playing/downloading use:
> # set startURL
https://www.youtube.com/watch?v=
> # "{startURL}${id}[dict get ${YouTubeURL} identifier]"
> dict set YouTubeURL original ${URL}
> dict set YouTubeURL valid False
> set expression {[\?&]v=([-a-zA-Z0-9_]{11})(&|$)}
> set startURL
https://www.youtube.com/watch?
> set length [string length ${startURL}]
>
> if {${startURL} == [string range ${URL} 0 [incr length -1]]} {
> if {[regexp ${expression} ${URL} _ identifier]} {
> dict set YouTubeURL identifier ${identifier}
> dict set YouTubeURL valid True
> }
> }
> return ${YouTubeURL}
> }
>
> Can I improve on this?
>