坚持迁移到youtube api v3

时间:2015-05-25 08:39:19

标签: javascript api youtube

所以我试图在我的psp中为youtube创建一个脚本,当我尝试播放它时崩溃。

var YouTube = new Object();
YouTube.rev = 4;
YouTube.SearchDesc = "YouTube by NT and JCRV";
YouTube.Name = "YouTube";
YouTube.Search = function(keyword, page) {
  var result = new Object();
  result.bypage = 20;
  result.start = (page - 1) * result.bypage + 1;
  var sortBy = "relevance";
  var catSpecified = false;

  if (keyword.charAt(0) == '$')
  {
    var keywordBu = keyword;
    var kpos = keyword.indexOf(" ");
    var category = keyword.substring(1, kpos);
    keyword = keyword.substring(kpos + 1);
    catSpecified = true;
  }

  if (keyword.charAt(0) == '@')
  {
    sortBy = "published";
  }


  if (catSpecified == false)
  {
    c = GetContents('https://www.googleapis.com/youtube/v3/search?q=' + escape(keyword) + '&maxResults=' + result.bypage + '&order=' + sortBy + '&part=snippet&key=AIzaSyD6Bdt4uJP0ewhNtgagGbSszfrYqcx6ydU');
  }
  else
  {
    c = GetContents('https://www.googleapis.com/youtube/v3/search?q=' + escape(keyword) + '&maxResults=' + result.bypage + '&order=' + sortBy + '&part=snippet&key=AIzaSyD6Bdt4uJP0ewhNtgagGbSszfrYqcx6ydU');
  }

  result.total = ext("<openSearch:totalResults>");
  result.VideoInfo = new Array();
  v = {attr: 2};
  v.id = 0;
  v.Title = "YouTube Search Help";
  v.Description = "@query = search by upload date\n$category query = search in a category";
  v.URL = '';
  p = 0;
  result.VideoInfo.push(v);
  while (p = c.indexOf("<entry", p) + 1) {
    v = {attr: 2};//neither IDA|npp find this string ...0=RD 1= 2=SRD 3=S
    v.id = ext("https://www.googleapis.com/youtube/v3/videos?id=", "&key=AIzaSyD6Bdt4uJP0ewhNtgagGbSszfrYqcx6ydU&part=snippet,contentDetails,statistics,status&forMine=true&type=video");
    v.Title = ext("<title type='text'>");
    v.Description = ext("content type='text'>") + '\nUploader:' + ext("<name>");
    v.CommentCount = ext("statistics.commentCount='") * 1;
    v.Tags = ext("keywords>").replace(/,/g, "");
    v.LengthSeconds = ext("contentDetails.duration='") * 1;
    v.RatingAvg = ext("contentDetails.contentRating='") * 1;
    v.RatingCount = ext("statistics.likeCount='") * 1;
    v.MylistCount = ext("statistics.favoriteCount='") * 1;
    v.ViewCount = ext("statistics.viewCount='") * 1;
    v.ThumbnailURL = 'http://i.ytimg.com/vi/' + v.id + '/default.jpg';
    v.SaveFilename = v.id + ".flv";
    v.URL = 'YouTube.play("' + v.id + '")';
    result.VideoInfo.push(v);
  }
  result.end = result.start - 1 + result.VideoInfo.length;
  return result;
}


YouTube.play = function(id) {
  var pos;
  c = GetContents("http://www.youtube.com/get_video_info?html5=1&video_id=" + id);
  //PSPTube.log("\n" + c + "\n");
  pos = c.indexOf("url_encoded_fmt_stream_map");
  if (pos == -1) {
    alert("Can not be played");
    return "";
  }
  c = ext('url_encoded_fmt_stream_map', "&");
  p = 0;
  c = unescape(c);
  var url = c.match(/url=(.+?itag%3D5.*?)[&,]/);
  //PSPTube.log("\n" + url + "\n");
  url = url[1];
  //PSPTube.log("\n" + url + "\n");
  pos = url.lastIndexOf("http");
  url = url.substr(pos);
  url = unescape(url);
  //PSPTube.log("\n" + url + "\n");
  return url;
}
SiteList.push(YouTube);

0 个答案:

没有答案