thibaudgg / video_info

Get video info from Dailymotion, Vimeo, Wistia, and YouTube URLs.
https://rubygems.org/gems/video_info
MIT License
428 stars 132 forks source link

Add safe navigation for user_interaction_count #226

Closed Spone closed 10 months ago

Spone commented 10 months ago

Close #225

Spone commented 10 months ago

Not sure why I have a bunch of new VCR cassettes 🤔

markets commented 10 months ago

Hey @Spone 👋🏼

Yeah! The specs for this project are a bit hard to maintain. For example, for YouTube and Vimeo, we have 2 "versions" for each service: scraper or API.

I've fixed some stuff, mainly related to specs+VCR, here 👉🏼 #227. Could you please update your branch?

To fully run the specs locally, you need a couple of ENV vars in your machine (the ones related to Youtube and Vimeo apis). You can create those keys by yourself (docs), but I can also share with you the ones we are using for dev/testing (ping me via email at srmarc.ai@gmail.com and I'll send you the keys). The CI already uses them.

Spone commented 10 months ago

Thanks @markets! I emailed you for the keys. I updated my branch. Do I need to delete all cassettes that have been created in my PR?

markets commented 10 months ago

Sorry, I'm not really a VCR hardcore user 😅... I'm just using it here because the project was implemented this way when I started contributing. I think new cassettes are created when you add a new spec hitting a new URL, but to be sure, you can delete the new ones and run the specs again (if they appear again, this is probably the expected behavior).

Spone commented 10 months ago

I'm hitting 429 Too Many Requests responses when running the tests. I'll wait for a bit and retry.

Spone commented 10 months ago

Sorry, I'm not really a VCR hardcore user

Me neither, and I always get a bit confused with the default behavior...

Okay, I'm getting there, but I still have an odd behavior:

When running with the scraper, I get the following stats:

{"plays" => nil, "likes" => nil, "comments" => nil}

But when running with the API:

{"plays" => nil}

Is there a way to expect different things depending on the service used? Or should I aim at having the same output?

markets commented 10 months ago

Yes! Both implementations are a bit different, since info is not available in both versions:

Scraper: https://github.com/thibaudgg/video_info/blob/2a94d69c978b2c19257c9729278adaa901901f95/lib/video_info/providers/vimeo_scraper.rb#L122

Api: https://github.com/thibaudgg/video_info/blob/2a94d69c978b2c19257c9729278adaa901901f95/lib/video_info/providers/vimeo_api.rb#L72

In the specs, you can use the api_key var to check what version is running:

https://github.com/thibaudgg/video_info/blob/2a94d69c978b2c19257c9729278adaa901901f95/spec/lib/video_info/providers/vimeo_spec.rb#L1

Something like this 👇🏼 is probably enough:

if api_key
  ...
else
  ...
end  
Spone commented 10 months ago

Thanks for your help! I think it's ready for review :)

EDIT: Damn, the specs pass locally but fail in Github Actions :/

EDIT 2: The failures are in Youtube tests, not sure how to fix those.