hlspider 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -2,7 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 1.9.2
5
+ - 2.0.0
5
6
  - jruby-19mode
6
7
  - rbx-19mode
7
- #- ruby-head
8
8
  - jruby-head
data/hlspider.gemspec CHANGED
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
20
20
 
21
21
  # specify any dependencies here
22
22
  s.add_development_dependency 'minitest', '~> 2.7.0'
23
+ s.add_development_dependency 'webmock'
23
24
  end
@@ -4,8 +4,6 @@ require 'hlspider/response'
4
4
  # Internal: Asynchronsoly downloads urls and returns Array of responses.
5
5
  module HLSpider
6
6
  module Downloader
7
- class DownloadError < StandardError; end;
8
-
9
7
  # Internal: Download given URLs.
10
8
  #
11
9
  # urls - An Array of strings or a single string of URL(s)
@@ -143,10 +143,10 @@ module HLSpider
143
143
  # http://hls.telvue.com/brightstar/2-1/playlist.m3u8?wowzasessionid=268983957'
144
144
  #
145
145
  # Returns String file.
146
- def to_s
146
+ def inspect
147
147
  @file
148
148
  end
149
- alias_method :to_s, :inspect
149
+ alias_method :inspect, :to_s
150
150
 
151
151
  private
152
152
  include PlaylistLine
@@ -166,7 +166,7 @@ module HLSpider
166
166
  @variable_playlist = true
167
167
 
168
168
  @file.each_line do |line|
169
- @playlists << line.strip if has_playlist?(line)
169
+ @playlists << line[/([^ "]+.m3u8)/].strip if has_playlist?(line)
170
170
  end
171
171
  elsif has_segment?(@file) && !has_playlist?(@file)
172
172
  @segment_playlist = true
@@ -1,3 +1,3 @@
1
1
  module HLSpider
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe HLSpider::Playlist do
4
+ before do
5
+ @segments_playlist = %q{#EXTM3U
6
+ #EXT-X-TARGETDURATION:10
7
+ #EXT-X-VERSION:3
8
+ #EXT-X-MEDIA-SEQUENCE:0
9
+ #EXT-X-PLAYLIST-TYPE:VOD
10
+ #EXTINF:7.12,
11
+ segment00000.ts
12
+ segment00001.ts
13
+ #EXT-X-ENDLIST
14
+ }
15
+
16
+ @variable_playlist = %q{#EXTM3U
17
+ #EXTM3U
18
+ #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=673742
19
+ rel/playlist.m3u8
20
+ #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=204909
21
+ http://anotherhost.com/playlist3.m3u8
22
+ }
23
+
24
+ @extra_media_playlist = %q{#EXTM3U
25
+ #EXT-X-FAXS-CM:URI="iphone360.mp4.drmmeta"
26
+ #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="Portuguese",DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="pt",URI="iphone.m3u8"
27
+ #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="SAP",DEFAULT=NO,AUTOSELECT=YES,LANGUAGE="en",URI="sap.m3u8"
28
+ #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=673742,CODECS="mp4a.40.2,avc1.4d401e",AUDIO="aac"
29
+ web.m3u8
30
+ #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=401437,CODECS="mp4a.40.2,avc1.4d401e",AUDIO="aac"
31
+ iphone.m3u8
32
+ }
33
+ end
34
+
35
+ it "should identify if it is a segments playlist" do
36
+ playlist = HLSpider::Playlist.new(@segments_playlist)
37
+ playlist.segment_playlist?.must_equal(true)
38
+ playlist.variable_playlist?.must_equal(false)
39
+ end
40
+
41
+ it "should identify if it is a variable playlist" do
42
+ playlist = HLSpider::Playlist.new(@variable_playlist)
43
+ playlist.variable_playlist?.must_equal(true)
44
+ playlist.segment_playlist?.must_equal(false)
45
+ end
46
+
47
+ it "should resolve relative playlists" do
48
+ playlist = HLSpider::Playlist.new(@variable_playlist, "http://host.com/main/playlist.m3u8")
49
+ playlist.playlists[0].must_equal("http://host.com/main/rel/playlist.m3u8")
50
+ end
51
+
52
+ it "should accept absolute playlists" do
53
+ playlist = HLSpider::Playlist.new(@variable_playlist, "http://host.com/main/playlist.m3u8")
54
+ playlist.playlists[1].must_equal("http://anotherhost.com/playlist3.m3u8")
55
+ end
56
+
57
+ it "should same value to to_s and inspect" do
58
+ playlist = HLSpider::Playlist.new(@segments_playlist)
59
+ playlist.to_s.must_equal(playlist.inspect)
60
+ end
61
+
62
+ it "should accept extra media urls on playlists" do
63
+ playlist = HLSpider::Playlist.new(@extra_media_playlist, "http://host.com/main/playlist.m3u8")
64
+ playlist.playlists.must_equal([
65
+ "http://host.com/main/iphone.m3u8",
66
+ "http://host.com/main/sap.m3u8",
67
+ "http://host.com/main/web.m3u8",
68
+ "http://host.com/main/iphone.m3u8"
69
+ ])
70
+ end
71
+ end
@@ -4,13 +4,79 @@ describe HLSpider::Spider do
4
4
  before do
5
5
  @playlist = "http://host.com/playlist.m3u8"
6
6
  @playlists = ["http://host.com/playlist.m3u8", "http://host.com/playlist2.m3u8"]
7
+ stub_request(:get, "http://host.com/playlist.m3u8").to_return({:status => 200, :headers => {}, :body => %q{#EXTM3U
8
+ #EXT-X-TARGETDURATION:10
9
+ #EXT-X-VERSION:3
10
+ #EXT-X-MEDIA-SEQUENCE:0
11
+ #EXT-X-PLAYLIST-TYPE:VOD
12
+ #EXTINF:7.12,
13
+ segment00000.ts
14
+ segment00001.ts
15
+ #EXT-X-ENDLIST
16
+ }})
17
+ stub_request(:get, "http://host.com/playlist2.m3u8").to_return({:status => 200, :headers => {}, :body => %q{#EXTM3U
18
+ #EXTM3U
19
+ #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=673742
20
+ playlist.m3u8
21
+ #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=204909
22
+ playlist3.m3u8
23
+ }})
24
+
25
+ stub_request(:get, "http://host.com/playlist3.m3u8").to_return({:status => 200, :headers => {}, :body => %q{#EXTM3U
26
+ #EXT-X-TARGETDURATION:10
27
+ #EXT-X-VERSION:3
28
+ #EXT-X-MEDIA-SEQUENCE:0
29
+ #EXT-X-PLAYLIST-TYPE:VOD
30
+ #EXTINF:7.12,
31
+ segment00000.ts
32
+ segment00001.ts
33
+ segment00002.ts
34
+ #EXT-X-ENDLIST
35
+ }})
36
+
37
+ stub_request(:get, "http://host.com/playlist4.m3u8").to_return({:status => 200, :headers => {}, :body => %q{#EXT-X-TARGETDURATION:10}})
7
38
  end
8
-
39
+
9
40
  it "can be created with a String" do
10
41
  HLSpider::Spider.new(@playlist).must_be_instance_of(HLSpider::Spider)
11
- end
12
-
42
+ end
43
+
13
44
  it "can be created with an Array" do
14
45
  HLSpider::Spider.new(@playlists).must_be_instance_of(HLSpider::Spider)
15
- end
16
- end
46
+ end
47
+
48
+ it "should download the playlist content when parsing it" do
49
+ spider = HLSpider::Spider.new(@playlist)
50
+ spider.playlists.count.must_equal(1)
51
+ spider.playlists[0].must_be_instance_of(HLSpider::Playlist)
52
+ assert_requested(:get, @playlist)
53
+ end
54
+
55
+ it "should download recursively when the playlist if of playlists" do
56
+ spider = HLSpider::Spider.new(@playlists)
57
+ spider.playlists.count.must_equal(3)
58
+ spider.playlists[0].must_be_instance_of(HLSpider::Playlist)
59
+ spider.playlists[1].must_be_instance_of(HLSpider::Playlist)
60
+ spider.playlists[2].must_be_instance_of(HLSpider::Playlist)
61
+ assert_requested(:get, "http://host.com/playlist.m3u8", :times => 2)
62
+ assert_requested(:get, "http://host.com/playlist2.m3u8")
63
+ assert_requested(:get, "http://host.com/playlist3.m3u8")
64
+ end
65
+
66
+ it "should raise error when the playlist is invalid" do
67
+ spider = HLSpider::Spider.new("http://host.com/playlist4.m3u8")
68
+ assert_raises(HLSpider::Spider::InvalidPlaylist) {
69
+ spider.playlists
70
+ }
71
+ end
72
+
73
+ it "should return the last segment of each playlist" do
74
+ spider = HLSpider::Spider.new(@playlists)
75
+ spider.last_segments.must_equal([0, 0, 0])
76
+ end
77
+
78
+ it "should check if the playlists are aligned" do
79
+ spider = HLSpider::Spider.new(@playlists)
80
+ spider.aligned?.must_equal(true)
81
+ end
82
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
1
  require 'minitest/autorun'
2
+ require 'webmock/minitest'
2
3
  require 'hlspider'
3
4
 
5
+ WebMock.disable_net_connect!
6
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hlspider
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 0.4.0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - brookemckim
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-13 00:00:00 Z
18
+ date: 2013-05-09 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: minitest
@@ -33,6 +33,20 @@ dependencies:
33
33
  version: 2.7.0
34
34
  type: :development
35
35
  version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: webmock
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
36
50
  description: Downloads .m3u8 playlists and reports back on whether or not the playlists are aligned in time.
37
51
  email:
38
52
  - brooke.mckim@gmail.com
@@ -60,6 +74,7 @@ files:
60
74
  - lib/hlspider/spider.rb
61
75
  - lib/hlspider/version.rb
62
76
  - spec/hlspider/playlist_line_spec.rb
77
+ - spec/hlspider/playlist_spec.rb
63
78
  - spec/hlspider/spider_spec.rb
64
79
  - spec/hlspider_spec.rb
65
80
  - spec/spec_helper.rb
@@ -98,6 +113,7 @@ specification_version: 3
98
113
  summary: Download and parse .m3u8 playlists.
99
114
  test_files:
100
115
  - spec/hlspider/playlist_line_spec.rb
116
+ - spec/hlspider/playlist_spec.rb
101
117
  - spec/hlspider/spider_spec.rb
102
118
  - spec/hlspider_spec.rb
103
119
  - spec/spec_helper.rb