FabianBeiner / PHP-IMDB-Grabber

This PHP library enables you to scrape data from IMDB.com.
MIT License
271 stars 160 forks source link

NOT A BUG movie trailer inconsistency in embed... #168

Closed PrinceOfAbyss closed 2 years ago

PrinceOfAbyss commented 3 years ago

I'm so sorry for opening this issue @FabianBeiner and @bla0r when it's not an issue with this great project!

I'm just hoping for some insight on this problem I'm facing...

So, I'd like to be able to embed some trailers I'm acquiring through this class... I found this stock IMDb tool that even produces the embed code for you...

The produced code looks like this:

<iframe src="https://www.imdb.com/video/imdb/vi1462938649/imdb/embed?autoplay=false&width=480" width="480" height="270" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" frameborder="no" scrolling="no"></iframe>

Then I thought that by changing the vi9999999999 param in the iframe's source, I'd be able to get any other trailer embedded in my site... Wrong... Some videos play normally, while others complain about the x-frame-options: sameorigin directive/policy in effect...

If it didn't work at all, I'd perfectly understand that... But why does it work on some videos, and on some others it doesn't?

From the collection of iframes below, 50% of them work, while the other 50% don't...

<iframe src="https://www.imdb.com/video/imdb/vi2945515801/imdb/embed?autoplay=false&amp;width=640" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" scrolling="no" width="640" height="360" frameborder="no"></iframe>

<iframe src="https://www.imdb.com/video/imdb/vi1627823385/imdb/embed?autoplay=false&amp;width=640" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" scrolling="no" width="640" height="360" frameborder="no"></iframe>

<iframe src="https://www.imdb.com/video/imdb/vi2117384985/imdb/embed?autoplay=false&amp;width=640" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" scrolling="no" width="640" height="360" frameborder="no"></iframe>

<iframe src="https://www.imdb.com/video/imdb/vi3812212505/imdb/embed?autoplay=false&amp;width=640" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" scrolling="no" width="640" height="360" frameborder="no"></iframe>

<iframe src="https://www.imdb.com/video/imdb/vi1341915417/imdb/embed?autoplay=false&amp;width=640" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" scrolling="no" width="640" height="360" frameborder="no"></iframe>

<iframe src="https://www.imdb.com/video/imdb/vi4036933145/imdb/embed?autoplay=false&amp;width=640" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" scrolling="no" width="640" height="360" frameborder="no"></iframe>

<iframe src="https://www.imdb.com/video/imdb/vi1726152985/imdb/embed?autoplay=false&amp;width=640" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" scrolling="no" width="640" height="360" frameborder="no"></iframe>

<iframe src="https://www.imdb.com/video/imdb/vi4059824409/imdb/embed?autoplay=false&amp;width=640" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" scrolling="no" width="640" height="360" frameborder="no"></iframe>

<iframe src="https://www.imdb.com/video/imdb/vi719454489/imdb/embed?autoplay=false&amp;width=640" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" scrolling="no" width="640" height="360" frameborder="no"></iframe>

<iframe src="https://www.imdb.com/video/imdb/vi1392427289/imdb/embed?autoplay=false&amp;width=640" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" scrolling="no" width="640" height="360" frameborder="no"></iframe>

I'm totally confused about this. Can you shed some light on this please? TIA

FabianBeiner commented 3 years ago

This is probably not a bug, but explicitly set by IMDb. I guess they don't have the rights or permissions to show some trailers outside their site, so they might simply set the headers to disallow that.

However, the iframe sources you provided had some dead URLs in it. Simply, you can't view the src via direct link as well.

PrinceOfAbyss commented 3 years ago

This is probably not a bug, but explicitly set by IMDb. I guess they don't have the rights or permissions to show some trailers outside their site, so they might simply set the headers to disallow that.

However, the iframe sources you provided had some dead URLs in it. Simply, you can't view the src via direct link as well.

Honestly, I think it's a bit more complicated than that! Basically what I do is I take the vi video id that this class is scraping, and put it in the code provided by their stock embed feature (image below)...

Screenshot 2021-06-21 155052

It's that URL that is not working for some videos, while it works for others... Also, a URL that doesn't work in its 'embed' form, when you take out the 'embed' relevant part of it, it works just fine!!!

Take a look at the following URLs:

https://www.imdb.com/video/imdb/vi2945515801/imdb/embed?autoplay=false&amp&width=640 <- This doesn't work https://www.imdb.com/video/imdb/vi2945515801 <- But if you take out the embed part /imdb/embed?autoplay=false&amp&width=640 it redirects to the link below, which works fine https://www.imdb.com/video/vi2945515801 <- This works fine

Also for the embed links that work, ie the one below, you can replace the 2nd occurrence of imdb in the link, and it will still work. So all of the links below work just fine whether you put the iframes in a blank page, or use the iframes' src directly as an address

https://www.imdb.com/video/imdb/vi1726152985/imdb/embed?autoplay=false&amp;width=640 https://www.imdb.com/video/aaaaaa/vi1726152985/imdb/embed?autoplay=false&amp;width=640 https://www.imdb.com/video/bbbbbbbb/vi1726152985/imdb/embed?autoplay=false&amp;width=640 https://www.imdb.com/video/gggg/vi1726152985/imdb/embed?autoplay=false&amp;width=640 https://www.imdb.com/video/chair/vi1726152985/imdb/embed?autoplay=false&amp;width=640

FabianBeiner commented 3 years ago

Yeah, so there is probably nothing you can do. If IMDb doesn't allow/want you to embed the video, they will enforce that.

ahrahimi commented 3 years ago

All movies TrailerAsUrl: n/A why?

FabianBeiner commented 2 years ago

I've updated getTrailerAsUrl in https://github.com/FabianBeiner/PHP-IMDB-Grabber/commit/8d745276472181e1be9c559bc65d2b9317f50cb8, give it a try.