lazyYT icon indicating copy to clipboard operation
lazyYT copied to clipboard

Unable to get video title

Open jaskaran27 opened this issue 9 years ago • 14 comments

The script is unable to get the video title for any video now. It shows https://youtube.com/devicesupport as the title for each video.

The same happens now in the official demo as well - http://works.daugilas.com/lazyYT/demo/fixed.html

jaskaran27 avatar May 07 '15 06:05 jaskaran27

Uh oh, looks like this is related to Google shutting down the Youtube v2 API today. I'll have to take a look at what the v3 API setup requires to see if it can be swapped out.

tylerpearson avatar May 07 '15 07:05 tylerpearson

New API requires registration and obtaining API key, which somehow makes it troublesome for less technical people

I was about to provide a PR that takes advantage of oEmbed endpoint which will not be deprecated any time soon and does not require API key:

$.getJSON('https://www.youtube.com/oembed?format=json&url=http://www.youtube.com/watch?v=' + id, function (data) 
  $('#lazyYT-title-' + id).text(data.title);
});

but Google does not provide CORS header for the main domain and request from javascript will fail. :-1:

Unless we find a way to fetch title without API key, I feel we may need consider adding it as a configuration option and fetching title via official API:

GET https://www.googleapis.com/youtube/v3/videos?part=snippet&id={VIDEO_ID}&fields=items%2Fsnippet(title)&key={YOUR_API_KEY}

Reference: https://developers.google.com/apis-explorer/?hl=en_US#p/youtube/v3/youtube.videos.list

lidel avatar May 09 '15 09:05 lidel

For now it would be nice if you could disable the title.

ruudboon avatar May 17 '15 15:05 ruudboon

I use this to just disable (hide) it, until a proper solution is found...

var elements = document.getElementsByClassName("html5-info-bar"); for(var i=0, l=elements.length; i<l; i++){ elements[i].style.display = 'none'; }

rorifree avatar May 23 '15 12:05 rorifree

I just requested api key and edited original js to fix it...

brownsugar avatar May 24 '15 12:05 brownsugar

how to get such an api key?

tim99-1977 avatar May 25 '15 10:05 tim99-1977

YouTube Data API (v3): https://developers.google.com/youtube/v3/ Obtaining authorization credentials: https://developers.google.com/youtube/registering_an_application

brownsugar avatar May 25 '15 11:05 brownsugar

I have a key etc, what exactly did you replace in the original js brownsugar to pull the new data?

I replaced the URL etc

https://www.googleapis.com/youtube/v3/videos?id=' + id + '&key=

jet2k avatar Jun 16 '15 03:06 jet2k

Here's my code:

$.getJSON('https://www.googleapis.com/youtube/v3/videos?part=snippet&id=' + id + '&key=YOUR_KEY', function (data) {
    $el.find('#lazyYT-title-' + id).text(data.items[0].snippet.title);
});

brownsugar avatar Jun 16 '15 04:06 brownsugar

ahh fantastic

my api url was a bit different, but most of all I had

 text(data.items[0].snippet.title.$t);  

thanks again, works now!

jet2k avatar Jun 16 '15 04:06 jet2k

@tylerpearson @ruudboon PR #39 Would add add the ability to hide the title.

Jmeyering avatar Jun 26 '15 15:06 Jmeyering

thx @brownsugar for the excellent workoing example.

mgrn0 avatar Jul 06 '15 08:07 mgrn0

Thanks everyone, especially those who already provided solutions. I have updated the plugin to work with Youtube API v3. Its here: https://github.com/Daugilas/lazyYT with few new options. Demo is updated as well.

Creating a PR in a moment.

Daugilas avatar Jul 08 '15 00:07 Daugilas

@Daugilas Thanks, this works perfectly.

jaskaran27 avatar Jul 29 '15 21:07 jaskaran27