]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blob - test/youtube_test.rb
Modified the Youtube class to accept in.youtube.com URLs.
[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 assert(Youtube.owns_url?('http://in.youtube.com/watch?v=VcydqSpYN00&feature=channel_page'))
37 end
38
39
40 def test_doesnt_own_redtube_urls
41 assert(!Youtube.owns_url?('http://www.redtube.com/6807'))
42 assert(!Youtube.owns_url?('www.redtube.com/6807'))
43 assert(!Youtube.owns_url?('http://redtube.com/6807'))
44 assert(!Youtube.owns_url?('redtube.com/6807'))
45 end
46
47
48 def test_parse_video_id
49 yt = Youtube.new('http://www.youtube.com/watch?v=SudixyugiX4')
50 expected_result = 'SudixyugiX4'
51 actual_result = yt.send('parse_video_id')
52 assert_equal(expected_result, actual_result)
53 end
54
55
56 def test_parse_video_id_again
57 yt = Youtube.new('http://www.youtube.com/watch?v=K9iDMcmm0tE')
58 expected_result = 'K9iDMcmm0tE'
59 actual_result = yt.send('parse_video_id')
60 assert_equal(expected_result, actual_result)
61 end
62
63
64 def test_parse_t_parameter
65 yt = Youtube.new(nil)
66
67 page_data = nil
68
69 File.open('test/fixtures/youtube/SudixyugiX4.html') do |f|
70 page_data = f.read
71 end
72
73 expected_result = 'OEgsToPDskLQUAntWWpzhEMhBMlgqHdo'
74 actual_result = yt.send('parse_t_parameter', page_data)
75 assert_equal(expected_result, actual_result)
76 end
77
78
79 def test_parse_t_parameter_again
80 # This was failing once because my regex missed a hyphen.
81 # I modified the regex to match anything between the pair
82 # of quotes, so it should now catch the hyphen and underscore.
83 yt = Youtube.new(nil)
84
85 page_data = nil
86
87 File.open('test/fixtures/youtube/K9iDMcmm0tE.html') do |f|
88 page_data = f.read
89 end
90
91 expected_result = 'O_EgsToPDskJsXVvAXpAct1zug-lBJBz'
92 actual_result = yt.send('parse_t_parameter', page_data)
93 assert_equal(expected_result, actual_result)
94 end
95
96
97 def test_get_video_filename
98 yt = Youtube.new('http://www.youtube.com/watch?v=SudixyugiX4')
99 expected_result = 'SudixyugiX4.flv'
100 actual_result = yt.get_video_filename()
101 assert_equal(expected_result, actual_result)
102 end
103
104
105 def test_get_video_filename_again
106 yt = Youtube.new('http://www.youtube.com/watch?v=K9iDMcmm0tE')
107 expected_result = 'K9iDMcmm0tE.flv'
108 actual_result = yt.get_video_filename()
109 assert_equal(expected_result, actual_result)
110 end
111
112
113 def test_get_troublesome_video_filename_first_form
114 # This non-alphanumeric video id was causing
115 # get_video_filename to barf.
116 yt = Youtube.new('http://www.youtube.com/watch?v=83-hlYMH1XE&feature=dir')
117 expected_result = '83-hlYMH1XE.flv'
118 actual_result = yt.get_video_filename()
119 assert_equal(expected_result, actual_result)
120 end
121
122
123 def test_get_troublesome_video_filename_second_form
124 yt = Youtube.new('http://www.youtube.com/v/83-hlYMH1XE&feature=dir')
125 expected_result = '83-hlYMH1XE.flv'
126 actual_result = yt.get_video_filename()
127 assert_equal(expected_result, actual_result)
128 end
129
130 end