How to handle youtube deleted videos using youtube api from json request

元气小坏坏 提交于 2019-12-11 23:16:30

问题


I want to get youtube videos from youtube api using json request. Now i get videos from youtube using json. Example the url have some deleted videos (http://www.youtube.com/watch?v=MlOHWLqgcoY&list=PLD62D6701B15FD3E1) but i get only playing videos not deleted videos. Is it possible or any other way to handle youtube deleted videos using json results.

This is my code to get youtube videos

string getPlaylistVideoUrl = https://gdata.youtube.com/feeds/api/playlists/PLD62D6701B15FD3E1?v=2&safeSearch=strict&orderby=position&start-index=1&max-results=25&alt=json;
var webRequest = (HttpWebRequest)WebRequest.Create(getPlaylistVideoUrl);
using (WebResponse response=await webRequest.GetResponseAsync())
using (Stream responseStream=response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
{
   var jsonResult = reader.ReadToEnd();
   var videosList = JsonConvert.DeserializeObject<YouTubeVideosByPlaylist>(jsonResult);
   if (videosList.Feed != null)
   {
      if (videosList.Feed.Entry != null)
      {
           //Add entries to class
      }
}

Thanks in advance.


回答1:


i solve the youtube deleted videos problem. if you get the playlist to given format=6 in the youtube api Url.

string getPlaylistVideoUrl = https://gdata.youtube.com/feeds/api/playlists/PLD62D6701B15FD3E1?v=2&safeSearch=strict&orderby=position&start-index=1&max-results=25&alt=json&format=6;



回答2:


Videos that are not playable will normally have app$control elements set in their JSON response when retrieved using v2 of the Data API. Here's an example of what to look for in your response JSON:

"app$control": {
 "app$draft": {
  "$t": "yes"
 },
 "yt$state": {
  "$t": "This video is not available in your region.",
  "name": "restricted",
  "reasonCode": "requesterRegion"
 }
}

There are other reasons why a video might not be playable in a given playback scenario, so the absence of app$control doesn't ensure that the video can always be played. But if app$control is there, then the video can't be played.




回答3:


From the Google documentation "If a video is not playable, the entry for that video will not contain a <media:content> tag. In addition, the entry may contain an <app:control> tag that contains an explanation of why the video is not playable"

https://developers.google.com/youtube/2.0/developers_guide_protocol_testing



来源:https://stackoverflow.com/questions/15170814/how-to-handle-youtube-deleted-videos-using-youtube-api-from-json-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!