2 # Copyright Michael Orlitzky
4 # http://michael.orlitzky.com/
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.
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.
16 # http://www.fsf.org/licensing/licenses/gpl.html
20 require 'src/websites/youtube'
22 class YoutubeTest
< Test
::Unit::TestCase
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 assert(Youtube
.owns_url
?('http://uk.youtube.com/watch?v=LN4Ov6ZLcrI'))
38 assert(Youtube
.owns_url
?('http://www.youtube.com/meetlocalbiz#p/u/0/rJVWV4aA6Jk'))
42 def test_doesnt_own_redtube_urls
43 assert(!Youtube
.owns_url
?('http://www.redtube.com/6807'))
44 assert(!Youtube
.owns_url
?('www.redtube.com/6807'))
45 assert(!Youtube
.owns_url
?('http://redtube.com/6807'))
46 assert(!Youtube
.owns_url
?('redtube.com/6807'))
50 def test_parse_video_id
51 yt
= Youtube
.new('http://www.youtube.com/watch?v=SudixyugiX4')
52 expected_result
= 'SudixyugiX4'
53 actual_result
= yt
.send('parse_video_id')
54 assert_equal(expected_result
, actual_result
)
58 def test_parse_video_id_again
59 yt
= Youtube
.new('http://www.youtube.com/watch?v=K9iDMcmm0tE')
60 expected_result
= 'K9iDMcmm0tE'
61 actual_result
= yt
.send('parse_video_id')
62 assert_equal(expected_result
, actual_result
)
66 def test_get_video_filename
67 yt
= Youtube
.new('http://www.youtube.com/watch?v=SudixyugiX4')
68 expected_result
= 'SudixyugiX4.flv'
69 actual_result
= yt
.get_video_filename()
70 assert_equal(expected_result
, actual_result
)
74 def test_get_video_filename_again
75 yt
= Youtube
.new('http://www.youtube.com/watch?v=K9iDMcmm0tE')
76 expected_result
= 'K9iDMcmm0tE.flv'
77 actual_result
= yt
.get_video_filename()
78 assert_equal(expected_result
, actual_result
)
82 def test_get_troublesome_video_filename_first_form
83 # This non-alphanumeric video id was causing
84 # get_video_filename to barf.
85 yt
= Youtube
.new('http://www.youtube.com/watch?v=83-hlYMH1XE&feature=dir')
86 expected_result
= '83-hlYMH1XE.flv'
87 actual_result
= yt
.get_video_filename()
88 assert_equal(expected_result
, actual_result
)
92 def test_get_troublesome_video_filename_second_form
93 yt
= Youtube
.new('http://www.youtube.com/v/83-hlYMH1XE&feature=dir')
94 expected_result
= '83-hlYMH1XE.flv'
95 actual_result
= yt
.get_video_filename()
96 assert_equal(expected_result
, actual_result
)