svt-recorder 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,15 @@
1
+ 2012-09-14 Björn Andersson <ba@sanitarium.se>, v1.0.3
2
+
3
+ SVT changed so that the playlists downloaded for a bitrate could be
4
+ a complete URL instead of just part of a chunk. This new naming scheme
5
+ changed so that downloads didn't complete fully on new videos.
6
+
7
+ So now the script always use the complete URL from the playlist instead
8
+ of making up its own URL based on off how it ought to be. Thus this
9
+ should be more future proof.
10
+
11
+ Fingers crossed. :)
12
+
1
13
  2012-09-14 Björn Andersson <ba@sanitarium.se>, v1.0.2
2
14
 
3
15
  Oops, typo in the recorder which affected urls with characters that
@@ -51,15 +51,15 @@ class HTTPDownload
51
51
  File.open(@file, 'wb+') do |file|
52
52
  @downloader.parts do |part|
53
53
  begin
54
- @server.request_get(File.join(@base_url.path, part),
55
- @headers) do |res|
54
+ @server.request_get(part, @headers) do |res|
56
55
  res.read_body do |body|
57
56
  file.write body
58
57
  end
59
58
  end # /@server
60
- rescue Timeout::Error
59
+ rescue Timeout::Error, EOFError, Errno::ECONNRESET => exception
61
60
  yield -1
62
61
  @server = Net::HTTP.start(@base_url.host, @base_url.port)
62
+ STDERR.puts "Connection error..."
63
63
  retry
64
64
  end
65
65
 
@@ -98,6 +98,7 @@ if File.exists? output_file
98
98
  end
99
99
 
100
100
  progress = ProgressBar.new(downloader.parts?, :bar, :elapsed, :eta, :counter)
101
+ puts "Starting recording..."
101
102
  HTTPDownload.new(downloader, output_file) do |down|
102
103
  down.fetch_all {|part| progress.increment! }
103
104
  puts "\nFinished recording: #{output_file}"
@@ -33,6 +33,6 @@ module SVT #:nodoc:
33
33
  end
34
34
  end
35
35
 
36
- VERSION = '1.0.2'
36
+ VERSION = '1.0.3'
37
37
  end
38
38
  end
@@ -48,14 +48,15 @@ module SVT
48
48
 
49
49
  @bitrates = {} # bitrate => stream
50
50
  @part_base = ''
51
- @first_part = 0
52
- @last_part = 0
51
+ @parts = []
53
52
  end
54
53
 
55
54
  attr_reader :title
56
55
  attr_reader :base_url
57
56
  attr_reader :bitrate
58
57
 
58
+ def last_part ; @parts.size ; end
59
+
59
60
  # All part URL:s for a specific +bitrate+
60
61
  #
61
62
  # Args:
@@ -72,14 +73,17 @@ module SVT
72
73
  bitrate
73
74
  end
74
75
 
75
- url = File.join(@base_url, @bitrates[@bitrate])
76
+ url = @bitrates[@bitrate]
77
+ unless url.match(/^http/)
78
+ url = File.join(@base_url, @bitrates[@bitrate])
79
+ end
76
80
 
77
81
  open(url).each do |row|
78
82
  next if row[0..0] == '#'
79
83
  row.strip!
80
84
 
81
85
  @part_base = File.dirname(row) if @part_base.empty?
82
- @last_part += 1
86
+ @parts << File.basename(row)
83
87
  end
84
88
 
85
89
  self
@@ -101,13 +105,13 @@ module SVT
101
105
  # A complete part download URL
102
106
  #
103
107
  # Returns:
104
- # All parts in an ordered array, first -> last
108
+ # All parts in an ordered array, first -> last, full URL
105
109
  def parts
106
- part_urls() if @last_part == 0
110
+ part_urls() if last_part == 0
107
111
 
108
112
  if block_given?
109
- (@first_part...@last_part).each do |i|
110
- yield "#{@part_base}/segment#{i}.ts"
113
+ @parts.each do |i|
114
+ yield "#{@part_base}/#{i}"
111
115
  end
112
116
  else
113
117
  # I want you Object#tap
@@ -122,15 +126,15 @@ module SVT
122
126
  # Returns:
123
127
  # int the numbers of parts, 0 index
124
128
  def parts?
125
- part_urls() if @last_part == 0
129
+ part_urls() if last_part == 0
126
130
 
127
- return @last_part
131
+ return last_part
128
132
  end
129
133
 
130
134
  # Yields all +parts+ concatenated with base_url
131
135
  def all_parts
132
136
  parts do |part|
133
- yield File.join(base_url, part)
137
+ yield "#{base_url}/#{part}"
134
138
  end
135
139
  end
136
140
 
@@ -145,7 +149,6 @@ module SVT
145
149
  bitrate = nil
146
150
  open(@stream).each do |row|
147
151
  row.strip!
148
- row = File.basename(row) if row.match(/^http/)
149
152
 
150
153
  if bitrate
151
154
  @bitrates[bitrate] = CGI.unescape(row)
@@ -21,14 +21,6 @@ module SVT
21
21
 
22
22
  data.title.should == title
23
23
  end
24
-
25
- it 'should handle streams with http and just give of the basename' do
26
- # An error when fetching Rapport videos, the playlist at times had
27
- # a FQDN
28
- data = SVT::Recorder::Base.new({:url => $stream_http,
29
- :title => 'Whatever'})
30
- data.parts[0].should == 'PG-1279307-001A-DOKUMENTUTIFRAN-02-hts-a-v1_Layer6/3512_Period1/segment0.ts'
31
- end
32
24
  end
33
25
 
34
26
  let(:title) { 'Glödlampskonspirationen' }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svt-recorder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: