mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
Things have not improved since this scraper was written
This commit is contained in:
parent
7a3b7e6d62
commit
886539c514
1 changed files with 16 additions and 8 deletions
|
@ -9,19 +9,27 @@ defmodule Philomena.Scrapers.Twitter do
|
||||||
def scrape(_uri, url) do
|
def scrape(_uri, url) do
|
||||||
[user, status_id] = Regex.run(@url_regex, url, capture: :all_but_first)
|
[user, status_id] = Regex.run(@url_regex, url, capture: :all_but_first)
|
||||||
|
|
||||||
image_url = "https://d.fxtwitter.com/#{user}/status/#{status_id}.jpg"
|
api_url = "https://api.fxtwitter.com/#{user}/status/#{status_id}"
|
||||||
|
{:ok, %Tesla.Env{status: 200, body: body}} = Philomena.Http.get(api_url)
|
||||||
|
|
||||||
{:ok, %Tesla.Env{status: 200}} = Philomena.Http.head(image_url)
|
json = Jason.decode!(body)
|
||||||
|
|
||||||
|
images =
|
||||||
|
Enum.map(json["tweet"]["media"]["photos"], fn p ->
|
||||||
|
%{
|
||||||
|
url: large_format(p["url"]),
|
||||||
|
camo_url: Camo.Image.image_url(p["url"])
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
%{
|
%{
|
||||||
source_url: "https://twitter.com/#{user}/status/#{status_id}",
|
source_url: "https://twitter.com/#{user}/status/#{status_id}",
|
||||||
author_name: user,
|
author_name: user,
|
||||||
images: [
|
images: images
|
||||||
%{
|
|
||||||
url: image_url,
|
|
||||||
camo_url: Camo.Image.image_url(image_url)
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp large_format(str) do
|
||||||
|
String.replace_suffix(str, ".jpg", "?format=jpg&name=large")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue