regular_videos_extract_spec.cr 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. require "../../parsers_helper.cr"
  2. Spectator.describe "parse_video_info" do
  3. it "parses a regular video" do
  4. # Enable mock
  5. _player = load_mock("video/regular_mrbeast.player")
  6. _next = load_mock("video/regular_mrbeast.next")
  7. raw_data = _player.merge!(_next)
  8. info = parse_video_info("2isYuQZMbdU", raw_data)
  9. # Some basic verifications
  10. expect(typeof(info)).to eq(Hash(String, JSON::Any))
  11. expect(info["videoType"].as_s).to eq("Video")
  12. # Basic video infos
  13. expect(info["title"].as_s).to eq("I Gave My 100,000,000th Subscriber An Island")
  14. expect(info["views"].as_i).to eq(220_226_287)
  15. expect(info["likes"].as_i).to eq(6_870_691)
  16. # For some reason the video length from VideoDetails and the
  17. # one from microformat differs by 1s...
  18. expect(info["lengthSeconds"].as_i).to be_between(930_i64, 931_i64)
  19. expect(info["published"].as_s).to eq("2022-08-04T00:00:00Z")
  20. # Extra video infos
  21. expect(info["allowedRegions"].as_a).to_not be_empty
  22. expect(info["allowedRegions"].as_a.size).to eq(249)
  23. expect(info["allowedRegions"].as_a).to contain(
  24. "AD", "BA", "BB", "BW", "BY", "EG", "GG", "HN", "NP", "NR", "TR",
  25. "TT", "TV", "TW", "TZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU",
  26. "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"
  27. )
  28. expect(info["keywords"].as_a).to be_empty
  29. expect(info["allowRatings"].as_bool).to be_true
  30. expect(info["isFamilyFriendly"].as_bool).to be_true
  31. expect(info["isListed"].as_bool).to be_true
  32. expect(info["isUpcoming"].as_bool).to be_false
  33. # Related videos
  34. expect(info["relatedVideos"].as_a.size).to eq(20)
  35. expect(info["relatedVideos"][0]["id"]).to eq("krsBRQbOPQ4")
  36. expect(info["relatedVideos"][0]["title"]).to eq("$1 vs $250,000,000 Private Island!")
  37. expect(info["relatedVideos"][0]["author"]).to eq("MrBeast")
  38. expect(info["relatedVideos"][0]["ucid"]).to eq("UCX6OQ3DkcsbYNE6H8uQQuVA")
  39. expect(info["relatedVideos"][0]["view_count"]).to eq("230617484")
  40. expect(info["relatedVideos"][0]["short_view_count"]).to eq("230M")
  41. expect(info["relatedVideos"][0]["author_verified"]).to eq("true")
  42. # Description
  43. description = "🚀Launch a store on Shopify, I’ll buy from 100 random stores that do ▸ "
  44. expect(info["description"].as_s).to start_with(description)
  45. expect(info["shortDescription"].as_s).to start_with(description)
  46. expect(info["descriptionHtml"].as_s).to start_with(description)
  47. # Video metadata
  48. expect(info["genre"].as_s).to eq("Entertainment")
  49. expect(info["genreUcid"].as_s?).to be_nil
  50. expect(info["license"].as_s).to be_empty
  51. # Author infos
  52. expect(info["author"].as_s).to eq("MrBeast")
  53. expect(info["ucid"].as_s).to eq("UCX6OQ3DkcsbYNE6H8uQQuVA")
  54. expect(info["authorThumbnail"].as_s).to eq(
  55. "https://yt3.ggpht.com/fxGKYucJAVme-Yz4fsdCroCFCrANWqw0ql4GYuvx8Uq4l_euNJHgE-w9MTkLQA805vWCi-kE0g=s48-c-k-c0x00ffffff-no-rj"
  56. )
  57. expect(info["authorVerified"].as_bool).to be_true
  58. expect(info["subCountText"].as_s).to eq("320M")
  59. end
  60. it "parses a regular video with no descrition/comments" do
  61. # Enable mock
  62. _player = load_mock("video/regular_no-description.player")
  63. _next = load_mock("video/regular_no-description.next")
  64. raw_data = _player.merge!(_next)
  65. info = parse_video_info("iuevw6218F0", raw_data)
  66. # Some basic verifications
  67. expect(typeof(info)).to eq(Hash(String, JSON::Any))
  68. expect(info["videoType"].as_s).to eq("Video")
  69. # Basic video infos
  70. expect(info["title"].as_s).to eq("Chris Rea - Auberge")
  71. expect(info["views"].as_i).to eq(14_324_584)
  72. expect(info["likes"].as_i).to eq(35_870)
  73. expect(info["lengthSeconds"].as_i).to eq(283_i64)
  74. expect(info["published"].as_s).to eq("2012-05-21T00:00:00Z")
  75. # Extra video infos
  76. expect(info["allowedRegions"].as_a).to_not be_empty
  77. expect(info["allowedRegions"].as_a.size).to eq(249)
  78. expect(info["allowedRegions"].as_a).to contain(
  79. "AD", "BA", "BB", "BW", "BY", "EG", "GG", "HN", "NP", "NR", "TR",
  80. "TT", "TV", "TW", "TZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU",
  81. "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"
  82. )
  83. expect(info["keywords"].as_a).to_not be_empty
  84. expect(info["keywords"].as_a.size).to eq(4)
  85. expect(info["keywords"].as_a).to contain_exactly(
  86. "Chris",
  87. "Rea",
  88. "Auberge",
  89. "1991"
  90. ).in_any_order
  91. expect(info["allowRatings"].as_bool).to be_true
  92. expect(info["isFamilyFriendly"].as_bool).to be_true
  93. expect(info["isListed"].as_bool).to be_true
  94. expect(info["isUpcoming"].as_bool).to be_false
  95. # Related videos
  96. expect(info["relatedVideos"].as_a.size).to eq(20)
  97. expect(info["relatedVideos"][0]["id"]).to eq("gUUdQfnshJ4")
  98. expect(info["relatedVideos"][0]["title"]).to eq("Chris Rea - The Road To Hell 1989 Full Version")
  99. expect(info["relatedVideos"][0]["author"]).to eq("NEA ZIXNH")
  100. expect(info["relatedVideos"][0]["ucid"]).to eq("UCYMEOGcvav3gCgImK2J07CQ")
  101. expect(info["relatedVideos"][0]["view_count"]).to eq("53298661")
  102. expect(info["relatedVideos"][0]["short_view_count"]).to eq("53M")
  103. expect(info["relatedVideos"][0]["author_verified"]).to eq("false")
  104. # Description
  105. expect(info["description"].as_s).to eq(" ")
  106. expect(info["shortDescription"].as_s).to be_empty
  107. expect(info["descriptionHtml"].as_s).to eq("")
  108. # Video metadata
  109. expect(info["genre"].as_s).to eq("Music")
  110. expect(info["genreUcid"].as_s?).to be_nil
  111. expect(info["license"].as_s).to be_empty
  112. # Author infos
  113. expect(info["author"].as_s).to eq("ChrisReaVideos")
  114. expect(info["ucid"].as_s).to eq("UC_5q6nWPbD30-y6oiWF_oNA")
  115. expect(info["authorThumbnail"].as_s).to eq(
  116. "https://yt3.ggpht.com/ytc/AIdro_n71nsegpKfjeRKwn1JJmK5IVMh_7j5m_h3_1KnUUg=s48-c-k-c0x00ffffff-no-rj"
  117. )
  118. expect(info["authorVerified"].as_bool).to be_false
  119. expect(info["subCountText"].as_s).to eq("3.11K")
  120. end
  121. end