iplayer-dl 0.1.16

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.
@@ -0,0 +1,75 @@
1
+ $:.unshift( File.join( File.dirname(__FILE__), '..', 'lib' ))
2
+ require 'test/unit'
3
+ require 'iplayer/metadata'
4
+ require 'mocha'
5
+
6
+ class MetadataTest < Test::Unit::TestCase
7
+
8
+ def test_should_return_mov_for_tv_filetype
9
+ xml = %{
10
+ <?xml version="1.0" encoding="UTF-8"?>
11
+ <playlist xmlns="http://bbc.co.uk/2008/emp/playlist" revision="1">
12
+ <item kind="programme" duration="5400" identifier="b00ftblc" group="b00ftbxh" publisher="pips">
13
+ </item>
14
+ </playlist>
15
+ }
16
+ pid = 'abc'
17
+ browser = stub(:get => stub(:body => xml))
18
+ metadata = IPlayer::Metadata.new(pid, browser)
19
+ assert_equal 'mov', metadata.filetype
20
+ end
21
+
22
+ def test_should_return_mp3_for_radio_filetype
23
+ xml = %{
24
+ <?xml version="1.0" encoding="UTF-8"?>
25
+ <playlist xmlns="http://bbc.co.uk/2008/emp/playlist" revision="1">
26
+ <item kind="radioProgramme" duration="1800" identifier="b00fn3dg" group="b00fn3fp" publisher="pips">
27
+ </item>
28
+ </playlist>
29
+ }
30
+ pid = 'abc'
31
+ browser = stub(:get => stub(:body => xml))
32
+ metadata = IPlayer::Metadata.new(pid, browser)
33
+ assert_equal 'mp3', metadata.filetype
34
+ end
35
+
36
+ def test_should_return_hash_of_available_versions_with_version_pids
37
+ xml = %{
38
+ <?xml version="1.0" encoding="UTF-8"?>
39
+ <playlist xmlns="http://bbc.co.uk/2008/emp/playlist" revision="1">
40
+ <item kind="programme" duration="5400" identifier="b00ftblc" group="b00ftbxh" publisher="pips">
41
+ <alternate id="default" />
42
+ </item>
43
+ <item kind="programme" duration="5400" identifier="b00fvy5y" group="b00ftbxh" publisher="pips">
44
+ <alternate id="signed" />
45
+ </item>
46
+ </playlist>
47
+ }
48
+ pid = 'abc'
49
+ browser = stub(:get => stub(:body => xml))
50
+ metadata = IPlayer::Metadata.new(pid, browser)
51
+ expected = {'default' => 'b00ftblc', 'signed' => 'b00fvy5y'}
52
+ assert_equal expected, metadata.versions
53
+ end
54
+
55
+ def test_should_call_version_anonymous_if_the_beeb_do_not_give_an_alternate_an_id
56
+ xml = %{
57
+ <?xml version="1.0" encoding="UTF-8"?>
58
+ <playlist xmlns="http://bbc.co.uk/2008/emp/playlist" revision="1">
59
+ <item kind="programme" duration="2700" identifier="b00htg55" group="b00hklrs" publisher="pips">
60
+ <tempav>1</tempav>
61
+ <id>tag:bbc.co.uk,2008:pips:b00htg55</id>
62
+ <service id="bbc_two" href="http://www.bbc.co.uk/iplayer/bbc_two">BBC Two</service>
63
+ <masterbrand id="bbc_one" href="http://www.bbc.co.uk/iplayer/bbc_one">BBC One</masterbrand>
64
+ <guidance id="W1">Contains adult humour.</guidance>
65
+ <mediator identifier="b00htg55" name="pips"/>
66
+ </item>
67
+ </playlist>
68
+ }
69
+ pid = 'abc'
70
+ browser = stub(:get => stub(:body => xml))
71
+ metadata = IPlayer::Metadata.new(pid, browser)
72
+ expected = {'anonymous' => 'b00htg55'}
73
+ assert_equal expected, metadata.versions
74
+ end
75
+ end
@@ -0,0 +1,175 @@
1
+ $:.unshift( File.join( File.dirname(__FILE__), '..', 'lib' ))
2
+ require 'test/unit'
3
+ require 'mocha'
4
+ require 'iplayer/preferences'
5
+ require 'stringio'
6
+
7
+ class PreferencesTestWithDefaults < Test::Unit::TestCase
8
+
9
+ def setup
10
+ File.stubs(:read).returns('')
11
+ end
12
+
13
+ def test_should_start_with_sensible_default_type_preference
14
+ prefs = IPlayer::Preferences.new
15
+
16
+ assert_equal ['default', 'signed'], prefs.type_preference
17
+ end
18
+
19
+ def test_should_use_current_working_directory_for_download_path
20
+ prefs = IPlayer::Preferences.new
21
+
22
+ assert_equal Dir.pwd, prefs.download_path
23
+ end
24
+
25
+ def test_should_not_use_subdirectories_by_default
26
+ prefs = IPlayer::Preferences.new
27
+
28
+ assert !prefs.subdirs
29
+ end
30
+
31
+ def test_should_use_nil_http_proxy_when_unspecified_in_environment
32
+ env = ENV.to_hash.merge('http_proxy' => nil)
33
+ prefs = IPlayer::Preferences.new(env)
34
+
35
+ assert_nil prefs.http_proxy
36
+ end
37
+
38
+ def test_should_use_current_http_proxy_environment_variable
39
+ env = ENV.to_hash.merge('http_proxy' => 'localhost:9999')
40
+ prefs = IPlayer::Preferences.new(env)
41
+
42
+ assert_equal 'localhost:9999', prefs.http_proxy
43
+ end
44
+
45
+ def test_should_override_defaults_via_assignment
46
+ prefs = IPlayer::Preferences.new
47
+ prefs.http_proxy = 'localhost:3128'
48
+ assert_equal 'localhost:3128', prefs.http_proxy
49
+ end
50
+
51
+ def test_should_reset_defaults
52
+ prefs = IPlayer::Preferences.new
53
+ prefs.type_preferences = ['foo', 'bar']
54
+ prefs.reset_defaults
55
+ assert_equal ['default', 'signed'], prefs.type_preference
56
+ end
57
+
58
+ end
59
+
60
+ class PreferencesTestWhenLoading < Test::Unit::TestCase
61
+
62
+ def test_should_read_from_dotfile_in_home_directory_on_posix_platforms
63
+ env = {'HOME' => '/home/peter'}
64
+ File.stubs(:exist?).returns(true)
65
+ File.expects(:read).with('/home/peter/.iplayer-dl').returns('')
66
+ prefs = IPlayer::Preferences.new(env, 'lunix')
67
+ end
68
+
69
+ def test_should_read_from_preference_file_in_appdata_directory_on_windows
70
+ env = {'APPDATA' => 'C:\Documents and Settings\Peter\Application Data'}
71
+ File.stubs(:exist?).returns(true)
72
+ File.expects(:read).with('C:\Documents and Settings\Peter\Application Data/iplayer-dl').returns('') # Looks weird, but paths work this way
73
+ prefs = IPlayer::Preferences.new(env, 'i386-mswin32')
74
+ end
75
+
76
+ def test_should_override_defaults_from_yaml_in_file
77
+ file_contents = {
78
+ 'type_preference' => %w[foo bar],
79
+ 'download_path' => '/nowhere',
80
+ 'http_proxy' => 'localhost:3128',
81
+ 'subdirs' => true
82
+ }.to_yaml
83
+ File.stubs(:exist?).returns(true)
84
+ File.stubs(:read).returns(file_contents)
85
+ env = {'HOME' => '/home/peter'}
86
+ prefs = IPlayer::Preferences.new(env, 'lunix')
87
+ assert_equal ['foo', 'bar'], prefs.type_preference
88
+ assert_equal '/nowhere', prefs.download_path
89
+ assert_equal 'localhost:3128', prefs.http_proxy
90
+ assert prefs.subdirs
91
+ end
92
+
93
+ def test_should_ignore_when_preferences_file_does_not_exist
94
+ env = {'HOME' => '/tmp'}
95
+ assert_nothing_raised do
96
+ IPlayer::Preferences.new(env, 'lunix')
97
+ end
98
+ end
99
+ end
100
+
101
+ class PreferencesWhenSaving < Test::Unit::TestCase
102
+
103
+ def test_should_write_to_dotfile_in_home_directory_on_posix_platforms
104
+ env = {'HOME' => '/home/peter'}
105
+ File.expects(:open).with('/home/peter/.iplayer-dl', 'w').yields(StringIO.new)
106
+ prefs = IPlayer::Preferences.new(env, 'lunix')
107
+ prefs.subdirs = true
108
+ prefs.save
109
+ end
110
+
111
+ def test_should_write_to_preference_file_in_appdata_directory_on_windows
112
+ env = {'APPDATA' => 'C:\Documents and Settings\Peter\Application Data'}
113
+ File.expects(:open).with('C:\Documents and Settings\Peter\Application Data/iplayer-dl', 'w').yields(StringIO.new)
114
+ prefs = IPlayer::Preferences.new(env, 'i386-mswin32')
115
+ prefs.subdirs = true
116
+ prefs.save
117
+ end
118
+
119
+ def test_should_save_all_details
120
+ prefs = IPlayer::Preferences.new
121
+ io = StringIO.new(yaml = '')
122
+ File.stubs(:open).with(anything, 'w').yields(io)
123
+
124
+ prefs.type_preference = %w[foo bar]
125
+ prefs.download_path = '/nowhere'
126
+ prefs.http_proxy = 'localhost:3128'
127
+ prefs.subdirs = true
128
+ prefs.save
129
+
130
+ expected = {
131
+ 'type_preference' => %w[foo bar],
132
+ 'download_path' => '/nowhere',
133
+ 'http_proxy' => 'localhost:3128',
134
+ 'subdirs' => true
135
+ }
136
+
137
+ assert_equal expected, YAML.load(yaml)
138
+ end
139
+
140
+ def test_should_not_save_details_that_were_not_changed
141
+ prefs = IPlayer::Preferences.new
142
+ io = StringIO.new(yaml = '')
143
+ File.stubs(:open).with(anything, 'w').yields(io)
144
+
145
+ prefs.http_proxy = 'localhost:3128'
146
+ prefs.save
147
+
148
+ expected = {'http_proxy' => 'localhost:3128'}
149
+
150
+ assert_equal expected, YAML.load(yaml)
151
+ end
152
+
153
+ def test_should_not_save_details_that_were_set_to_the_same_value
154
+ prefs = IPlayer::Preferences.new
155
+ io = StringIO.new(yaml = '')
156
+ File.stubs(:open).with(anything, 'w').yields(io)
157
+
158
+ prefs.http_proxy = 'localhost:3128'
159
+ prefs.type_preference = prefs.type_preference
160
+ prefs.save
161
+
162
+ expected = {'http_proxy' => 'localhost:3128'}
163
+
164
+ assert_equal expected, YAML.load(yaml)
165
+ end
166
+
167
+ def test_should_not_save_at_all_if_nothing_has_changed
168
+ prefs = IPlayer::Preferences.new
169
+ File.expects(:open).with(anything, 'w').never
170
+
171
+ prefs.save
172
+ end
173
+
174
+ end
175
+
@@ -0,0 +1,57 @@
1
+ $:.unshift( File.join( File.dirname(__FILE__), '..', 'lib' ))
2
+ require 'test/unit'
3
+ require 'iplayer/subtitles'
4
+ require 'mocha'
5
+
6
+ class SubtitlesTest < Test::Unit::TestCase
7
+
8
+ def test_should_return_subtitles_if_found
9
+ selection = %{
10
+ <?xml version="1.0" encoding="UTF-8"?>
11
+ <mediaSelection xmlns="http://bbc.co.uk/2008/mp/mediaselection">
12
+ <media kind="captions"
13
+ expires="2009-01-31T20:59:00+00:00"
14
+ type="application/ttaf+xml" >
15
+ <connection
16
+ priority="10"
17
+ kind="http"
18
+ server="http://www.bbc.co.uk/iplayer/subtitles/"
19
+ identifier="ng/b00ftjq6_104732850.xml"
20
+ href="http://www.bbc.co.uk/iplayer/subtitles/ng/b00ftjq6_104732850.xml"
21
+ />
22
+ </media>
23
+ </mediaSelection>
24
+ }
25
+ expected = 'SUBTITLES'
26
+ browser = stub
27
+ browser.stubs(:get).with('http://www.bbc.co.uk/mediaselector/4/mtis/stream/b00ftjq6').returns(stub(:body => selection))
28
+ browser.stubs(:get).with('http://www.bbc.co.uk/iplayer/subtitles/ng/b00ftjq6_104732850.xml').returns(stub(:body => expected))
29
+ subtitles = IPlayer::Subtitles.new('b00ftjq6', browser)
30
+ assert_equal expected, subtitles.w3c_timed_text
31
+ end
32
+
33
+ def test_should_return_nil_if_no_subtitles_were_found
34
+ selection = %{
35
+ <?xml version="1.0" encoding="UTF-8"?>
36
+ <mediaSelection xmlns="http://bbc.co.uk/2008/mp/mediaselection">
37
+ <media kind=""
38
+ expires="2009-01-31T20:59:00+00:00"
39
+ type="video/mpeg"
40
+ encoding="h264" >
41
+ <connection
42
+ priority="10"
43
+ kind="sis"
44
+ server="http://www.bbc.co.uk/mediaselector/4/sdp/"
45
+ identifier="b00ftjq6/iplayer_streaming_n95_3g"
46
+ href="http://www.bbc.co.uk/mediaselector/4/sdp/b00ftjq6/iplayer_streaming_n95_3g"
47
+ />
48
+ </media>
49
+ </mediaSelection>
50
+ }
51
+ browser = stub
52
+ browser.stubs(:get).with('http://www.bbc.co.uk/mediaselector/4/mtis/stream/b00ftjq6').returns(stub(:body => selection))
53
+ subtitles = IPlayer::Subtitles.new('b00ftjq6', browser)
54
+ assert_nil subtitles.w3c_timed_text
55
+ end
56
+
57
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iplayer-dl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.16
5
+ platform: ruby
6
+ authors:
7
+ - Paul Battley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-11 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mocha
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: pbattley@gmail.com
27
+ executables:
28
+ - iplayer-dl
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - COPYING
35
+ - README
36
+ - setup.rb
37
+ - Rakefile
38
+ - lib/
39
+ - lib/iplayer
40
+ - lib/iplayer/version.rb
41
+ - lib/iplayer/browser.rb
42
+ - lib/iplayer/downloader.rb
43
+ - lib/iplayer/preferences.rb
44
+ - lib/iplayer/gui
45
+ - lib/iplayer/gui/app.rb
46
+ - lib/iplayer/gui/main_frame.rb
47
+ - lib/iplayer/subtitles.rb
48
+ - lib/iplayer/errors.rb
49
+ - lib/iplayer/metadata.rb
50
+ - lib/iplayer.rb
51
+ - test/
52
+ - test/test_preferences.rb
53
+ - test/test_metadata.rb
54
+ - test/test_subtitles.rb
55
+ - bin/
56
+ - bin/iplayer-dl
57
+ - bin/iplayer-dl-gui
58
+ - share/
59
+ - share/pixmaps
60
+ - share/pixmaps/iplayer-dl
61
+ - share/pixmaps/iplayer-dl/icon128.png
62
+ - share/pixmaps/iplayer-dl/icon48.png
63
+ - share/pixmaps/iplayer-dl/icon16.png
64
+ - share/pixmaps/iplayer-dl/icon32.png
65
+ - share/pixmaps/iplayer-dl/icon64.png
66
+ has_rdoc: false
67
+ homepage: http://po-ru.com/projects/iplayer-downloader
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.1
89
+ signing_key:
90
+ specification_version: 2
91
+ summary: Download iPlayer content
92
+ test_files: []
93
+