Class: YoutubeChannel

Inherits:
Youtube show all
Defined in:
lib/youtube.rb

Instance Method Summary collapse

Methods inherited from WebRadio

instance

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, options)
    super
    @target_content = ['contents', 'twoColumnBrowseResultsRenderer', 'tabs', 1, 'tabRenderer', 'content', 'sectionListRenderer', 'contents', 0, 'itemSectionRenderer', 'contents', 0, 'gridRenderer', 'items'].freeze
end

Instance Method Details

#downloadObject



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

#dumpObject



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