2

I have a script that uses the YouTube API (v3) to find a video of a music from the name of the artist and the name of the music.

This works, however, in some cases, the first choice (sorted by relevance) is not the official video VEVO.

I tried adding VEVO in my query (after name of the artist and name of the music), but when there is no video VEVO, the API returns no results.

Is it possible to force to choose VEVO videos, if they exist?

Thank you.

Vincent

0

3 Answers 3

2
var request = gapi.client.youtube.search.list
({
    q: artiste+' '+track,
    part: 'snippet',
    order: 'relevance'
});

request.execute(function(response) 
{
    idVideo=response.result.items[0].id.videoId;
});

This is the part that allows to select the id of a video based on the artist's name and the name of the music

0

UPDATE: I don't think the syndicated video suggesting I put below would work well but I'll leave it there just in case you want to explore it. What might work better, again not guaranteed but should be more accurate just hoping for the best would be to simply sort it by viewCount instead of relevance... Generally speaking, the VEVO videos have the most views.

Example: https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet&order=viewCount&q=nicki+minaj+anaconda&type=video&_h=3&

GET https://www.googleapis.com/youtube/v3/search?part=snippet&order=viewCount&q=nicki+minaj+anaconda&type=video&key={YOUR_API_KEY}

--

ORIGINAL ANSWER

I haven't been able to test it yet and it won't necessarily restrict it to ONLY vevo videos but you can try the syndicated option https://developers.google.com/youtube/v3/docs/search/list#videoSyndicated

string
The videoSyndicated parameter lets you to restrict a search to only videos that can be played outside youtube.com. If you specify a value for this parameter, you must also set the type parameter's value to video.

Acceptable values are:
any – Return all videos, syndicated or not.
true – Only retrieve syndicated videos.

If that returns nothing, than do the same search without syndicated and use the first option from that.

0

It is actually pretty easy. What you need to do is add 'VEVO' to you search query. This will make sure that anything from a VEVO channel will be the first result. It should look something like this.

var request = gapi.client.youtube.search.list
({
    q: artiste+' '+track + 'VEVO',
    part: 'snippet',
    order: 'relevance'
});

If you wan't to make sure you are getting a VEVO video the easiest thing to do is parse the channel title to make sure it contains the word "VEVO". The Code would then look something like this

var request = gapi.client.youtube.search.list
({
    q: artiste+' '+track + 'VEVO',
    part: 'snippet',
    order: 'relevance'
});
  var obj = JSON.parse(result.content);
  var findChannelTitle = obj.items[0].snippet.channelTitle;
  var isVevo = findChannelTitle.match(/VEVO/g); //checks to see if this is VEVO content. We only wan't to use Vevo videos. 
  if (isVevo){ //returns true if VEVO is found in the channel title
    var youtubeVideoId = obj.items[0].id.videoId; //finds the video ID
    return youtubeVideoId;
  }else{
    return null;
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.