End time gets lost in a YouTube URL to a copyrighted video

133 Views Asked by At

I'm having trouble with video clip end times in deep links into YouTube.

You may have watched the YouTube URL structure evolve over the decades; there are plenty of Q&As on Stack Overflow on the general subject. I think I've tried them all. But this seems to be a hole in the system, or more likely in my knowledge.

Context:

My JS code builds a linked thumbnail HREF'ing into YouTube. First it creates an IMG element, sets its source attribute to the thumbnail image, sticks this image inside an A element with the intention that a user, clicking the thumbnail image, should browse over to YouTube to watch the linked clip. The HREF attribute of the A anchor holds the link into YouTube. So far so good. However...

Problem:

YouTube's "embed" links, following a format like this,

https://www.youtube.com/watch?v=$VIDEOID&start=$STARTIME&end=$ENDTIME

ought to work, and often do. For example:

https://www.youtube.com/embed/VIrRz6uq95c?start=59&end=67&autoplay=1

brings up a browser window which plays the desired clip and starts and stops at the desired times.

However, an identically structured URL with a different video id like this,

https://www.youtube.com/embed/JohQ4_mI27Y?start=65&end=92

fails with a comment, "Video Unavailable. Watch on YouTube".

Apparently the copyrighted (Star Trek) content must be watched using a different URL, the kind that includes the string "watch" rather than "embed" as follows:

https://www.youtube.com/watch/v=JohQ4_mI27Y?start=65&end=92

(with or without autoplay=1). The "watch" link, however, upon loading, translates itself to a URL like this,

https://www.youtube.com/watch/v=JohQ4_mI27Y&t=65

thus keeping the start time parameter under the parameter name, t, and losing the end time parameter entirely.

Question:

What URL can I insert as the HREF value for a link into YouTube that doesn't lose the end time?

Background Homework:

I did find and read this:

https://developers.google.com/youtube/player_parameters#end

And I've tried the following (JavaScript) url constructions (using variables vid,st,et for video id, start time and end time):

url='https://www.youtube.com/watch?v=' + vid + "&start=" + st + "&end=" + et; 
// self-translates deleting end= parameter.                                                                               

url='https://www.youtube.com/watch?v=' + vid + "#t=" + st + "s"; 
// old version; now it's &t=59s rather than #t=59s but in any case no *end* time.

url='https://www.youtube.com/embed/' + vid + "?start=" + st + "&end=" + et;                                                                                            
// denies service, apparently for copyright reasons, for some class of vid's.
// the error page offers a "watch" link to the video with neither start nor end times. Useless.

url='http://youtu.be/' + vid;      
// youtu.be is purposely a URL *shortener*, so no parameters are allowed.                                                                                                                                  

url='https://www.youtube.com/v/' + vid + "&start=" + st + "&end=" + et;                                                                                                
// self-translates to watch?v=$VIDEOID with neither start nor end times.

// and (stupidly)
url='<iframe id="ytplayer" type="text/html" '                                                                                                                         
            + 'width="640" height="360" '                                                                                                                                        
            + 'src="https://www.youtube.com/embed/' + vid                                                                                                                         
            + "?autoplay=1&start=" + st                                                                                                                                          
            + "&end=" + et                                                                                                                                                       
            + '" frameborder="0"></iframe>';                                                                                                                                     
// This iframe is not an HREF target to click through to, but an entire in-page player. 

I don't really want my nice simple auto-generated page of thumbnails to become a giant one-page bimodal web app that hides everything under a whole-screen iframe player and then reverts when the play is finished. I'd prefer not to build, and have responsibility for, a whole JS player UI inside my page; YouTube does a fine job at this, so I want to link over to where users could themselves go and could themselves click start and stop if they wanted to. Besides the UI design and coding work I'm not looking forward to, YouTube's API terms of service seem onerous; they own everything you do, if you agree to it.

Is my request too much to ask? Is there some business reason this is impossible? Or have I just missed some key point in the documentation?

0

There are 0 best solutions below