video_info 2.6.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/unit_test.yml +39 -0
  3. data/.gitignore +0 -1
  4. data/.rubocop.yml +242 -1
  5. data/CONTRIBUTING.md +11 -0
  6. data/Gemfile +1 -1
  7. data/Guardfile +2 -2
  8. data/README.md +29 -7
  9. data/lib/video_info.rb +25 -28
  10. data/lib/video_info/provider.rb +25 -12
  11. data/lib/video_info/providers/dailymotion.rb +19 -3
  12. data/lib/video_info/providers/vimeo.rb +3 -3
  13. data/lib/video_info/providers/vimeo_api.rb +20 -11
  14. data/lib/video_info/providers/vimeo_scraper.rb +93 -23
  15. data/lib/video_info/providers/wistia.rb +2 -1
  16. data/lib/video_info/providers/youtube.rb +16 -2
  17. data/lib/video_info/providers/youtube_api.rb +42 -8
  18. data/lib/video_info/providers/youtube_scraper.rb +64 -31
  19. data/lib/video_info/providers/youtubeplaylist.rb +5 -2
  20. data/lib/video_info/providers/youtubeplaylist_api.rb +22 -1
  21. data/lib/video_info/providers/youtubeplaylist_scraper.rb +16 -3
  22. data/lib/video_info/version.rb +1 -1
  23. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/_available_/with_invalid_video_url/_available_/1_2_2_1_1.yml +82 -0
  24. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/_available_/with_valid_video/_available_/1_2_1_1_1.yml +87 -0
  25. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_author/1_3_7_1.yml +91 -0
  26. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_author_thumbnail/1_3_9_1.yml +91 -0
  27. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_author_url/1_3_8_1.yml +91 -0
  28. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_date/should_show_correct_date.yml +91 -0
  29. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_description/1_3_10_1.yml +91 -0
  30. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_duration/1_3_12_1.yml +91 -0
  31. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_keywords/1_3_11_1.yml +91 -0
  32. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_thumbnail/1_3_21_1.yml +91 -0
  33. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_thumbnail_large/1_3_18_1.yml +91 -0
  34. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_thumbnail_medium/1_3_17_1.yml +91 -0
  35. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_thumbnail_small/1_3_16_1.yml +91 -0
  36. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_title/1_3_6_1.yml +91 -0
  37. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Dailymotion/with_video_x7lni3/_view_count/1_3_22_1.yml +91 -0
  38. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/_available_/with_password_required_video/_available_/1_2_3_1_1.yml +151 -0
  39. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/_available_/with_password_required_video/_available_/2_2_3_1_1.yml +68 -0
  40. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/_available_/with_this_video_does_not_exist_video/_available_/1_2_2_1_1.yml +127 -0
  41. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/_available_/with_this_video_does_not_exist_video/_available_/2_2_2_1_1.yml +70 -0
  42. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/_available_/with_valid_video/_available_/1_2_1_1_1.yml +158 -0
  43. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/_available_/with_valid_video/_available_/2_2_1_1_1.yml +68 -0
  44. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_unavailable_video/author/1_13_2_1.yml +130 -0
  45. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_unavailable_video/author_thumbnail/1_13_3_1.yml +130 -0
  46. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_unavailable_video/author_url/1_13_4_1.yml +132 -0
  47. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_unavailable_video/available_/1_13_1_1.yml +130 -0
  48. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_unavailable_video/date/1_13_7_1.yml +128 -0
  49. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_unavailable_video/description/1_13_6_1.yml +131 -0
  50. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_unavailable_video/duration/1_13_8_1.yml +130 -0
  51. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_unavailable_video/height/1_13_10_1.yml +131 -0
  52. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_unavailable_video/keywords/1_13_9_1.yml +128 -0
  53. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_unavailable_video/thumbnail_large/1_13_14_1.yml +129 -0
  54. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_unavailable_video/thumbnail_medium/1_13_13_1.yml +129 -0
  55. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_unavailable_video/thumbnail_small/1_13_12_1.yml +129 -0
  56. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_unavailable_video/title/1_13_5_1.yml +130 -0
  57. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_unavailable_video/view_count/1_13_15_1.yml +129 -0
  58. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_unavailable_video/width/1_13_11_1.yml +129 -0
  59. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_author/1_3_20_1.yml +158 -0
  60. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_author/2_3_20_1.yml +80 -0
  61. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_author_thumbnail/1_3_19_1.yml +158 -0
  62. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_author_thumbnail/2_3_19_1.yml +85 -0
  63. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_author_url/1_3_21_1.yml +159 -0
  64. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_author_url/2_3_21_1.yml +80 -0
  65. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_date/should_have_correct_upload_date.yml +240 -0
  66. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_description/1_3_7_1.yml +160 -0
  67. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_description/2_3_7_1.yml +80 -0
  68. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_duration/1_3_9_1.yml +158 -0
  69. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_duration/2_3_9_1.yml +85 -0
  70. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_height/1_3_11_1.yml +158 -0
  71. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_height/2_3_11_1.yml +80 -0
  72. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_keywords/should_return_a_string_list_of_keywords.yml +240 -0
  73. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_thumbnail/1_3_18_1.yml +236 -0
  74. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_thumbnail/2_3_18_1.yml +82 -0
  75. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_thumbnail_large/1_3_15_1.yml +236 -0
  76. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_thumbnail_large/2_3_15_1.yml +82 -0
  77. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_thumbnail_medium/1_3_14_1.yml +235 -0
  78. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_thumbnail_medium/2_3_14_1.yml +84 -0
  79. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_thumbnail_small/1_3_13_1.yml +236 -0
  80. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_thumbnail_small/2_3_13_1.yml +84 -0
  81. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_title/1_3_6_1.yml +159 -0
  82. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_title/2_3_6_1.yml +85 -0
  83. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_view_count/1_3_22_1.yml +158 -0
  84. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_view_count/2_3_22_1.yml +84 -0
  85. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_width/1_3_10_1.yml +156 -0
  86. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_136971428/_width/2_3_10_1.yml +82 -0
  87. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_141349194/thumbnail/1_12_1_1.yml +234 -0
  88. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_141349194/thumbnail/2_12_1_1.yml +78 -0
  89. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_141349194/thumbnail_large/1_12_2_1.yml +233 -0
  90. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_141349194/thumbnail_large/2_12_2_1.yml +78 -0
  91. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_141349194/thumbnail_medium/1_12_3_1.yml +235 -0
  92. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_141349194/thumbnail_medium/2_12_3_1.yml +73 -0
  93. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_141349194/thumbnail_small/1_12_4_1.yml +234 -0
  94. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_141349194/thumbnail_small/2_12_4_1.yml +77 -0
  95. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/_available_/with_invalid_video/_available_/1_2_2_1_1.yml +75 -0
  96. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/_available_/with_valid_video/_available_/1_2_1_1_1.yml +79 -0
  97. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_duration/1_4_7_1.yml +85 -0
  98. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_height/1_4_9_1.yml +85 -0
  99. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_thumbnail_large/1_4_12_1.yml +86 -0
  100. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_thumbnail_medium/1_4_11_1.yml +86 -0
  101. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_thumbnail_small/1_4_10_1.yml +85 -0
  102. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_title/1_4_6_1.yml +86 -0
  103. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_pxonqr42is/_width/1_4_8_1.yml +86 -0
  104. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_duration/1_3_7_1.yml +85 -0
  105. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_height/1_3_9_1.yml +87 -0
  106. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_thumbnail/1_3_15_1.yml +87 -0
  107. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_thumbnail_large/1_3_12_1.yml +87 -0
  108. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_thumbnail_medium/1_3_11_1.yml +87 -0
  109. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_thumbnail_small/1_3_10_1.yml +85 -0
  110. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_title/1_3_6_1.yml +85 -0
  111. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Wistia/with_video_rs1me54mpw/_width/1_3_8_1.yml +87 -0
  112. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_unavailable_video/_available_/1_2_2_1_1.yml +59 -0
  113. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_unavailable_video/_available_/2_2_2_1_1.yml +114 -0
  114. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_unavailable_video/_date/1_2_2_11_1.yml +59 -0
  115. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_unavailable_video/_date/2_2_2_11_1.yml +114 -0
  116. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_unavailable_video/_description/1_2_2_8_1.yml +59 -0
  117. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_unavailable_video/_description/2_2_2_8_1.yml +114 -0
  118. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_unavailable_video/_duration/1_2_2_10_1.yml +59 -0
  119. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_unavailable_video/_duration/2_2_2_10_1.yml +114 -0
  120. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_unavailable_video/_keywords/1_2_2_9_1.yml +59 -0
  121. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_unavailable_video/_keywords/2_2_2_9_1.yml +114 -0
  122. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_unavailable_video/_title/1_2_2_7_1.yml +59 -0
  123. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_unavailable_video/_title/2_2_2_7_1.yml +114 -0
  124. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_unavailable_video/_view_count/1_2_2_18_1.yml +59 -0
  125. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_unavailable_video/_view_count/2_2_2_18_1.yml +114 -0
  126. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_valid_video/_available_/1_2_1_1_1.yml +59 -0
  127. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_valid_video/_available_/2_2_1_1_1.yml +187 -0
  128. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_video_removed_because_of_copyright_claim/_available_/1_2_3_1_1.yml +59 -0
  129. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/_available_/with_video_removed_because_of_copyright_claim/_available_/2_2_3_1_1.yml +114 -0
  130. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_a_video_without_description/_description/1_1_1_1.yml +59 -0
  131. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_full_screen_video_URLs/_date/should_return_date_video_was_posted.yml +249 -0
  132. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_full_screen_video_URLs/_description/1_17_7_1.yml +59 -0
  133. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_full_screen_video_URLs/_description/2_17_7_1.yml +187 -0
  134. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_full_screen_video_URLs/_duration/1_17_9_1.yml +59 -0
  135. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_full_screen_video_URLs/_duration/2_17_9_1.yml +187 -0
  136. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_full_screen_video_URLs/_keywords/1_17_8_1.yml +59 -0
  137. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_full_screen_video_URLs/_keywords/2_17_8_1.yml +187 -0
  138. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_full_screen_video_URLs/_title/1_17_6_1.yml +59 -0
  139. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_full_screen_video_URLs/_title/2_17_6_1.yml +187 -0
  140. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_full_screen_video_URLs/_view_count/1_17_17_1.yml +59 -0
  141. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_full_screen_video_URLs/_view_count/2_17_17_1.yml +187 -0
  142. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_author/1_3_6_1.yml +115 -0
  143. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_author/2_3_6_1.yml +187 -0
  144. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_author_thumbnail/1_3_7_1.yml +115 -0
  145. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_author_thumbnail/2_3_7_1.yml +335 -0
  146. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_author_url/1_3_8_1.yml +59 -0
  147. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_author_url/2_3_8_1.yml +335 -0
  148. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_author_url/can_be_called_twice_and_receive_the_same_value.yml +391 -0
  149. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_date/should_return_date_video_was_posted.yml +243 -0
  150. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_description/1_3_10_1.yml +60 -0
  151. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_description/2_3_10_1.yml +187 -0
  152. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_duration/1_3_12_1.yml +59 -0
  153. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_duration/2_3_12_1.yml +187 -0
  154. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_keywords/1_3_11_1.yml +59 -0
  155. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_keywords/2_3_11_1.yml +187 -0
  156. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_title/1_3_9_1.yml +59 -0
  157. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_title/2_3_9_1.yml +187 -0
  158. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_view_count/1_3_21_1.yml +59 -0
  159. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/_view_count/2_3_21_1.yml +187 -0
  160. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/_available_/with_invalid_playlist/_available_/1_2_2_1_1.yml +120 -0
  161. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/_available_/with_list_url/_available_/1_2_3_1_1.yml +154 -0
  162. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/_available_/with_valid_playlist/_available_/1_2_1_1_1.yml +154 -0
  163. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_author/1_3_21_1.yml +165 -0
  164. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_author_thumbnail/1_3_22_1.yml +274 -0
  165. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_author_url/1_3_23_1.yml +274 -0
  166. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_description/1_3_7_1.yml +165 -0
  167. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_keywords/1_3_8_1.yml +165 -0
  168. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_thumbnail/1_3_18_1.yml +165 -0
  169. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_thumbnail_large/1_3_15_1.yml +165 -0
  170. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_thumbnail_large_2x/1_3_16_1.yml +165 -0
  171. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_thumbnail_maxres/1_3_17_1.yml +165 -0
  172. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_thumbnail_medium/1_3_14_1.yml +165 -0
  173. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_thumbnail_small/1_3_13_1.yml +165 -0
  174. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_title/1_3_6_1.yml +165 -0
  175. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_PL9hW1uS6HUftLdHI6RIsaf/_videos/returns_list_of_videos_in_playlist.yml +112 -0
  176. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_YoutubePlaylist/with_playlist_that_does_not_exist_in_embed_path/_videos/1_4_2_1.yml +114 -0
  177. data/spec/lib/video_info/provider_spec.rb +42 -22
  178. data/spec/lib/video_info/providers/dailymotion_spec.rb +75 -27
  179. data/spec/lib/video_info/providers/vimeo_spec.rb +270 -174
  180. data/spec/lib/video_info/providers/wistia_spec.rb +59 -20
  181. data/spec/lib/video_info/providers/youtube_playlist_spec.rb +97 -41
  182. data/spec/lib/video_info/providers/youtube_scraper_spec.rb +14 -0
  183. data/spec/lib/video_info/providers/youtube_spec.rb +441 -384
  184. data/spec/lib/video_info_spec.rb +27 -25
  185. data/spec/spec_helper.rb +6 -1
  186. data/tmp/rspec_guard_result +25 -0
  187. data/video_info.gemspec +11 -14
  188. metadata +358 -100
  189. data/.travis.yml +0 -13
  190. data/foo.txt +0 -33
  191. data/lib/video_info/providers/vkontakte.rb +0 -170
  192. data/spec/lib/video_info/providers/vimeo_api_spec.rb +0 -242
  193. data/spec/lib/video_info/providers/vkontakte_spec.rb +0 -173
  194. data/spec/lib/video_info/providers/youtube_api_spec.rb +0 -476
  195. data/spec/lib/video_info/providers/youtube_playlist_api_spec.rb +0 -187
@@ -1,8 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  require 'spec_helper'
3
3
 
4
- describe VideoInfo::Providers::Wistia do
5
-
4
+ describe VideoInfo::Providers::Wistia, :vcr do
6
5
  describe '.usable?' do
7
6
  subject { VideoInfo::Providers::Wistia.usable?(url) }
8
7
 
@@ -18,8 +17,9 @@ describe VideoInfo::Providers::Wistia do
18
17
  end
19
18
 
20
19
  describe '#available?' do
21
- context 'with valid video', :vcr do
22
- subject { VideoInfo.new('http://fast.wistia.net/embed/iframe/rs1me54mpw') }
20
+ context 'with valid video' do
21
+ video_url = 'http://fast.wistia.net/embed/iframe/rs1me54mpw'
22
+ subject { VideoInfo.new(video_url.freeze) }
23
23
 
24
24
  describe '#available?' do
25
25
  subject { super().available? }
@@ -27,7 +27,7 @@ describe VideoInfo::Providers::Wistia do
27
27
  end
28
28
  end
29
29
 
30
- context 'with invalid video', :vcr do
30
+ context 'with invalid video' do
31
31
  subject { VideoInfo.new('http://fast.wistia.net/embed/iframe/no_video') }
32
32
 
33
33
  describe '#available?' do
@@ -35,10 +35,9 @@ describe VideoInfo::Providers::Wistia do
35
35
  it { is_expected.to be_falsey }
36
36
  end
37
37
  end
38
-
39
38
  end
40
39
 
41
- context 'with video rs1me54mpw', :vcr do
40
+ context 'with video rs1me54mpw' do
42
41
  subject { VideoInfo.new('http://fast.wistia.net/embed/iframe/rs1me54mpw') }
43
42
 
44
43
  describe '#provider' do
@@ -63,7 +62,9 @@ describe VideoInfo::Providers::Wistia do
63
62
 
64
63
  describe '#embed_code' do
65
64
  subject { super().embed_code }
66
- it { is_expected.to eq '<iframe src="//fast.wistia.net/embed/iframe/rs1me54mpw" frameborder="0"></iframe>' }
65
+ embed_code = '<iframe src="//fast.wistia.net/embed/iframe/rs1me54mpw" '\
66
+ 'frameborder="0"></iframe>'
67
+ it { is_expected.to eq embed_code }
67
68
  end
68
69
 
69
70
  describe '#title' do
@@ -88,21 +89,48 @@ describe VideoInfo::Providers::Wistia do
88
89
 
89
90
  describe '#thumbnail_small' do
90
91
  subject { super().thumbnail_small }
91
- it { is_expected.to eq 'https://embed-ssl.wistia.com/deliveries/dc005e6a7583a25c4b7c284c08afc42fb67fdb95.jpg?image_crop_resized=960x540' }
92
+ thumbnail_url = 'https://embed-ssl.wistia.com/deliveries/' \
93
+ 'dc005e6a7583a25c4b7c284c08afc42fb67fdb95.jpg' \
94
+ '?image_crop_resized=960x540'
95
+ it { is_expected.to eq thumbnail_url }
92
96
  end
93
97
 
94
98
  describe '#thumbnail_medium' do
95
99
  subject { super().thumbnail_small }
96
- it { is_expected.to eq 'https://embed-ssl.wistia.com/deliveries/dc005e6a7583a25c4b7c284c08afc42fb67fdb95.jpg?image_crop_resized=960x540' }
100
+ thumbnail_url = 'https://embed-ssl.wistia.com/deliveries/' \
101
+ 'dc005e6a7583a25c4b7c284c08afc42fb67fdb95.jpg?' \
102
+ 'image_crop_resized=960x540'
103
+ it { is_expected.to eq thumbnail_url }
97
104
  end
98
-
105
+
99
106
  describe '#thumbnail_large' do
100
107
  subject { super().thumbnail_small }
101
- it { is_expected.to eq 'https://embed-ssl.wistia.com/deliveries/dc005e6a7583a25c4b7c284c08afc42fb67fdb95.jpg?image_crop_resized=960x540' }
108
+ thumbnail_url = 'https://embed-ssl.wistia.com/deliveries/' \
109
+ 'dc005e6a7583a25c4b7c284c08afc42fb67fdb95.jpg' \
110
+ '?image_crop_resized=960x540'
111
+ it { is_expected.to eq thumbnail_url }
112
+ end
113
+
114
+ describe '#thumbnail_large_2x' do
115
+ subject { super().thumbnail_large_2x }
116
+ it { is_expected.to be_nil }
117
+ end
118
+
119
+ describe '#thumbnail_maxres' do
120
+ subject { super().thumbnail_maxres }
121
+ it { is_expected.to be_nil }
122
+ end
123
+
124
+ describe '#thumbnail' do
125
+ subject { super().thumbnail }
126
+ thumbnail_url = 'https://embed-ssl.wistia.com/deliveries/' \
127
+ 'dc005e6a7583a25c4b7c284c08afc42fb67fdb95.jpg' \
128
+ '?image_crop_resized=960x540'
129
+ it { is_expected.to eq thumbnail_url }
102
130
  end
103
131
  end
104
132
 
105
- context 'with video pxonqr42is', :vcr do
133
+ context 'with video pxonqr42is' do
106
134
  subject { VideoInfo.new('http://fast.wistia.com/embed/medias/pxonqr42is') }
107
135
 
108
136
  describe '#provider' do
@@ -127,7 +155,9 @@ describe VideoInfo::Providers::Wistia do
127
155
 
128
156
  describe '#embed_code' do
129
157
  subject { super().embed_code }
130
- it { is_expected.to eq '<iframe src="//fast.wistia.net/embed/iframe/pxonqr42is" frameborder="0"></iframe>' }
158
+ embed_code = '<iframe src="//fast.wistia.net/embed/iframe/pxonqr42is" ' \
159
+ 'frameborder="0"></iframe>'
160
+ it { is_expected.to eq embed_code }
131
161
  end
132
162
 
133
163
  describe '#title' do
@@ -137,7 +167,7 @@ describe VideoInfo::Providers::Wistia do
137
167
 
138
168
  describe '#duration' do
139
169
  subject { super().duration }
140
- it { is_expected.to eq 250.0 }
170
+ it { is_expected.to eq 250.428 }
141
171
  end
142
172
 
143
173
  describe '#width' do
@@ -147,22 +177,31 @@ describe VideoInfo::Providers::Wistia do
147
177
 
148
178
  describe '#height' do
149
179
  subject { super().height }
150
- it { is_expected.to eq 568 }
180
+ it { is_expected.to eq 540 }
151
181
  end
152
-
182
+
153
183
  describe '#thumbnail_small' do
154
184
  subject { super().thumbnail_small }
155
- it { is_expected.to eq 'https://embed-ssl.wistia.com/deliveries/0fccbdc60ade35723f79f1c002bc61b135b610fa.jpg?image_crop_resized=960x540' }
185
+ thumbnail_url = 'https://embed-ssl.wistia.com/deliveries/' \
186
+ '0fccbdc60ade35723f79f1c002bc61b135b610fa.jpg' \
187
+ '?image_crop_resized=960x540'
188
+ it { is_expected.to eq thumbnail_url }
156
189
  end
157
190
 
158
191
  describe '#thumbnail_medium' do
159
192
  subject { super().thumbnail_small }
160
- it { is_expected.to eq 'https://embed-ssl.wistia.com/deliveries/0fccbdc60ade35723f79f1c002bc61b135b610fa.jpg?image_crop_resized=960x540' }
193
+ thumbnail_url = 'https://embed-ssl.wistia.com/deliveries/' \
194
+ '0fccbdc60ade35723f79f1c002bc61b135b610fa.jpg' \
195
+ '?image_crop_resized=960x540'
196
+ it { is_expected.to eq thumbnail_url }
161
197
  end
162
198
 
163
199
  describe '#thumbnail_large' do
164
200
  subject { super().thumbnail_small }
165
- it { is_expected.to eq 'https://embed-ssl.wistia.com/deliveries/0fccbdc60ade35723f79f1c002bc61b135b610fa.jpg?image_crop_resized=960x540' }
201
+ thumbnail_url = 'https://embed-ssl.wistia.com/deliveries/' \
202
+ '0fccbdc60ade35723f79f1c002bc61b135b610fa.jpg' \
203
+ '?image_crop_resized=960x540'
204
+ it { is_expected.to eq thumbnail_url }
166
205
  end
167
206
  end
168
207
  end
@@ -1,37 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe VideoInfo::Providers::YoutubePlaylist do
4
- before(:all) do
5
- VideoInfo.provider_api_keys = {}
3
+ describe VideoInfo::Providers::YoutubePlaylist, :vcr do
4
+ before(:each) do
5
+ api_key = ENV["YOUTUBE_API_KEY"] || "youtube_api_key_123"
6
+ VideoInfo.provider_api_keys = { youtube: api_key }
6
7
  end
7
8
 
8
- describe ".usable?" do
9
+ describe '.usable?' do
9
10
  subject { VideoInfo::Providers::YoutubePlaylist.usable?(url) }
10
11
 
11
- context "with youtube.com/playlist?p= url" do
12
+ context 'with youtube.com/playlist?p= url' do
12
13
  let(:url) { 'http://www.youtube.com/playlist?p=PLA575C81A1FBC04CF' }
13
14
  it { is_expected.to be_truthy }
14
15
  end
15
16
 
16
- context "with youtube.com/playlist?list= url" do
17
+ context 'with youtube.com/playlist?list= url' do
17
18
  let(:url) { 'http://www.youtube.com/playlist?list=PLA575C81A1FBC04CF' }
18
19
  it { is_expected.to be_truthy }
19
20
  end
20
21
 
21
- context "with youtube.com url" do
22
+ context 'with youtube.com url' do
22
23
  let(:url) { 'http://www.youtube.com/watch?v=Xp6CXF' }
23
24
  it { is_expected.to be_falsey }
24
25
  end
25
26
 
26
- context "with other url" do
27
+ context 'with other url' do
27
28
  let(:url) { 'http://example.com/video1' }
28
29
  it { is_expected.to be_falsey }
29
30
  end
30
31
  end
31
32
 
32
- describe "#available?" do
33
- context "with valid playlist", :vcr do
34
- subject { VideoInfo.new('http://www.youtube.com/playlist?p=PLA575C81A1FBC04CF') }
33
+ describe '#available?' do
34
+ context 'with valid playlist' do
35
+ playlist_url = 'http://www.youtube.com/playlist?p=PLA575C81A1FBC04CF'
36
+ subject { VideoInfo.new(playlist_url.freeze) }
35
37
 
36
38
  describe '#available?' do
37
39
  subject { super().available? }
@@ -39,8 +41,10 @@ describe VideoInfo::Providers::YoutubePlaylist do
39
41
  end
40
42
  end
41
43
 
42
- context "with invalid playlist", :vcr do
43
- subject { VideoInfo.new('http://www.youtube.com/playlist?p=PLA575C81A1FBC04CF_invalid') }
44
+ context 'with invalid playlist' do
45
+ invalid_playlist_url = 'http://www.youtube.com/playlist?' \
46
+ 'p=PLA575C81A1FBC04CF_invalid'
47
+ subject { VideoInfo.new(invalid_playlist_url) }
44
48
 
45
49
  describe '#available?' do
46
50
  subject { super().available? }
@@ -48,8 +52,9 @@ describe VideoInfo::Providers::YoutubePlaylist do
48
52
  end
49
53
  end
50
54
 
51
- context "with &list= url", :vcr do
52
- subject { VideoInfo.new('http://www.youtube.com/playlist?list=PLA575C81A1FBC04CF') }
55
+ context 'with &list= url' do
56
+ playlist_url = 'http://www.youtube.com/playlist?list=PLA575C81A1FBC04CF'
57
+ subject { VideoInfo.new(playlist_url) }
53
58
 
54
59
  describe '#available?' do
55
60
  subject { super().available? }
@@ -58,18 +63,17 @@ describe VideoInfo::Providers::YoutubePlaylist do
58
63
  end
59
64
  end
60
65
 
61
- context "with playlist PL9hW1uS6HUftLdHI6RIsaf", :vcr do
62
- let(:videos) {
66
+ context 'with playlist PL9hW1uS6HUftLdHI6RIsaf' do
67
+ let(:video_ids) do
63
68
  [
64
- VideoInfo.new('http://www.youtube.com/watch?v=Oi67QjrXy2w'),
65
- VideoInfo.new('http://www.youtube.com/watch?v=_Bt3-WsHfB0'),
66
- VideoInfo.new('http://www.youtube.com/watch?v=9g2U12SsRns'),
67
- VideoInfo.new('http://www.youtube.com/watch?v=8b0aEoxqqC0'),
68
- VideoInfo.new('http://www.youtube.com/watch?v=6c3mHikRz0I'),
69
- VideoInfo.new('http://www.youtube.com/watch?v=OQVHWsTHcoc')
69
+ "9g2U12SsRns", "AsqTAkLKb4M", "K681ILSXyUY", "OQVHWsTHcoc", "QtwplSG6VvM", "WK8qRNSmhEU", "XIoGq39abMk", "eKkv1C_O-QI", "lau14lhZpoU", "HvplY9BPKG8", "mTdNi9Mqiu8", "qAVwpBZ1HYA"
70
70
  ]
71
- }
72
- subject { VideoInfo.new('http://www.youtube.com/playlist?p=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr') }
71
+ end
72
+
73
+ playlist_url = 'http://www.youtube.com/playlist?' \
74
+ 'p=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr'
75
+
76
+ subject { VideoInfo.new(playlist_url) }
73
77
 
74
78
  describe '#provider' do
75
79
  subject { super().provider }
@@ -83,17 +87,23 @@ describe VideoInfo::Providers::YoutubePlaylist do
83
87
 
84
88
  describe '#url' do
85
89
  subject { super().url }
86
- it { is_expected.to eq 'http://www.youtube.com/playlist?p=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr' }
90
+ it { is_expected.to eq playlist_url }
87
91
  end
88
92
 
89
93
  describe '#embed_url' do
90
94
  subject { super().embed_url }
91
- it { is_expected.to eq '//www.youtube.com/embed/videoseries?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr' }
95
+ embed_url = '//www.youtube.com/embed/videoseries' \
96
+ '?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr'
97
+ it { is_expected.to eq embed_url }
92
98
  end
93
99
 
94
100
  describe '#embed_code' do
95
101
  subject { super().embed_code }
96
- it { is_expected.to eq '<iframe src="//www.youtube.com/embed/videoseries?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr" frameborder="0" allowfullscreen="allowfullscreen"></iframe>' }
102
+ embed_code = '<iframe src="//www.youtube.com/embed/videoseries' \
103
+ '?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr" ' \
104
+ 'frameborder="0" allowfullscreen="allowfullscreen">' \
105
+ '</iframe>'
106
+ it { is_expected.to eq embed_code }
97
107
  end
98
108
 
99
109
  describe '#title' do
@@ -103,7 +113,9 @@ describe VideoInfo::Providers::YoutubePlaylist do
103
113
 
104
114
  describe '#description' do
105
115
  subject { super().description }
106
- it { is_expected.to eq 'Learn more about copyright basics, flagging, and the YouTube community.' }
116
+ description_text = 'Learn more about copyright basics, flagging, ' \
117
+ 'and the YouTube community.'
118
+ it { is_expected.to eq description_text }
107
119
  end
108
120
 
109
121
  describe '#keywords' do
@@ -133,32 +145,76 @@ describe VideoInfo::Providers::YoutubePlaylist do
133
145
 
134
146
  describe '#thumbnail_small' do
135
147
  subject { super().thumbnail_small }
136
- it { is_expected.to eq 'https://i.ytimg.com/vi/8b0aEoxqqC0/default.jpg' }
148
+ thumbnail_url = 'https://i.ytimg.com/vi/9g2U12SsRns/default.jpg'
149
+ it { is_expected.to eq thumbnail_url }
137
150
  end
138
151
 
139
152
  describe '#thumbnail_medium' do
140
153
  subject { super().thumbnail_medium }
141
- it { is_expected.to eq 'https://i.ytimg.com/vi/8b0aEoxqqC0/mqdefault.jpg' }
154
+ thumbnail_url = 'https://i.ytimg.com/vi/9g2U12SsRns/mqdefault.jpg'
155
+ it { is_expected.to eq thumbnail_url }
142
156
  end
143
157
 
144
158
  describe '#thumbnail_large' do
145
159
  subject { super().thumbnail_large }
146
- it { is_expected.to eq 'https://i.ytimg.com/vi/8b0aEoxqqC0/hqdefault.jpg' }
160
+ thumbnail_url = 'https://i.ytimg.com/vi/9g2U12SsRns/hqdefault.jpg'
161
+ it { is_expected.to eq thumbnail_url }
162
+ end
163
+
164
+ describe '#thumbnail_large_2x' do
165
+ subject { super().thumbnail_large_2x }
166
+ thumbnail_url = 'https://i.ytimg.com/vi/9g2U12SsRns/sddefault.jpg'
167
+ it { is_expected.to eq thumbnail_url }
168
+ end
169
+
170
+ describe '#thumbnail_maxres' do
171
+ subject { super().thumbnail_maxres }
172
+ thumbnail_url = 'https://i.ytimg.com/vi/9g2U12SsRns/maxresdefault.jpg'
173
+ it { is_expected.to eq thumbnail_url }
174
+ end
175
+
176
+ describe '#thumbnail' do
177
+ subject { super().thumbnail }
178
+ thumbnail_url = 'https://i.ytimg.com/vi/9g2U12SsRns/default.jpg'
179
+ it { is_expected.to eq thumbnail_url }
147
180
  end
148
181
 
149
182
  describe '#videos' do
150
- subject { super().videos }
151
- it { expect { subject }.to raise_error(NotImplementedError) }
183
+ subject { super().videos.map(&:video_id) }
184
+ it 'returns list of videos in playlist' do
185
+ is_expected.to match_array(video_ids)
186
+ end
152
187
  end
153
188
 
154
189
  describe '#view_count' do
155
190
  subject { super().view_count }
156
191
  it { is_expected.to be_nil }
157
192
  end
193
+
194
+ describe '#author' do
195
+ subject { super().author }
196
+ it { is_expected.to eq 'TeamYouTube [Help]' }
197
+ end
198
+
199
+ describe '#author_thumbnail' do
200
+ subject { super().author_thumbnail }
201
+ author_thumbnail = 'https://yt3.ggpht.com/a/' \
202
+ 'AATXAJwyEv0uEyk3JLskjLiUCqSVzsGmpWw2icLfBOBzWg' \
203
+ '=s88-c-k-c0x00ffffff-no-rj'
204
+ it { is_expected.to eq author_thumbnail }
205
+ end
206
+
207
+ describe '#author_url' do
208
+ subject { super().author_url }
209
+ author_url = 'https://www.youtube.com/channel/UCMDQxm7cUx3yXkfeHa5zJIQ'
210
+ it { is_expected.to eq author_url }
211
+ end
158
212
  end
159
213
 
160
- context "with playlist PL0E8117603D70E10A in embed path", :vcr do
161
- subject { VideoInfo.new('http://www.youtube.com/embed/videoseries?list=PL0E8117603D70E10A') }
214
+ context 'with playlist that does not exist in embed path' do
215
+ playlist_url = 'http://www.youtube.com/embed/videoseries?' \
216
+ 'list=PL0E8117603D70E10A'
217
+ subject { VideoInfo.new(playlist_url) }
162
218
 
163
219
  describe '#playlist_id' do
164
220
  subject { super().playlist_id }
@@ -167,18 +223,18 @@ describe VideoInfo::Providers::YoutubePlaylist do
167
223
 
168
224
  describe '#videos' do
169
225
  subject { super().videos }
170
- it { expect { subject }.to raise_error(NotImplementedError) }
226
+ it { is_expected.to eq [] }
171
227
  end
172
228
  end
173
229
 
174
- context "with playlist PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr in embed path", :vcr do
175
- subject { VideoInfo.new('http://www.youtube.com/embed/videoseries?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr') }
230
+ context 'with playlist valid playlist in embed path' do
231
+ playlist_url = 'http://www.youtube.com/embed/videoseries' \
232
+ '?list=PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr'
233
+ subject { VideoInfo.new(playlist_url) }
176
234
 
177
235
  describe '#playlist_id' do
178
236
  subject { super().playlist_id }
179
237
  it { is_expected.to eq 'PL9hW1uS6HUftLdHI6RIsaf-iXTm09qnEr' }
180
238
  end
181
239
  end
182
-
183
-
184
240
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe VideoInfo::Providers::Youtube do
4
+ before { VideoInfo.provider_api_keys = {} }
5
+
6
+ context 'with a video without description', :vcr do
7
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=WVsj2pS-zFY') }
8
+
9
+ describe '#description' do
10
+ subject { super().description }
11
+ it { is_expected.to eq " " }
12
+ end
13
+ end
14
+ end
@@ -1,67 +1,160 @@
1
1
  require 'spec_helper'
2
- require 'webmock/rspec'
3
2
 
4
- describe VideoInfo::Providers::Youtube do
5
- describe ".usable?" do
6
- subject { VideoInfo::Providers::Youtube.usable?(url) }
7
-
8
- context "with youtube.com url" do
9
- let(:url) { 'http://www.youtube.com/watch?v=Xp6CXF' }
10
- it { is_expected.to be_truthy }
3
+ [nil, ENV["YOUTUBE_API_KEY"] || "youtube_api_key_123"].each do |api_key|
4
+ describe VideoInfo::Providers::Youtube, :vcr do
5
+ before(:all) do
6
+ VideoInfo.provider_api_keys = { youtube: api_key }
11
7
  end
12
8
 
13
- context "with youtu.be url" do
14
- let(:url) { 'http://youtu.be/JM9NgvjjVng' }
15
- it { is_expected.to be_truthy }
16
- end
9
+ describe '.usable?' do
10
+ subject { VideoInfo::Providers::Youtube.usable?(url) }
17
11
 
18
- context "with other url" do
19
- let(:url) { 'http://google.com/video1' }
20
- it { is_expected.to be_falsey }
21
- end
12
+ context 'with youtube.com url' do
13
+ let(:url) { 'http://www.youtube.com/watch?v=Xp6CXF' }
14
+ it { is_expected.to be_truthy }
15
+ end
22
16
 
23
- context "with playlist url" do
24
- let(:url) { 'http://www.youtube.com/playlist?p=PLA575C81A1FBC04CF' }
25
- it { is_expected.to be_falsey }
26
- end
27
- end
17
+ context 'with youtu.be url' do
18
+ let(:url) { 'http://youtu.be/JM9NgvjjVng' }
19
+ it { is_expected.to be_truthy }
20
+ end
28
21
 
29
- describe "#available?" do
30
- context "with valid video", :vcr do
31
- subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
22
+ context 'with other url' do
23
+ let(:url) { 'http://google.com/video1' }
24
+ it { is_expected.to be_falsey }
25
+ end
32
26
 
33
- describe '#available?' do
34
- subject { super().available? }
35
- it { is_expected.to be_truthy }
27
+ context 'with playlist url' do
28
+ let(:url) { 'http://www.youtube.com/playlist?p=PLA575C81A1FBC04CF' }
29
+ it { is_expected.to be_falsey }
36
30
  end
37
31
  end
38
32
 
39
- context 'with valid video and invalid API key' do
40
- subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
41
- let(:msg) { 'your API key is probably invalid. Please verify it.' }
42
- before do
43
- VideoInfo.provider_api_keys[:youtube] = 'invalid_key'
44
- end
33
+ describe '#available?' do
34
+ context 'with valid video' do
35
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4'.freeze) }
45
36
 
46
- after do
47
- VideoInfo.provider_api_keys[:youtube] = nil
37
+ describe '#available?' do
38
+ subject { super().available? }
39
+ it { is_expected.to be_truthy }
40
+ end
48
41
  end
49
42
 
50
- describe '#available?' do
51
- it 'logs warning message to alert user about invalid API key' do
52
- expect(VideoInfo.logger).to receive(:warn).with(msg)
53
- subject.title
43
+ context 'with unavailable video' do
44
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=SUkXvWn1m7Q') }
45
+
46
+ describe '#available?' do
47
+ subject { super().available? }
48
+ it { is_expected.to be_falsey }
49
+ end
50
+
51
+ describe '#provider' do
52
+ subject { super().provider }
53
+ it { is_expected.to eq 'YouTube' }
54
+ end
55
+
56
+ describe '#video_id' do
57
+ subject { super().video_id }
58
+ it { is_expected.to eq 'SUkXvWn1m7Q' }
59
+ end
60
+
61
+ describe '#url' do
62
+ subject { super().url }
63
+ it { is_expected.to eq 'http://www.youtube.com/watch?v=SUkXvWn1m7Q' }
64
+ end
65
+
66
+ describe '#embed_url' do
67
+ subject { super().embed_url }
68
+ it { is_expected.to eq '//www.youtube.com/embed/SUkXvWn1m7Q' }
69
+ end
70
+
71
+ describe '#embed_code' do
72
+ subject { super().embed_code }
73
+ embed_code = '<iframe src="//www.youtube.com/embed/SUkXvWn1m7Q" ' \
74
+ 'frameborder="0" allowfullscreen="allowfullscreen">' \
75
+ '</iframe>'
76
+ it { is_expected.to eq embed_code }
77
+ end
78
+
79
+ describe '#title' do
80
+ subject { super().title }
81
+ it { is_expected.to eq nil }
82
+ end
83
+
84
+ describe '#description' do
85
+ subject { super().description }
86
+ it { is_expected.to eq nil }
87
+ end
88
+
89
+ describe '#keywords' do
90
+ subject { super().keywords }
91
+ it { is_expected.to be_nil }
92
+ end
93
+
94
+ describe '#duration' do
95
+ subject { super().duration }
96
+ it { is_expected.to eq 0 }
97
+ end
98
+
99
+ describe '#date' do
100
+ subject { super().date }
101
+ it { is_expected.to eq nil }
102
+ end
103
+
104
+ describe '#thumbnail_small' do
105
+ subject { super().thumbnail_small }
106
+ thumbnail_url = 'https://i.ytimg.com/vi/SUkXvWn1m7Q/default.jpg'
107
+ it { is_expected.to eq thumbnail_url }
108
+ end
109
+
110
+ describe '#thumbnail_medium' do
111
+ subject { super().thumbnail_medium }
112
+ thumbnail_url = 'https://i.ytimg.com/vi/SUkXvWn1m7Q/mqdefault.jpg'
113
+ it { is_expected.to eq thumbnail_url }
114
+ end
115
+
116
+ describe '#thumbnail_large' do
117
+ subject { super().thumbnail_large }
118
+ thumbnail_url = 'https://i.ytimg.com/vi/SUkXvWn1m7Q/hqdefault.jpg'
119
+ it { is_expected.to eq thumbnail_url }
120
+ end
121
+
122
+ describe '#thumbnail_large_2x' do
123
+ subject { super().thumbnail_large_2x }
124
+ thumbnail_url = 'https://i.ytimg.com/vi/SUkXvWn1m7Q/sddefault.jpg'
125
+ it { is_expected.to eq thumbnail_url }
126
+ end
127
+
128
+ describe '#thumbnail_maxres' do
129
+ subject { super().thumbnail_maxres }
130
+ thumbnail_url = 'https://i.ytimg.com/vi/SUkXvWn1m7Q/maxresdefault.jpg'
131
+ it { is_expected.to eq thumbnail_url }
132
+ end
133
+
134
+ describe '#thumbnail' do
135
+ subject { super().thumbnail }
136
+ thumbnail_url = 'https://i.ytimg.com/vi/SUkXvWn1m7Q/hqdefault.jpg'
137
+ it { is_expected.to eq thumbnail_url }
138
+ end
139
+
140
+ describe '#view_count' do
141
+ subject { super().view_count }
142
+ it { is_expected.to be == 0 }
54
143
  end
55
144
  end
56
- end
57
145
 
58
- context "with 'video is unavailable' video", :vcr do
59
- subject { VideoInfo.new('http://www.youtube.com/watch?v=SUkXvWn1m7Q') }
146
+ context 'with video removed because of copyright claim' do
147
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=ffClNhwx0KU') }
60
148
 
61
- describe '#available?' do
62
- subject { super().available? }
63
- it { is_expected.to be_falsey }
149
+ describe '#available?' do
150
+ subject { super().available? }
151
+ it { is_expected.to be_falsey }
152
+ end
64
153
  end
154
+ end
155
+
156
+ context 'with video mZqGqE0D0n4' do
157
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
65
158
 
66
159
  describe '#provider' do
67
160
  subject { super().provider }
@@ -70,472 +163,436 @@ describe VideoInfo::Providers::Youtube do
70
163
 
71
164
  describe '#video_id' do
72
165
  subject { super().video_id }
73
- it { is_expected.to eq 'SUkXvWn1m7Q' }
166
+ it { is_expected.to eq 'mZqGqE0D0n4' }
74
167
  end
75
168
 
76
169
  describe '#url' do
77
170
  subject { super().url }
78
- it { is_expected.to eq 'http://www.youtube.com/watch?v=SUkXvWn1m7Q' }
171
+ it { is_expected.to eq 'http://www.youtube.com/watch?v=mZqGqE0D0n4' }
79
172
  end
80
173
 
81
174
  describe '#embed_url' do
82
175
  subject { super().embed_url }
83
- it { is_expected.to eq '//www.youtube.com/embed/SUkXvWn1m7Q' }
176
+ it { is_expected.to eq '//www.youtube.com/embed/mZqGqE0D0n4' }
84
177
  end
85
178
 
86
179
  describe '#embed_code' do
87
180
  subject { super().embed_code }
88
- it { is_expected.to eq '<iframe src="//www.youtube.com/embed/SUkXvWn1m7Q" frameborder="0" allowfullscreen="allowfullscreen"></iframe>' }
181
+ embed_code = '<iframe src="//www.youtube.com/embed/mZqGqE0D0n4" ' \
182
+ 'frameborder="0" allowfullscreen="allowfullscreen">' \
183
+ '</iframe>'
184
+ it { is_expected.to eq embed_code }
185
+ end
186
+
187
+ describe '#author' do
188
+ subject { super().author }
189
+ it { is_expected.to eql 'Cherry Bloom' }
190
+ end
191
+
192
+ describe '#author_thumbnail' do
193
+ subject { super().author_thumbnail }
194
+ author_thumbnail = 'https://yt3.ggpht.com/a/' \
195
+ 'AATXAJyf5l8p3WQvOx-Q0o8ssGmIL-K5taxKHv5ZEEYc' \
196
+ '=s88-c-k-c0x00ffffff-no-rj'
197
+
198
+ it { is_expected.to eql author_thumbnail }
199
+ end
200
+
201
+ describe '#author_url' do
202
+ author_url = 'https://www.youtube.com/channel/UCzxQk-rZGowoqMBKxGD5jSA'
203
+
204
+ it { expect(subject.author_url).to eql(author_url) }
205
+
206
+ it 'can be called twice and receive the same value' do
207
+ expect(subject.author_url).to eq(subject.author_url)
208
+ end
89
209
  end
90
210
 
91
211
  describe '#title' do
92
212
  subject { super().title }
93
- it { is_expected.to eq nil }
213
+ it { is_expected.to eq 'Cherry Bloom - King Of The Knife' }
94
214
  end
95
215
 
96
216
  describe '#description' do
97
217
  subject { super().description }
98
- it { is_expected.to eq nil }
218
+ description = 'The first video from the upcoming album Secret Sounds,' \
219
+ ' to download in-stores April 14. ' \
220
+ 'Checkout http://www.cherrybloom.net'
221
+ it { is_expected.to eq description }
99
222
  end
100
223
 
101
224
  describe '#keywords' do
102
225
  subject { super().keywords }
103
- it { is_expected.to be_nil }
226
+ keywords_list = %w(cherry bloom king of the knife guitar
227
+ drum clip rock alternative tremplin Paris-Forum)
228
+ it { is_expected.to eq keywords_list }
104
229
  end
105
230
 
106
231
  describe '#duration' do
107
232
  subject { super().duration }
108
- it { is_expected.to eq 0 }
233
+ it { is_expected.to eq 176 }
234
+ end
235
+
236
+ describe '#width' do
237
+ subject { super().width }
238
+ it { is_expected.to be_nil }
239
+ end
240
+
241
+ describe '#height' do
242
+ subject { super().height }
243
+ it { is_expected.to be_nil }
109
244
  end
110
245
 
111
246
  describe '#date' do
112
247
  subject { super().date }
113
- it { is_expected.to eq nil }
248
+
249
+ it 'should return date video was posted' do
250
+ if api_key.nil?
251
+ is_expected.to eq Time.parse('Sat Apr 12 2008', Time.now.utc)
252
+ else
253
+ is_expected.to eq Time.parse('Sat Apr 12 22:34:48 UTC 2008',
254
+ Time.now.utc)
255
+ end
256
+ end
114
257
  end
115
258
 
116
259
  describe '#thumbnail_small' do
117
260
  subject { super().thumbnail_small }
118
- it { is_expected.to eq 'https://i.ytimg.com/vi/SUkXvWn1m7Q/default.jpg' }
261
+ thumbnail_url = 'https://i.ytimg.com/vi/mZqGqE0D0n4/default.jpg'
262
+ it { is_expected.to eq thumbnail_url }
119
263
  end
120
264
 
121
265
  describe '#thumbnail_medium' do
122
266
  subject { super().thumbnail_medium }
123
- it { is_expected.to eq 'https://i.ytimg.com/vi/SUkXvWn1m7Q/mqdefault.jpg' }
267
+ thumbnail_url = 'https://i.ytimg.com/vi/mZqGqE0D0n4/mqdefault.jpg'
268
+ it { is_expected.to eq thumbnail_url }
124
269
  end
125
270
 
126
271
  describe '#thumbnail_large' do
127
272
  subject { super().thumbnail_large }
128
- it { is_expected.to eq 'https://i.ytimg.com/vi/SUkXvWn1m7Q/hqdefault.jpg' }
273
+ thumbnail_url = 'https://i.ytimg.com/vi/mZqGqE0D0n4/hqdefault.jpg'
274
+ it { is_expected.to eq thumbnail_url }
129
275
  end
130
276
 
131
- describe '#view_count' do
132
- subject { super().view_count }
133
- it { is_expected.to be == 0 }
277
+ describe '#thumbnail_large_2x' do
278
+ subject { super().thumbnail_large_2x }
279
+ thumbnail_url = 'https://i.ytimg.com/vi/mZqGqE0D0n4/sddefault.jpg'
280
+ it { is_expected.to eq thumbnail_url }
134
281
  end
135
- end
136
-
137
- context "with 'video no longer available due to a copyright claim' video", :vcr do
138
- subject { VideoInfo.new('http://www.youtube.com/watch?v=ffClNhwx0KU') }
139
282
 
140
- describe '#available?' do
141
- subject { super().available? }
142
- it { is_expected.to be_falsey }
283
+ describe '#thumbnail_maxres' do
284
+ subject { super().thumbnail_maxres }
285
+ thumbnail_url = 'https://i.ytimg.com/vi/mZqGqE0D0n4/maxresdefault.jpg'
286
+ it { is_expected.to eq thumbnail_url }
143
287
  end
144
- end
145
- end
146
-
147
- context "with video mZqGqE0D0n4", :vcr do
148
- subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
149
-
150
- describe '#provider' do
151
- subject { super().provider }
152
- it { is_expected.to eq 'YouTube' }
153
- end
154
-
155
- describe '#video_id' do
156
- subject { super().video_id }
157
- it { is_expected.to eq 'mZqGqE0D0n4' }
158
- end
159
-
160
- describe '#url' do
161
- subject { super().url }
162
- it { is_expected.to eq 'http://www.youtube.com/watch?v=mZqGqE0D0n4' }
163
- end
164
-
165
- describe '#embed_url' do
166
- subject { super().embed_url }
167
- it { is_expected.to eq '//www.youtube.com/embed/mZqGqE0D0n4' }
168
- end
169
-
170
- describe '#embed_code' do
171
- subject { super().embed_code }
172
- it { is_expected.to eq '<iframe src="//www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen"></iframe>' }
173
- end
174
-
175
- describe '#title' do
176
- subject { super().title }
177
- it { is_expected.to eq 'Cherry Bloom - King Of The Knife' }
178
- end
179
-
180
- describe '#description' do
181
- subject { super().description }
182
- it { is_expected.to eq 'The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net' }
183
- end
184
-
185
- describe '#keywords' do
186
- subject { super().keywords }
187
- it { is_expected.to eq %w(cherry bloom king of the knife guitar drum clip rock alternative tremplin Paris-Forum) }
188
- end
189
-
190
- describe '#duration' do
191
- subject { super().duration }
192
- it { is_expected.to eq 176 }
193
- end
194
-
195
- describe '#width' do
196
- subject { super().width }
197
- it { is_expected.to be_nil }
198
- end
199
-
200
- describe '#height' do
201
- subject { super().height }
202
- it { is_expected.to be_nil }
203
- end
204
-
205
- describe '#date' do
206
- subject { super().date }
207
- it { is_expected.to eq Time.parse('Sat Apr 12 2008', Time.now.utc) }
208
- end
209
-
210
- describe '#thumbnail_small' do
211
- subject { super().thumbnail_small }
212
- it { is_expected.to eq 'https://i.ytimg.com/vi/mZqGqE0D0n4/default.jpg' }
213
- end
214
-
215
- describe '#thumbnail_medium' do
216
- subject { super().thumbnail_medium }
217
- it { is_expected.to eq 'https://i.ytimg.com/vi/mZqGqE0D0n4/mqdefault.jpg' }
218
- end
219
-
220
- describe '#thumbnail_large' do
221
- subject { super().thumbnail_large }
222
- it { is_expected.to eq 'https://i.ytimg.com/vi/mZqGqE0D0n4/hqdefault.jpg' }
223
- end
224
-
225
- describe '#view_count' do
226
- subject { super().view_count }
227
- it { is_expected.to be > 4000 }
228
- end
229
- end
230
-
231
- context "with video oQ49W_xKzKA", :vcr do
232
- subject { VideoInfo.new('http://www.youtube.com/watch?v=oQ49W_xKzKA') }
233
-
234
- it { expect(subject.embed_code(url_attributes: { autoplay: 1 })).to match(/autoplay=1/) }
235
- end
236
-
237
- context "with video oQ49W_xKzKA", :vcr do
238
- subject { VideoInfo.new('http://www.youtube.com/watch?v=oQ49W_xKzKA') }
239
-
240
- describe '#provider' do
241
- subject { super().provider }
242
- it { is_expected.to eq 'YouTube' }
243
- end
244
288
 
245
- describe '#video_id' do
246
- subject { super().video_id }
247
- it { is_expected.to eq 'oQ49W_xKzKA' }
289
+ describe '#view_count' do
290
+ subject { super().view_count }
291
+ it { is_expected.to be > 4000 }
292
+ end
248
293
  end
249
- end
250
294
 
251
- context "with video Xp6CXF-Cesg", :vcr do
252
- subject { VideoInfo.new('http://www.youtube.com/watch?v=Xp6CXF-Cesg') }
295
+ context 'with video oQ49W_xKzKA' do
296
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=oQ49W_xKzKA') }
253
297
 
254
- describe '#provider' do
255
- subject { super().provider }
256
- it { is_expected.to eq 'YouTube' }
257
- end
258
-
259
- describe '#video_id' do
260
- subject { super().video_id }
261
- it { is_expected.to eq 'Xp6CXF-Cesg' }
298
+ it 'should properly apply arbitrary url attributes' do
299
+ embed_code = subject.embed_code(url_attributes: { autoplay: 1 })
300
+ expect(embed_code).to match(/autoplay=1/)
301
+ end
262
302
  end
263
- end
264
303
 
265
- context "with video VeasFckfMHY in user url", :vcr do
266
- subject { VideoInfo.new('http://www.youtube.com/user/EducatorVids3?v=VeasFckfMHY') }
304
+ context 'with video oQ49W_xKzKA' do
305
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=oQ49W_xKzKA') }
267
306
 
268
- describe '#provider' do
269
- subject { super().provider }
270
- it { is_expected.to eq 'YouTube' }
271
- end
307
+ describe '#provider' do
308
+ subject { super().provider }
309
+ it { is_expected.to eq 'YouTube' }
310
+ end
272
311
 
273
- describe '#video_id' do
274
- subject { super().video_id }
275
- it { is_expected.to eq 'VeasFckfMHY' }
312
+ describe '#video_id' do
313
+ subject { super().video_id }
314
+ it { is_expected.to eq 'oQ49W_xKzKA' }
315
+ end
276
316
  end
277
317
 
278
- describe '#url' do
279
- subject { super().url }
280
- it { is_expected.to eq 'http://www.youtube.com/user/EducatorVids3?v=VeasFckfMHY' }
281
- end
282
- end
318
+ context 'with video Xp6CXF-Cesg' do
319
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=Xp6CXF-Cesg') }
283
320
 
284
- context "with video VeasFckfMHY after params", :vcr do
285
- subject { VideoInfo.new('http://www.youtube.com/watch?feature=player_profilepage&v=VeasFckfMHY') }
321
+ describe '#provider' do
322
+ subject { super().provider }
323
+ it { is_expected.to eq 'YouTube' }
324
+ end
286
325
 
287
- describe '#provider' do
288
- subject { super().provider }
289
- it { is_expected.to eq 'YouTube' }
326
+ describe '#video_id' do
327
+ subject { super().video_id }
328
+ it { is_expected.to eq 'Xp6CXF-Cesg' }
329
+ end
290
330
  end
291
331
 
292
- describe '#video_id' do
293
- subject { super().video_id }
294
- it { is_expected.to eq 'VeasFckfMHY' }
295
- end
332
+ context 'with video VeasFckfMHY in user url' do
333
+ video_url = 'http://www.youtube.com/user/EducatorVids3?v=VeasFckfMHY'
334
+ subject { VideoInfo.new(video_url) }
296
335
 
297
- describe '#url' do
298
- subject { super().url }
299
- it { is_expected.to eq 'http://www.youtube.com/watch?feature=player_profilepage&v=VeasFckfMHY' }
300
- end
301
- end
336
+ describe '#provider' do
337
+ subject { super().provider }
338
+ it { is_expected.to eq 'YouTube' }
339
+ end
302
340
 
303
- context "with video VeasFckfMHY in path", :vcr do
304
- subject { VideoInfo.new('http://www.youtube.com/v/VeasFckfMHY') }
341
+ describe '#video_id' do
342
+ subject { super().video_id }
343
+ it { is_expected.to eq 'VeasFckfMHY' }
344
+ end
305
345
 
306
- describe '#provider' do
307
- subject { super().provider }
308
- it { is_expected.to eq 'YouTube' }
346
+ describe '#url' do
347
+ subject { super().url }
348
+ it { is_expected.to eq video_url }
349
+ end
309
350
  end
310
351
 
311
- describe '#video_id' do
312
- subject { super().video_id }
313
- it { is_expected.to eq 'VeasFckfMHY' }
314
- end
315
- end
352
+ context 'with video VeasFckfMHY after params' do
353
+ video_url = 'http://www.youtube.com/watch?feature=player_profilepage&v=VeasFckfMHY'
354
+ subject { VideoInfo.new(video_url) }
316
355
 
317
- context "with video VeasFckfMHY in e path", :vcr do
318
- subject { VideoInfo.new('http://www.youtube.com/e/VeasFckfMHY') }
356
+ describe '#provider' do
357
+ subject { super().provider }
358
+ it { is_expected.to eq 'YouTube' }
359
+ end
319
360
 
320
- describe '#provider' do
321
- subject { super().provider }
322
- it { is_expected.to eq 'YouTube' }
323
- end
361
+ describe '#video_id' do
362
+ subject { super().video_id }
363
+ it { is_expected.to eq 'VeasFckfMHY' }
364
+ end
324
365
 
325
- describe '#video_id' do
326
- subject { super().video_id }
327
- it { is_expected.to eq 'VeasFckfMHY' }
366
+ describe '#url' do
367
+ subject { super().url }
368
+ it { is_expected.to eq video_url }
369
+ end
328
370
  end
329
- end
330
371
 
331
- context "with video VeasFckfMHY in embed path", :vcr do
332
- subject { VideoInfo.new('http://www.youtube.com/embed/VeasFckfMHY') }
372
+ context 'with video VeasFckfMHY in path' do
373
+ subject { VideoInfo.new('http://www.youtube.com/v/VeasFckfMHY') }
333
374
 
334
- describe '#provider' do
335
- subject { super().provider }
336
- it { is_expected.to eq 'YouTube' }
337
- end
375
+ describe '#provider' do
376
+ subject { super().provider }
377
+ it { is_expected.to eq 'YouTube' }
378
+ end
338
379
 
339
- describe '#video_id' do
340
- subject { super().video_id }
341
- it { is_expected.to eq 'VeasFckfMHY' }
380
+ describe '#video_id' do
381
+ subject { super().video_id }
382
+ it { is_expected.to eq 'VeasFckfMHY' }
383
+ end
342
384
  end
343
- end
344
385
 
345
- context "with video JM9NgvjjVng in youtu.be url", :vcr do
346
- subject { VideoInfo.new('http://youtu.be/JM9NgvjjVng') }
386
+ context 'with video VeasFckfMHY in e path' do
387
+ subject { VideoInfo.new('http://www.youtube.com/e/VeasFckfMHY') }
347
388
 
348
- describe '#provider' do
349
- subject { super().provider }
350
- it { is_expected.to eq 'YouTube' }
351
- end
389
+ describe '#provider' do
390
+ subject { super().provider }
391
+ it { is_expected.to eq 'YouTube' }
392
+ end
352
393
 
353
- describe '#video_id' do
354
- subject { super().video_id }
355
- it { is_expected.to eq 'JM9NgvjjVng' }
394
+ describe '#video_id' do
395
+ subject { super().video_id }
396
+ it { is_expected.to eq 'VeasFckfMHY' }
397
+ end
356
398
  end
357
- end
358
399
 
359
- context 'without http or www', :vcr do
360
- subject { VideoInfo.new('youtu.be/JM9NgvjjVng') }
400
+ context 'with video VeasFckfMHY in embed path' do
401
+ subject { VideoInfo.new('http://www.youtube.com/embed/VeasFckfMHY') }
361
402
 
362
- describe '#provider' do
363
- subject { super().provider }
364
- it { is_expected.to eq('YouTube') }
365
- end
403
+ describe '#provider' do
404
+ subject { super().provider }
405
+ it { is_expected.to eq 'YouTube' }
406
+ end
366
407
 
367
- describe '#video_id' do
368
- subject { super().video_id }
369
- it { is_expected.to eq 'JM9NgvjjVng' }
408
+ describe '#video_id' do
409
+ subject { super().video_id }
410
+ it { is_expected.to eq 'VeasFckfMHY' }
411
+ end
370
412
  end
371
- end
372
413
 
373
- context "with video url in text", :vcr do
374
- subject { VideoInfo.new('<a href="http://www.youtube.com/watch?v=mZqGqE0D0n4">http://www.youtube.com/watch?v=mZqGqE0D0n4</a>') }
414
+ context 'with video JM9NgvjjVng in youtu.be url' do
415
+ subject { VideoInfo.new('http://youtu.be/JM9NgvjjVng') }
375
416
 
376
- describe '#provider' do
377
- subject { super().provider }
378
- it { is_expected.to eq('YouTube') }
379
- end
417
+ describe '#provider' do
418
+ subject { super().provider }
419
+ it { is_expected.to eq 'YouTube' }
420
+ end
380
421
 
381
- describe '#video_id' do
382
- subject { super().video_id }
383
- it { is_expected.to eq('mZqGqE0D0n4') }
422
+ describe '#video_id' do
423
+ subject { super().video_id }
424
+ it { is_expected.to eq 'JM9NgvjjVng' }
425
+ end
384
426
  end
385
- end
386
427
 
387
- context "with iframe attributes", :vcr do
388
- subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
389
-
390
- describe '#provider' do
391
- subject { super().provider }
392
- it { is_expected.to eq('YouTube') }
393
- end
394
- it { expect(subject.embed_code(iframe_attributes: { width: 800, height: 600 })).to match(/width="800"/) }
395
- it { expect(subject.embed_code(iframe_attributes: { width: 800, height: 600 })).to match(/height="600"/) }
396
- end
428
+ context 'without http or www' do
429
+ subject { VideoInfo.new('youtu.be/JM9NgvjjVng') }
397
430
 
398
- context "with arbitrary iframe_attributes", :vcr do
399
- subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
431
+ describe '#provider' do
432
+ subject { super().provider }
433
+ it { is_expected.to eq('YouTube') }
434
+ end
400
435
 
401
- describe '#provider' do
402
- subject { super().provider }
403
- it { is_expected.to eq('YouTube') }
436
+ describe '#video_id' do
437
+ subject { super().video_id }
438
+ it { is_expected.to eq 'JM9NgvjjVng' }
439
+ end
404
440
  end
405
- it { expect(subject.embed_code(iframe_attributes: { :'data-colorbox' => true })).to match(/data-colorbox="true"/) }
406
- end
407
441
 
408
- context "URL without http:// or https://" do
409
- subject { VideoInfo.new('www.youtube.com/watch?v=ylTY9WbMGDc') }
442
+ context 'with video url in text' do
443
+ url_in_text = '<a href="http://www.youtube.com/watch?v=mZqGqE0D0n4">' \
444
+ 'http://www.youtube.com/watch?v=mZqGqE0D0n4</a>'
445
+ subject { VideoInfo.new(url_in_text) }
410
446
 
411
- describe '#title' do
412
- subject { super().title }
413
- it { is_expected.to eq ('Deafheaven - Sunbather') }
414
- end
415
- end
416
-
417
- context "with full screen video URLs", :vcr do
418
- subject { VideoInfo.new('http://www.youtube.com/v/mZqGqE0D0n4') }
447
+ describe '#provider' do
448
+ subject { super().provider }
449
+ it { is_expected.to eq('YouTube') }
450
+ end
419
451
 
420
- describe '#provider' do
421
- subject { super().provider }
422
- it { is_expected.to eq 'YouTube' }
452
+ describe '#video_id' do
453
+ subject { super().video_id }
454
+ it { is_expected.to eq('mZqGqE0D0n4') }
455
+ end
423
456
  end
424
457
 
425
- describe '#video_id' do
426
- subject { super().video_id }
427
- it { is_expected.to eq 'mZqGqE0D0n4' }
428
- end
458
+ context 'with iframe attributes' do
459
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
429
460
 
430
- describe '#url' do
431
- subject { super().url }
432
- it { is_expected.to eq 'http://www.youtube.com/v/mZqGqE0D0n4' }
433
- end
461
+ describe '#provider' do
462
+ subject { super().provider }
463
+ it { is_expected.to eq('YouTube') }
464
+ end
434
465
 
435
- describe '#embed_url' do
436
- subject { super().embed_url }
437
- it { is_expected.to eq '//www.youtube.com/embed/mZqGqE0D0n4' }
466
+ it 'should properly apply dimensions attributes' do
467
+ dimensions = { width: 800, height: 600 }
468
+ embed_code = subject.embed_code(iframe_attributes: dimensions)
469
+ expect(embed_code).to match(/width="800"/)
470
+ expect(embed_code).to match(/height="600"/)
471
+ end
438
472
  end
439
473
 
440
- describe '#embed_code' do
441
- subject { super().embed_code }
442
- it { is_expected.to eq '<iframe src="//www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen"></iframe>' }
443
- end
474
+ context 'with arbitrary iframe_attributes' do
475
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
444
476
 
445
- describe '#title' do
446
- subject { super().title }
447
- it { is_expected.to eq 'Cherry Bloom - King Of The Knife' }
448
- end
477
+ describe '#provider' do
478
+ subject { super().provider }
479
+ it { is_expected.to eq('YouTube') }
480
+ end
449
481
 
450
- describe '#description' do
451
- subject { super().description }
452
- it { is_expected.to eq 'The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net' }
482
+ it 'should properly apply arbitrary attributes' do
483
+ attributes = { :'data-colorbox' => true }
484
+ embed_code = subject.embed_code(iframe_attributes: attributes)
485
+ expect(embed_code).to match(/data-colorbox="true"/)
486
+ end
453
487
  end
454
488
 
455
- describe '#keywords' do
456
- subject { super().keywords }
457
- it { is_expected.to eq %w(cherry bloom king of the knife guitar drum clip rock alternative tremplin Paris-Forum) }
458
- end
489
+ context 'with full screen video URLs' do
490
+ subject { VideoInfo.new('http://www.youtube.com/v/mZqGqE0D0n4') }
459
491
 
460
- describe '#duration' do
461
- subject { super().duration }
462
- it { is_expected.to eq 176 }
463
- end
492
+ describe '#provider' do
493
+ subject { super().provider }
494
+ it { is_expected.to eq 'YouTube' }
495
+ end
464
496
 
465
- describe '#width' do
466
- subject { super().width }
467
- it { is_expected.to be_nil }
468
- end
497
+ describe '#video_id' do
498
+ subject { super().video_id }
499
+ it { is_expected.to eq 'mZqGqE0D0n4' }
500
+ end
469
501
 
470
- describe '#height' do
471
- subject { super().height }
472
- it { is_expected.to be_nil }
473
- end
502
+ describe '#url' do
503
+ subject { super().url }
504
+ it { is_expected.to eq 'http://www.youtube.com/v/mZqGqE0D0n4' }
505
+ end
474
506
 
475
- describe '#date' do
476
- subject { super().date }
477
- it { is_expected.to eq Time.parse('Sat Apr 12 2008', Time.now.utc) }
478
- end
507
+ describe '#embed_url' do
508
+ subject { super().embed_url }
509
+ it { is_expected.to eq '//www.youtube.com/embed/mZqGqE0D0n4' }
510
+ end
479
511
 
480
- describe '#thumbnail_small' do
481
- subject { super().thumbnail_small }
482
- it { is_expected.to eq 'https://i.ytimg.com/vi/mZqGqE0D0n4/default.jpg' }
483
- end
512
+ describe '#embed_code' do
513
+ subject { super().embed_code }
514
+ embed_code = '<iframe src="//www.youtube.com/embed/mZqGqE0D0n4" ' \
515
+ 'frameborder="0" allowfullscreen="allowfullscreen">' \
516
+ '</iframe>'
517
+ it { is_expected.to eq embed_code }
518
+ end
484
519
 
485
- describe '#thumbnail_medium' do
486
- subject { super().thumbnail_medium }
487
- it { is_expected.to eq 'https://i.ytimg.com/vi/mZqGqE0D0n4/mqdefault.jpg' }
488
- end
520
+ describe '#title' do
521
+ subject { super().title }
522
+ it { is_expected.to eq 'Cherry Bloom - King Of The Knife' }
523
+ end
489
524
 
490
- describe '#thumbnail_large' do
491
- subject { super().thumbnail_large }
492
- it { is_expected.to eq 'https://i.ytimg.com/vi/mZqGqE0D0n4/hqdefault.jpg' }
493
- end
525
+ describe '#description' do
526
+ subject { super().description }
527
+ description = 'The first video from the upcoming album Secret Sounds,' \
528
+ ' to download in-stores April 14. ' \
529
+ 'Checkout http://www.cherrybloom.net'
530
+ it { is_expected.to eq description }
531
+ end
494
532
 
495
- describe '#view_count' do
496
- subject { super().view_count }
497
- it { is_expected.to be > 4000 }
498
- end
499
- end
533
+ describe '#keywords' do
534
+ subject { super().keywords }
535
+ keywords_list = %w(cherry bloom king of the knife guitar
536
+ drum clip rock alternative tremplin Paris-Forum)
537
+ it { is_expected.to eq keywords_list }
538
+ end
500
539
 
540
+ describe '#duration' do
541
+ subject { super().duration }
542
+ it { is_expected.to eq 176 }
543
+ end
501
544
 
502
- context "with full screen video URLs with params", :vcr do
503
- subject { VideoInfo.new('https://www.youtube.com/v/ylTY9WbMGDc?someParam=foo') }
545
+ describe '#width' do
546
+ subject { super().width }
547
+ it { is_expected.to be_nil }
548
+ end
504
549
 
505
- describe '#title' do
506
- subject { super().title }
507
- it { is_expected.to eq 'Deafheaven - Sunbather' }
508
- end
509
- end
550
+ describe '#height' do
551
+ subject { super().height }
552
+ it { is_expected.to be_nil }
553
+ end
510
554
 
511
- context 'with valid video and connection timeout' do
512
- subject { VideoInfo.new('https://www.youtube.com/watch?v=lExm5LELpP4') }
555
+ describe '#date' do
556
+ subject { super().date }
513
557
 
514
- describe '#title' do
515
- before do
516
- @stubbed = stub_request(:get, 'https://www.youtube.com/watch?v=lExm5LELpP4').to_timeout
558
+ it 'should return date video was posted' do
559
+ if api_key.nil?
560
+ is_expected.to eq Time.parse('Sat Apr 12 2008', Time.now.utc)
561
+ else
562
+ is_expected.to eq Time.parse('Sat Apr 12 22:34:48 UTC 2008',
563
+ Time.now.utc)
564
+ end
565
+ end
517
566
  end
518
567
 
519
- after do
520
- remove_request_stub(@stubbed) if @stubbed
568
+ describe '#thumbnail_small' do
569
+ subject { super().thumbnail_small }
570
+ thumbnail_url = 'https://i.ytimg.com/vi/mZqGqE0D0n4/default.jpg'
571
+ it { is_expected.to eq thumbnail_url }
521
572
  end
522
573
 
523
- it 'raises VideoInfo::HttpError exception' do
524
- expect { subject.title }.to raise_error VideoInfo::HttpError
574
+ describe '#thumbnail_medium' do
575
+ subject { super().thumbnail_medium }
576
+ thumbnail_url = 'https://i.ytimg.com/vi/mZqGqE0D0n4/mqdefault.jpg'
577
+ it { is_expected.to eq thumbnail_url }
525
578
  end
526
- end
527
- end
528
579
 
529
- context 'with valid video and OpenURI::HTTPError exception' do
530
- subject { VideoInfo.new('https://www.youtube.com/watch?v=lExm5LELpP4') }
580
+ describe '#thumbnail_large' do
581
+ subject { super().thumbnail_large }
582
+ thumbnail_url = 'https://i.ytimg.com/vi/mZqGqE0D0n4/hqdefault.jpg'
583
+ it { is_expected.to eq thumbnail_url }
584
+ end
531
585
 
532
- describe '#title' do
533
- before do
534
- stub_request(:get, 'https://www.youtube.com/watch?v=lExm5LELpP4').to_raise(OpenURI::HTTPError.new('error', :nop))
586
+ describe '#thumbnail_large_2x' do
587
+ subject { super().thumbnail_large_2x }
588
+ thumbnail_url = 'https://i.ytimg.com/vi/mZqGqE0D0n4/sddefault.jpg'
589
+ it { is_expected.to eq thumbnail_url }
535
590
  end
536
591
 
537
- it 'raises VideoInfo::HttpError exception' do
538
- expect { subject.title }.to raise_error VideoInfo::HttpError
592
+ describe '#view_count' do
593
+ subject { super().view_count }
594
+
595
+ it { is_expected.to eq 7962 }
539
596
  end
540
597
  end
541
598
  end