Class: YoutubeChannel
Instance Method Summary collapse
- #download ⇒ Object
- #dump ⇒ Object
-
#initialize(params, options) ⇒ YoutubeChannel
constructor
A new instance of YoutubeChannel.
Methods inherited from WebRadio
Constructor Details
#initialize(params, options) ⇒ YoutubeChannel
Returns a new instance of YoutubeChannel.
89 90 91 92 |
# File 'lib/youtube.rb', line 89 def initialize(params, ) super @target_content = ['contents', 'twoColumnBrowseResultsRenderer', 'tabs', 1, 'tabRenderer', 'content', 'sectionListRenderer', 'contents', 0, 'itemSectionRenderer', 'contents', 0, 'gridRenderer', 'items'].freeze end |
Instance Method Details
#download ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/youtube.rb', line 94 def download first_video(URI.open(@url).read) do |content| item = content['gridVideoRenderer'] @cover = item['thumbnail']['thumbnails'].last['url'] title = item['title']['runs'][0]['text'] serial = title.scan(/\d+/).first.to_i url = "https://www.youtube.com#{item['navigationEndpoint']['commandMetadata']['webCommandMetadata']['url']}" mp4_file = serial_file title, @label, serial, 'mp4' mp3_file = serial_file title, @label, serial, 'mp3' youtube_download url, mp4_file, mp3_file end end |
#dump ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/youtube.rb', line 109 def dump tag = @url.scan(%r|/c/([^/]*)|).flatten.first html = Nokogiri(URI(@url).open.read) label = html.css('meta[property="og:title"]').attr('content').text return { tag => { 'desc' => label, 'url' => "#{@url.scan(%r|(.*?/c/[^/]*)|).flatten.first}/videos?view=0&sort=dd&flow=grid", 'label' => label } } end |