diff --git a/app/logical/source/extractor/newgrounds.rb b/app/logical/source/extractor/newgrounds.rb index 1eb4764e3..33da87755 100644 --- a/app/logical/source/extractor/newgrounds.rb +++ b/app/logical/source/extractor/newgrounds.rb @@ -14,7 +14,9 @@ module Source elsif parsed_url.image_url? [url] elsif video_data.present? - [video_data.dig("sources", "1080p", 0, "src")&.sub(".1080p.", ".")].compact + sample = video_data&.[]("sources")&.max_by { |k, _v| k.gsub(/p$/, "").to_i }&.dig(1, 0, "src") + final = [Source::URL.parse(sample).full_image_url, sample].find { |u| http_exists?(u) } + [final].compact else urls = [] diff --git a/test/unit/sources/newgrounds_test.rb b/test/unit/sources/newgrounds_test.rb index b8b5c0a38..cae4d5df1 100644 --- a/test/unit/sources/newgrounds_test.rb +++ b/test/unit/sources/newgrounds_test.rb @@ -37,7 +37,7 @@ module Sources context "A newgrounds video post" do strategy_should_work( "https://www.newgrounds.com/portal/view/536659", - image_urls: [%r{https://uploads\.ungrounded\.net/alternate/167000/167280_alternate_602\.mp4}], + image_urls: ["https://uploads.ungrounded.net/alternate/167000/167280_alternate_602.mp4"], profile_url: "https://jenjamik.newgrounds.com", artist_name: "jenjamik", page_url: "https://www.newgrounds.com/portal/view/536659", @@ -46,6 +46,20 @@ module Sources ) end + context "A newgrounds video post with no 1080p version" do + strategy_should_work( + "https://www.newgrounds.com/portal/view/758590", + image_urls: ["https://uploads.ungrounded.net/alternate/1483000/1483159_alternate_102560.mp4"] + ) + end + + context "A newgrounds video post where all images have the resolution in their url" do + strategy_should_work( + "https://www.newgrounds.com/portal/view/734778", + image_urls: ["https://uploads.ungrounded.net/alternate/1352000/1352451_alternate_80350.1080p.mp4?1563167480"] + ) + end + context "A newgrounds direct video url" do strategy_should_work( "https://uploads.ungrounded.net/alternate/1801000/1801343_alternate_165104.360p.mp4?1639666238",