Class: Coelacanth::Extractor::Preprocessor::Preprocessors::YouTube

Inherits:
Object
  • Object
show all
Defined in:
lib/coelacanth/extractor/preprocessor.rb

Overview

Converts YouTube video pages into structured article-like HTML using the YouTube Data API. This allows the downstream extractor to consume the video description and thumbnail as if it were a standard article.

Constant Summary collapse

API_ENDPOINT =
"https://www.googleapis.com/youtube/v3/videos"
WATCH_HOSTS =
%w[youtube.com www.youtube.com youtu.be m.youtube.com music.youtube.com].freeze

Instance Method Summary collapse

Instance Method Details

#call(html:, url:) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/coelacanth/extractor/preprocessor.rb', line 43

def call(html:, url:)
  video_id = extract_video_id(url)
  return unless video_id

  api_key = youtube_api_key
  return if api_key.nil? || api_key.empty?

  snippet = fetch_snippet(video_id, api_key)
  return unless snippet

  build_document(snippet)
end