Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', 'head']
ruby: ['3.2', '3.3', '3.4', '4.0', 'head']
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler: '4'
bundler-cache: true
- name: Run tests
run: bundle exec rspec
Expand All @@ -39,6 +40,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: StandardRB Linter
uses: amoeba/standardrb-action@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: standardrb/standard-ruby-action@v1
with:
ruby-version: '4.0'
autofix: false
1 change: 1 addition & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby_version: 4.0
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ source "http://rubygems.org"
gemspec

# Temporal Ruby 3.4 support, see more: https://github.com/vcr/vcr/pull/1003
gem 'base64'
gem "base64"
8 changes: 3 additions & 5 deletions lib/video_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def provider_api_keys=(api_keys)
end

def logger
@logger ||= Logger.new($stdout).tap do |lgr|
lgr.progname = name
end
@logger ||= Logger.new($stdout, progname: name)
end
end

Expand All @@ -56,8 +54,8 @@ def initialize(url, options = {})
@provider = _select_provider(url, options)
end

def self.get(*args)
new(*args)
def self.get(*)
new(*)
end

def self.usable?(url)
Expand Down
10 changes: 7 additions & 3 deletions lib/video_info/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,13 @@ def _embed_url(options)
url_attrs = options.fetch(:url_attributes, {})
url_attrs = _default_url_attributes.merge(url_attrs)

url = embed_url
url += "?#{_hash_to_params(url_attrs)}" unless url_attrs.empty?
url
return embed_url if url_attrs.empty?

uri = URI.parse(embed_url)
existing_params = uri.query ? URI.decode_www_form(uri.query).to_h : {}
merged_params = existing_params.merge(url_attrs.transform_keys(&:to_s))
uri.query = URI.encode_www_form(merged_params)
uri.to_s
end

def _hash_to_attributes(hash)
Expand Down
2 changes: 1 addition & 1 deletion lib/video_info/providers/vimeo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(url, options = {})
extend VimeoAPI
end

super(url, options)
super
end

def self.usable?(url)
Expand Down
4 changes: 4 additions & 0 deletions lib/video_info/providers/vimeo_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def stats
_video["stats"]
end

def embed_url
_video["player_embed_url"]
end

private

def generate_thumbnail(width = 200, height = nil)
Expand Down
1 change: 0 additions & 1 deletion lib/video_info/providers/vimeo_scraper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def json_info
end
end


def thumbnail_url
@thumbnail_url ||= remove_overlay(meta_node_value("og:image"))
end
Expand Down
2 changes: 1 addition & 1 deletion lib/video_info/providers/youtube.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(url, options = {})
extend YoutubeAPI
end

super(url, options)
super
end

def self.usable?(url)
Expand Down
38 changes: 35 additions & 3 deletions lib/video_info/providers/youtube_scraper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module YoutubeScraper
BASE_URL = "https://www.youtube.com"
CHANNEL_URL = "#{BASE_URL}/channel/"
THUMB_DEFAULT_SIZE = 88
DEFAULT_YOUTUBE_DESCRIPTION = "Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube."

def available?
!!title
Expand Down Expand Up @@ -41,7 +42,11 @@ def author_url
end

def description
meta_node_value(video_meta_nodes, "og:description")
# NOTE: If a video has no description, YouTube will insert a generic message.
description = meta_node_value(video_meta_nodes, "og:description")
return "" if description == DEFAULT_YOUTUBE_DESCRIPTION

description
end

def duration
Expand All @@ -68,7 +73,7 @@ def title
end

def view_count
itemprop_node_value("interactionCount").to_i
interaction_statistics["https://schema.org/WatchAction"]&.to_i || 0
end

def stats
Expand Down Expand Up @@ -97,7 +102,8 @@ def meta_node_value(meta_nodes, name)
end

return unless node
node&.attr("content") && node.attr("content").value

node.attr("content")&.value
end

def itemprop_node_value(name)
Expand All @@ -111,6 +117,32 @@ def itemprop_node_value(name)
node.attr("content").value
end

def interaction_statistics
@interaction_statistics ||= begin
stats = {}
# Find all divs with itemprop="interactionStatistic"
interaction_divs = data.css('div[itemprop="interactionStatistic"]')

interaction_divs.each do |div|
# Find meta tag with interactionType
interaction_type_meta = div.css('meta[itemprop="interactionType"]').first
interaction_type_attr = interaction_type_meta&.attr("content")
next unless interaction_type_attr

interaction_type = interaction_type_attr.value

# Get the userInteractionCount from the same div
count_meta = div.css('meta[itemprop="userInteractionCount"]').first
count_attr = count_meta&.attr("content")
next unless count_attr

stats[interaction_type] = count_attr.value
end

stats
end
end

def _set_data_from_api_impl(api_url)
# handle fullscreen video URLs
if url.include?(".com/v/")
Expand Down
2 changes: 1 addition & 1 deletion lib/video_info/providers/youtubeplaylist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class YoutubePlaylist < Youtube
attr_accessor :playlist_items_data

def initialize(url, options = {})
super(url, options)
super

if VideoInfo.provider_api_keys[:youtube].nil?
extend YoutubePlaylistScraper
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading