Skip to content

Commit

Permalink
chore(DownloadCaptions): set a legit user agent & relax job
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed Feb 24, 2025
1 parent dc253a0 commit 44a1dea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 4 additions & 2 deletions apps/cf/lib/videos/captions_fetcher_youtube.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ defmodule CF.Videos.CaptionsFetcherYoutube do
require Logger
import SweetXml

@user_agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/135.0"

@impl true
def fetch(%{youtube_id: youtube_id, language: language}) do
with {:ok, data} <- fetch_youtube_data(youtube_id),
Expand All @@ -27,7 +29,7 @@ defmodule CF.Videos.CaptionsFetcherYoutube do
defp fetch_youtube_data(video_id) do
url = "https://www.youtube.com/watch?v=#{video_id}"

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

Expand Down Expand Up @@ -59,7 +61,7 @@ defmodule CF.Videos.CaptionsFetcherYoutube do
end

defp fetch_transcript(base_url) do
case HTTPoison.get(base_url, []) do
case HTTPoison.get(base_url, [{"User-Agent", @user_agent}]) do
{:ok, %HTTPoison.Response{body: body}} ->
{:ok, body}

Expand Down
14 changes: 7 additions & 7 deletions apps/cf_jobs/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ config :cf_jobs, CF.Jobs.Scheduler,
schedule: {:extended, "*/5"},
task: {CF.Jobs.CreateNotifications, :update, []},
overlap: false
]
],
# Captions
# download_captions: [
# # every minute
# schedule: "*/1 * * * *",
# task: {CF.Jobs.DownloadCaptions, :update, []},
# overlap: false
# ]
download_captions: [
# every 8h
schedule: "0 */8 * * *",
task: {CF.Jobs.DownloadCaptions, :update, []},
overlap: false
]
]

# Configure Postgres pool size
Expand Down
1 change: 1 addition & 0 deletions apps/cf_jobs/lib/jobs/download_captions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ defmodule CF.Jobs.DownloadCaptions do
|> Enum.map(fn video ->
Logger.info("Downloading captions for video #{video.id}")
CF.Videos.download_captions(video)
Process.sleep(1000)
end)

{:reply, :ok, :ok}
Expand Down

0 comments on commit 44a1dea

Please sign in to comment.