hlspider 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (C) 2011 by Brooke McKim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -38,11 +38,11 @@ playlist.target_duration
38
38
  HLSpider is also available from the command line
39
39
 
40
40
  ```
41
- hlspider crawl --playlists=http://host.com/video1/playlist1.m3u8,http://host.com/video1/playlist2.m3u8 http://host.com/video1/playlist3.m3u8
41
+ hlspider --playlists=http://host.com/video1/playlist1.m3u8,http://host.com/video1/playlist2.m3u8,http://host.com/video1/playlist3.m3u8
42
42
  ```
43
43
 
44
44
  OR
45
45
 
46
46
  ```
47
- hlspider crawl --playlists=http://host.com/video1/all_bitrates_playlist.m3u8
47
+ hlspider --playlists=http://host.com/video1/all_bitrates_playlist.m3u8
48
48
  ```
@@ -21,6 +21,8 @@ module HLSpider
21
21
  def async_download(urls)
22
22
  urls = Array.new(urls)
23
23
 
24
+ puts urls.inspect
25
+
24
26
  responses = nil
25
27
  EventMachine.run {
26
28
  multi = EventMachine::MultiRequest.new
@@ -36,6 +36,9 @@ module HLSpider
36
36
  # Public: Gets the target duration if available.
37
37
  attr_reader :target_duration
38
38
 
39
+ # Public: Gets the media sequence of the playlist.
40
+ attr_reader :media_sequence
41
+
39
42
  # Internal: Initialize a Playlist.
40
43
  #
41
44
  # file - A String containing an .m3u8 playlist file.
@@ -108,7 +111,28 @@ module HLSpider
108
111
  def valid?
109
112
  @valid
110
113
  end
111
-
114
+
115
+ # Public: Sub-Playlists of playlist file. Appends source if
116
+ # playlists are not absolute urls.
117
+ #
118
+ #
119
+ #
120
+ # Examples
121
+ #
122
+ # playlists
123
+ # # => ["http://site.tld/playlist_1.m3u8", "http://site.tld/playlist_2.m3u8"]
124
+ #
125
+ # Returns Array of Strings.
126
+ def playlists
127
+ @playlists.collect do |p|
128
+ if absolute_url?(p)
129
+ p
130
+ elsif @source
131
+ @source.sub(/\w*.m3u8/, p)
132
+ end
133
+ end
134
+ end
135
+
112
136
  # Public: Prints contents of @file.
113
137
  #
114
138
  #
@@ -152,6 +176,8 @@ module HLSpider
152
176
  @segments << filename(line.strip)
153
177
  elsif duration_line?(line)
154
178
  @target_duration = parse_duration(line.strip)
179
+ elsif media_sequence_line?(line)
180
+ @media_sequence = parse_sequence(line.strip)
155
181
  end
156
182
  end
157
183
  else
@@ -15,7 +15,7 @@ module HLSpider
15
15
  #
16
16
  # Returns Boolean.
17
17
  def has_segment?(str)
18
- !!/.*.ts(\z|\?)/.match(str)
18
+ !!/.*.ts(\z|\?|$)/.match(str)
19
19
  end
20
20
 
21
21
  # Internal: Checks if String str contains links to .m3u8 file extensions.
@@ -91,5 +91,59 @@ module HLSpider
91
91
  def filename(str)
92
92
  str.slice(/\w{1,}(.ts)/)
93
93
  end
94
+
95
+ # Internal: Parses string and returns whether or not it is an absolute url.
96
+ #
97
+ # str - String to be parsed
98
+ #
99
+ # Examples
100
+ #
101
+ # absolute_url?("directory/file.m3u8")
102
+ # #=> false
103
+ #
104
+ # absolute_url?("http://www.site.tld/file.m3u8")
105
+ # #=> true
106
+ #
107
+ # Returns String or nil.
108
+ def absolute_url?(str)
109
+ str.split("://").size > 1
110
+ end
111
+
112
+ # Internal: Parses string and returns whether or not it is a media sequence line.
113
+ #
114
+ # str - String to be parsed
115
+ #
116
+ # Examples
117
+ #
118
+ # media_sequence_line?("#EXT-X-MEDIA-SEQUENCE:1739")
119
+ # #=> true
120
+ #
121
+ # media_sequence_line?("holla")
122
+ # #=> false
123
+ #
124
+ # Returns Boolean.
125
+ def media_sequence_line?(str)
126
+ !!/EXT-X-MEDIA-SEQUENCE/.match(str)
127
+ end
128
+
129
+ # Internal: Parses string and returns media sequence number.
130
+ #
131
+ # line - Line to be parsed
132
+ #
133
+ # Examples
134
+ #
135
+ # parse_sequence("#EXT-X-MEDIA-SEQUENCE:1739")
136
+ # #=> 1739
137
+ #
138
+ # Returns Integer or nil.
139
+ def parse_sequence(line)
140
+ /#EXT-X-MEDIA-SEQUENCE:\s*(\d*)/.match(line)
141
+
142
+ if sequence = Regexp.last_match(1)
143
+ sequence.to_i
144
+ else
145
+ nil
146
+ end
147
+ end
94
148
  end
95
149
  end
@@ -91,7 +91,7 @@ module HLSpider
91
91
  #
92
92
  # Returns Array of Strings
93
93
  def last_segments
94
- playlists.collect { |p| p.segments.last }
94
+ playlists.collect { |p| p.media_sequence }
95
95
  end
96
96
 
97
97
  private
@@ -1,3 +1,3 @@
1
1
  module HLSpider
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -53,6 +53,36 @@ describe HLSpider::PlaylistLine do
53
53
  it "returns String with filename on String with filename" do
54
54
  PlaylistLine.filename(@segment_line).must_equal("video_123123023030.ts")
55
55
  end
56
- end
56
+ end
57
+
58
+ describe "#absolute_url?" do
59
+ it "returns true for full url" do
60
+ PlaylistLine.absolute_url?("http://www.google.com/gmail/").must_equal(true)
61
+ end
62
+
63
+ it "returns false for relative path" do
64
+ PlaylistLine.absolute_url?("holla/dolla.m3u8").must_equal(false)
65
+ end
66
+ end
67
+
68
+ describe "#media_sequence_line?" do
69
+ it "returns false when line is not a media sequence line" do
70
+ PlaylistLine.media_sequence_line?("!!!!!!!hello").must_equal(false)
71
+ end
72
+
73
+ it "returns true when line is a media sequence line" do
74
+ PlaylistLine.media_sequence_line?("#EXT-X-MEDIA-SEQUENCE:1739").must_equal(true)
75
+ end
76
+ end
77
+
78
+ describe "#parse_sequence" do
79
+ it "returns sequence number when the line has one" do
80
+ PlaylistLine.parse_sequence("#EXT-X-MEDIA-SEQUENCE:1739").must_equal(1739)
81
+ end
82
+
83
+ it "returns nil when line does not a sequence number" do
84
+ PlaylistLine.parse_sequence("~_~").must_equal(nil)
85
+ end
86
+ end
57
87
  end
58
88
 
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
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: 2011-11-17 00:00:00 -05:00
18
+ date: 2011-12-06 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -82,6 +82,7 @@ files:
82
82
  - .rbenv-version
83
83
  - Gemfile
84
84
  - Gemfile.lock
85
+ - LICENSE
85
86
  - README.md
86
87
  - Rakefile
87
88
  - bin/hlspider