检测“丢失视频".YouTube图片 [英] Detecting "Missing Video" Youtube Image

查看:70
本文介绍了检测“丢失视频".YouTube图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

未来穴居人的问候

我在页面上加载了许多YouTube缩略图.它们从我数据库中的缩略图URL加载.

I load a lot of youtube thumbnails on my page. They load from thumbnail urls I have in my db.

作者有时会在youtube上更改或删除相关视频.这给我留下了两个问题:

From time to time the video in question is changed or deleted by the author on youtube. This leaves me with 2 problems:

  1. 我正在从youtube加载空白图片

  1. 在我的数据库中,我仍然列出了此图片网址.

找出丢失的视频"缩略图,而不显示它,并更新我的数据库将是一个解决方案.我需要通过识别此图像来触发事件.请注意,这是默认的丢失"图像,可以显示不同的URL.因此,看到一个特定的URL不是一件简单的事情.

What would be a solution for figuring out the "missing video" thumnail, NOT displaying it, and updating my db. I need to fire an event by recognizing this image. Note that this is the default "missing" image that can appear different urls. So it's not a simple matter of seeing a particular url.

我还考虑过使用youtube api,但是每次页面加载时都会进行大量调用,这对我来说是违反直觉的.

I also thought of using youtube api but making a bunch of calls every time the page loads seems counterintuitive to me.

我需要检测图像并触发,所以甚至JS/jquery都可以通过ajax使用它来更新我的数据库.

I need to detect the image and fire so some of even for JS/jquery to use to update my db via ajax.

也许我想得太过分了,所以如果有人对我的问题有其他解决方案,我会开放的.

Maybe I'm overthinking this so if anybody has another solution to my problem I'm open.

但是上述解决方案似乎不合适.答案中的第一个选项是我现在正在做的事情,它不起作用-因为youtube会提供默认图像,即使您使用1.jpg或2等(我使用的是).视频基本上消失了.

But the solution above does not seem to fit. The first option in the answer is what I'm doing now and it doesn't work - because youtube serves the default image even when you use 1.jpg, or 2 etc.. (which is what I use). Basically the video is gone.

第二个选项(基于64位编码,创建canvas元素等)并未真正扩展,而似乎像是用电锯代替手术刀.

The second option (base 64 encoding, creating canvas element etcc) is not really expanded upon and seems rather like using a chainsaw in place of a scalpel.

谢谢

推荐答案

我发现如果我在使用

http://img.youtube.com/vi/<video_id>/mqdefault.jpg

它将显示修剪的YouTube缩略图(顶部和底部无黑色边框).尺寸为 320 x 180 px.

it will display the trimmed (no black borders at top and bottom) YouTube thumbnail. The dimensions of this are 320 x 180px.

如果没有可用的缩略图,您将获得YouTube的后备缩略图,但实际上是 120 x 90 px.

Whereas if there is no available thumbnail, you will get YouTube's fallback thumbnail, but that is actually 120 x 90px.

因此,这是一种更简单的方法来确定是否有无效的缩略图(与从< img> 标记中读取base64数据相比).

So here's a much easier way for figuring out if you got an invalid thumbnail (as compared to reading base64 data from the <img> tag).

希望这会有所帮助.

这篇关于检测“丢失视频".YouTube图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆