Class: YoutubeUtils
- Inherits:
-
Object
- Object
- YoutubeUtils
- Defined in:
- lib/youtube_utils.rb
Overview
Class Method Summary collapse
-
.get_vid(url) ⇒ Object
input: www.youtube.com/watch?v=cRdxXPV9GNQ output: cRdxXPV9GNQ.
-
.type2suffix(type) ⇒ Object
input: video/webm; codecs=“vp8.0, v outut: webm.
Instance Method Summary collapse
- #get_videos(youtube_watch_url) ⇒ Object
-
#initialize(debug = false) ⇒ YoutubeUtils
constructor
A new instance of YoutubeUtils.
Constructor Details
#initialize(debug = false) ⇒ YoutubeUtils
Returns a new instance of YoutubeUtils.
9 10 11 |
# File 'lib/youtube_utils.rb', line 9 def initialize(debug = false) @debug = debug end |
Class Method Details
.get_vid(url) ⇒ Object
input: www.youtube.com/watch?v=cRdxXPV9GNQ output: cRdxXPV9GNQ
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/youtube_utils.rb', line 32 def self.get_vid url querys = URI.parse(url).query.split('&') querys.each {|x| a = x.split('=') if a[0] == 'v' return a[1] end } return nil end |
.type2suffix(type) ⇒ Object
input: video/webm; codecs=“vp8.0, v outut: webm
45 46 47 |
# File 'lib/youtube_utils.rb', line 45 def self.type2suffix type return type.split(';')[0].split('/')[1] end |
Instance Method Details
#get_videos(youtube_watch_url) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/youtube_utils.rb', line 13 def get_videos youtube_watch_url res = get_webpage(youtube_watch_url); unless res.code == '200' raise res.code end result = [] fmt_stream_map = get_url_encoded_fmt_stream_map(res.body) fmt_list = get_fmt_list(res.body) puts fmt_stream_map, fmt_list if @debug result.concat(parse_fmt_stream_map(fmt_stream_map, fmt_list)) if fmt_list&&fmt_stream_map return result end |