]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blob - test/youtube_test.rb
Made the output filename the responsibility of the website subclass.
[dead/whatever-dl.git] / test / youtube_test.rb
1 #
2 # Copyright Michael Orlitzky
3 #
4 # http://michael.orlitzky.com/
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # http://www.fsf.org/licensing/licenses/gpl.html
17 #
18
19 require 'test/unit'
20 require 'src/websites/youtube'
21
22 class YoutubeTest < Test::Unit::TestCase
23
24 def test_owns_youtube_urls
25 assert(Youtube.owns_url?('http://www.youtube.com/watch?v=SudixyugiX4'))
26 assert(Youtube.owns_url?('http://www.youtube.com/watch?v=SudixyugiX4&hl=en'))
27 assert(Youtube.owns_url?('http://youtube.com/watch?v=SudixyugiX4&hl=en'))
28 assert(Youtube.owns_url?('http://www.youtube.com/v/SudixyugiX4'))
29 assert(Youtube.owns_url?('http://www.youtube.com/v/SudixyugiX4&hl=en'))
30 assert(Youtube.owns_url?('http://youtube.com/v/SudixyugiX4&hl=en'))
31 assert(Youtube.owns_url?('http://www.youtube.com/watch?v=K9iDMcmm0tE'))
32 assert(Youtube.owns_url?('http://www.youtube.com/watch?v=K9iDMcmm0tE#'))
33 assert(Youtube.owns_url?('http://www.youtube.com/v/K9iDMcmm0tE'))
34 assert(Youtube.owns_url?('http://www.youtube.com/watch?v=83-hlYMH1XE'))
35 assert(Youtube.owns_url?('http://www.youtube.com/watch?v=83-hlYMH1XE&feature=dir'))
36 end
37
38
39 def test_doesnt_own_redtube_urls
40 assert(!Youtube.owns_url?('http://www.redtube.com/6807'))
41 assert(!Youtube.owns_url?('www.redtube.com/6807'))
42 assert(!Youtube.owns_url?('http://redtube.com/6807'))
43 assert(!Youtube.owns_url?('redtube.com/6807'))
44 end
45
46
47 def test_parse_video_id
48 yt = Youtube.new('http://www.youtube.com/watch?v=SudixyugiX4')
49 expected_result = 'SudixyugiX4'
50 actual_result = yt.send('parse_video_id')
51 assert_equal(expected_result, actual_result)
52 end
53
54
55 def test_parse_video_id_again
56 yt = Youtube.new('http://www.youtube.com/watch?v=K9iDMcmm0tE')
57 expected_result = 'K9iDMcmm0tE'
58 actual_result = yt.send('parse_video_id')
59 assert_equal(expected_result, actual_result)
60 end
61
62
63 def test_parse_t_parameter
64 yt = Youtube.new(nil)
65
66 page_data = nil
67
68 File.open('test/fixtures/youtube/SudixyugiX4.html') do |f|
69 page_data = f.read
70 end
71
72 expected_result = 'OEgsToPDskLQUAntWWpzhEMhBMlgqHdo'
73 actual_result = yt.send('parse_t_parameter', page_data)
74 assert_equal(expected_result, actual_result)
75 end
76
77
78 def test_parse_t_parameter_again
79 # This was failing once because my regex missed a hyphen.
80 # I modified the regex to match anything between the pair
81 # of quotes, so it should now catch the hyphen and underscore.
82 yt = Youtube.new(nil)
83
84 page_data = nil
85
86 File.open('test/fixtures/youtube/K9iDMcmm0tE.html') do |f|
87 page_data = f.read
88 end
89
90 expected_result = 'O_EgsToPDskJsXVvAXpAct1zug-lBJBz'
91 actual_result = yt.send('parse_t_parameter', page_data)
92 assert_equal(expected_result, actual_result)
93 end
94
95
96 def test_get_video_filename
97 yt = Youtube.new('http://www.youtube.com/watch?v=SudixyugiX4')
98 expected_result = 'SudixyugiX4.flv'
99 actual_result = yt.get_video_filename()
100 assert_equal(expected_result, actual_result)
101 end
102
103
104 def test_get_video_filename_again
105 yt = Youtube.new('http://www.youtube.com/watch?v=K9iDMcmm0tE')
106 expected_result = 'K9iDMcmm0tE.flv'
107 actual_result = yt.get_video_filename()
108 assert_equal(expected_result, actual_result)
109 end
110
111
112 def test_get_troublesome_video_filename_first_form
113 # This non-alphanumeric video id was causing
114 # get_video_filename to barf.
115 yt = Youtube.new('http://www.youtube.com/watch?v=83-hlYMH1XE&feature=dir')
116 expected_result = '83-hlYMH1XE.flv'
117 actual_result = yt.get_video_filename()
118 assert_equal(expected_result, actual_result)
119 end
120
121
122 def test_get_troublesome_video_filename_second_form
123 yt = Youtube.new('http://www.youtube.com/v/83-hlYMH1XE&feature=dir')
124 expected_result = '83-hlYMH1XE.flv'
125 actual_result = yt.get_video_filename()
126 assert_equal(expected_result, actual_result)
127 end
128
129 end