Add reddit support

This commit is contained in:
nonamethanks
2022-10-31 13:31:11 +01:00
parent 2341d8341d
commit e294e1193e
4 changed files with 149 additions and 2 deletions

View File

@@ -3,7 +3,7 @@
module Source
class URL
class Reddit < Source::URL
attr_reader :subreddit, :work_id, :title, :username
attr_reader :subreddit, :work_id, :title, :username, :file
def self.match?(url)
url.domain.in?(["reddit.com", "redd.it"])
@@ -14,11 +14,14 @@ module Source
# https://i.redd.it/p5utgk06ryq81.png
# https://preview.redd.it/qoyhz3o8yde71.jpg?width=1440&format=pjpg&auto=webp&s=5cbe3b0b097d6e7263761c461dae19a43038db22
in ("i" | "preview"), "redd.it", file
@file = file
# https://external-preview.redd.it/92G2gkb545UNlA-PywJqM_F-4TT0xngvmf_gb9sFDqk.jpg?auto=webp&s=0f1e3d0603dbaabe1ead7352202d0de1653d76f6
# https://g.redditmedia.com/f-OWw5C5aVumPS4HXVFhTspgzgQB4S77mO-6ad0rzpg.gif?fm=mp4&mp4-fragmented=false&s=ed3d767bf3b0360a50ddd7f503d46225
# https://i.redditmedia.com/9cYFBDQ3QsqWnF9v7EhW5uOcQNHz1Ak9_E1zVNeSLek.png?s=6fee1bb56e7d926847dc3ece01a1ffd4
in *rest if image_url?
# pass
# pass
# https://www.reddit.com/user/xSlimes
# https://www.reddit.com/u/Valshier
@@ -73,6 +76,12 @@ module Source
def profile_url
"https://www.reddit.com/user/#{username}" if username.present?
end
def full_image_url
return unless image_url?
return "https://i.redd.it/#{file}" if file.present?
original_url
end
end
end
end