From 228850b7494897396ccd059850a4708bcb3f49fc Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 23 Aug 2022 13:39:32 -0500 Subject: [PATCH] newgrounds: support parsing video urls. Fixes URLS like `https://www.newgrounds.com/portal/view/830293` being treated as bad_source. --- app/logical/source/url/newgrounds.rb | 9 ++++++++- test/unit/sources/newgrounds_test.rb | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/logical/source/url/newgrounds.rb b/app/logical/source/url/newgrounds.rb index e74669683..3ff4e04b3 100644 --- a/app/logical/source/url/newgrounds.rb +++ b/app/logical/source/url/newgrounds.rb @@ -16,7 +16,7 @@ # * https://uploads.ungrounded.net/225000/225625_colormedressup.swf?1111143751 (file) # class Source::URL::Newgrounds < Source::URL - attr_reader :username, :work_id, :work_title + attr_reader :username, :work_id, :work_title, :video_id def self.match?(url) url.domain.in?(["newgrounds.com", "ngfiles.com", "ungrounded.net"]) @@ -31,6 +31,11 @@ class Source::URL::Newgrounds < Source::URL @username = username @work_title = work_title + # https://www.newgrounds.com/portal/view/536659 + # https://www.newgrounds.com/portal/video/536659 (curl 'https://www.newgrounds.com/portal/video/536659' -H 'X-Requested-With: XMLHttpRequest') + in "www.newgrounds.com", "portal", ("view" | "video"), video_id + @video_id = video_id + # https://art.ngfiles.com/images/1254000/1254722_natthelich_pandora.jpg # https://art.ngfiles.com/images/1033000/1033622_natthelich_fire-emblem-marth-plus-progress-pic.png?f1569487181 in "art.ngfiles.com", "images", _, /^(\d+)_([^_]+)_(.*)\.\w+$/ @@ -63,6 +68,8 @@ class Source::URL::Newgrounds < Source::URL def page_url if username.present? && work_title.present? "https://www.newgrounds.com/art/view/#{username}/#{work_title}" + elsif video_id.present? + "https://www.newgrounds.com/portal/view/#{video_id}" end end diff --git a/test/unit/sources/newgrounds_test.rb b/test/unit/sources/newgrounds_test.rb index f9a7a0028..39eff763d 100644 --- a/test/unit/sources/newgrounds_test.rb +++ b/test/unit/sources/newgrounds_test.rb @@ -130,6 +130,7 @@ module Sources assert(Source::URL.image_url?("https://art.ngfiles.com/thumbnails/1254000/1254985.png?f1588263349")) assert(Source::URL.page_url?("https://www.newgrounds.com/art/view/puddbytes/costanza-at-bat")) + assert(Source::URL.page_url?("https://www.newgrounds.com/portal/view/830293")) assert(Source::URL.profile_url?("https://natthelich.newgrounds.com")) refute(Source::URL.profile_url?("https://www.newgrounds.com"))