javascript - 从图像标签数组中查找最高分辨率的 youtube 视频缩略图
问题描述
我可以使用类似 codepen 的东西来检索 youtube 图像缩略图信息,但我需要做的是找出 4 或 5 个缩略图分辨率,这是最高的。传统上,有 /mddefault、/maxresdefault、/sddefault 等。我想做的是尝试查看 /maxresdefault.jpg 是否存在,如果不存在,则查看 /hqdefault.jpg 是否存在等。我已经尝试过这篇文章,this post,this link以及其他一些方法,但是找不到查看图像是否存在的有效方法...我也尝试使用 jQuerys $.get(img_url)
,但有趣的是,即使图像存在,它也会返回为假。 .. 我能做些什么来从逻辑上确定 JS 中最高分辨率的缩略图是什么?
我还尝试使用正则表达式let regex = /\b(?:maxres|hq|sd|mq)\b/gi;
并遍历以查看存在的最高分辨率图像是什么。但无法确认该图像是否确实存在。
有谁知道最好的方法?
for (var i = 0; i < ytplayer.length; i++) {
// step 1 - check if there is maxresdefault.jpg
// step 1a - if true, save the data to the variable
var source = "https://img.youtube.com/vi/"+ ytplayer[i].dataset.embed +"/maxresdefault.jpg"; <===== try to get /maxresdefault.jpg
//step 2 - if false (how do we know), see if there is /hddefault.jpg, the sddefault.jpg, then mddefault.jpg
// step 2a - save to variable
解决方案
推荐阅读
- android - 无法让 ButterKnife 与 Android Studio 一起工作
- react-native - 如何在 react-native 中每次启动应用程序时增加 asyncStorage 值?
- node.js - 播放视频而不是在节点 js 中下载
- dart - Flutter ListView 删除和撤消操作
- javascript - 如何加载包含动态惰性模块的Angular库?
- javascript - 汉堡侧边栏 - 隐藏外部点击
- c# - C# 设计模式内带有边距设置的无边框表单
- ruby-on-rails - 如何从关联中过滤记录
- angular - 如何获取具有相同参数的嵌套对象数组
- java - 条件满足时 if 语句不打印正文