Skip to content

Commit 30b594a

Browse files
authored
chore(DownloadCaptions): set a legit user agent & relax job (#491)
1 parent dc253a0 commit 30b594a

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

apps/cf/lib/videos/captions_fetcher_youtube.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ defmodule CF.Videos.CaptionsFetcherYoutube do
99
require Logger
1010
import SweetXml
1111

12+
@user_agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/135.0"
13+
1214
@impl true
1315
def fetch(%{youtube_id: youtube_id, language: language}) do
1416
with {:ok, data} <- fetch_youtube_data(youtube_id),
@@ -27,7 +29,7 @@ defmodule CF.Videos.CaptionsFetcherYoutube do
2729
defp fetch_youtube_data(video_id) do
2830
url = "https://www.youtube.com/watch?v=#{video_id}"
2931

30-
case HTTPoison.get(url, []) do
32+
case HTTPoison.get(url, [{"User-Agent", @user_agent}]) do
3133
{:ok, %HTTPoison.Response{body: body}} ->
3234
{:ok, body}
3335

@@ -59,7 +61,7 @@ defmodule CF.Videos.CaptionsFetcherYoutube do
5961
end
6062

6163
defp fetch_transcript(base_url) do
62-
case HTTPoison.get(base_url, []) do
64+
case HTTPoison.get(base_url, [{"User-Agent", @user_agent}]) do
6365
{:ok, %HTTPoison.Response{body: body}} ->
6466
{:ok, body}
6567

apps/cf_jobs/config/config.exs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ config :cf_jobs, CF.Jobs.Scheduler,
3838
schedule: {:extended, "*/5"},
3939
task: {CF.Jobs.CreateNotifications, :update, []},
4040
overlap: false
41-
]
41+
],
4242
# Captions
43-
# download_captions: [
44-
# # every minute
45-
# schedule: "*/1 * * * *",
46-
# task: {CF.Jobs.DownloadCaptions, :update, []},
47-
# overlap: false
48-
# ]
43+
download_captions: [
44+
# every 8h
45+
schedule: "0 */8 * * *",
46+
task: {CF.Jobs.DownloadCaptions, :update, []},
47+
overlap: false
48+
]
4949
]
5050

5151
# Configure Postgres pool size

apps/cf_jobs/lib/jobs/download_captions.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ defmodule CF.Jobs.DownloadCaptions do
3636
|> Enum.map(fn video ->
3737
Logger.info("Downloading captions for video #{video.id}")
3838
CF.Videos.download_captions(video)
39+
Process.sleep(1000)
3940
end)
4041

4142
{:reply, :ok, :ok}

0 commit comments

Comments
 (0)