From 9a61a4e9414fed4964a15a092236fbbf37fa1971 Mon Sep 17 00:00:00 2001 From: rroller Date: Sat, 19 Oct 2024 16:19:55 -0700 Subject: [PATCH] Use a specific version of yt-dlp and verify the sha246 --- Dockerfile | 14 +++++++++----- src/main.go | 5 +++-- src/media/fetch.go | 12 ++++++------ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8062245..d36a8d3 100755 --- a/Dockerfile +++ b/Dockerfile @@ -19,20 +19,24 @@ FROM python:3.13.0-alpine3.20 ENV MR_DOWNLOAD_DIR="/download" RUN apk add --update --no-cache \ - curl + curl -COPY --from=builder /app/media-roller /app/media-roller +# https://hub.docker.com/r/mwader/static-ffmpeg/tags +# https://github.com/wader/static-ffmpeg COPY --from=mwader/static-ffmpeg:7.1 /ffmpeg /usr/local/bin/ +COPY --from=builder /app/media-roller /app/media-roller COPY templates /app/templates COPY static /app/static WORKDIR /app -RUN curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp && \ - chmod a+rx /usr/local/bin/yt-dlp +# Get new releases here https://github.com/yt-dlp/yt-dlp/releases +RUN curl -L https://github.com/yt-dlp/yt-dlp/releases/download/2024.10.07/yt-dlp -o /usr/local/bin/yt-dlp && \ + echo "8d8151368376c4d2f6dd6993d893be09334c06b7e6fa1e7e07bc3c4fbef848b3 /usr/local/bin/yt-dlp" | sha256sum -c - && \ + chmod a+rx /usr/local/bin/yt-dlp # Sanity check RUN yt-dlp --version && \ ffmpeg -version -CMD /app/media-roller +CMD /app/media-roller \ No newline at end of file diff --git a/src/main.go b/src/main.go index 1e1708c..05ce7d6 100644 --- a/src/main.go +++ b/src/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "errors" "github.com/go-chi/chi/v5" "github.com/rs/zerolog/log" "media-roller/src/media" @@ -53,7 +54,7 @@ func main() { go func() { <-shutdownCtx.Done() - if shutdownCtx.Err() == context.DeadlineExceeded { + if errors.Is(shutdownCtx.Err(), context.DeadlineExceeded) { log.Fatal().Msg("graceful shutdown timed out.. forcing exit.") } }() @@ -68,7 +69,7 @@ func main() { // Run the server err := server.ListenAndServe() - if err != nil && err != http.ErrServerClosed { + if err != nil && !errors.Is(err, http.ErrServerClosed) { log.Fatal().Err(err) } diff --git a/src/media/fetch.go b/src/media/fetch.go index 77277b2..9a6b101 100644 --- a/src/media/fetch.go +++ b/src/media/fetch.go @@ -32,7 +32,7 @@ type Media struct { HumanSize string } -type MediaResults struct { +type Results struct { Medias []Media } @@ -79,10 +79,10 @@ func FetchMediaApi(w http.ResponseWriter, r *http.Request) { streamFileToClientById(w, r, response.Medias[0].Id) } -func getMediaResults(r *http.Request) (MediaResults, error) { +func getMediaResults(r *http.Request) (Results, error) { url := r.URL.Query().Get("url") if url == "" { - return MediaResults{}, errors.New("Missing URL") + return Results{}, errors.New("Missing URL") } // NOTE: This system is for a simple use case, meant to run at home. This is not a great design for a robust system. @@ -96,15 +96,15 @@ func getMediaResults(r *http.Request) (MediaResults, error) { // We don't, so go fetch it id, err = downloadMedia(url) if err != nil { - return MediaResults{}, err + return Results{}, err } medias, err = getAllFilesForId(id) if err != nil { - return MediaResults{}, err + return Results{}, err } } - return MediaResults{ + return Results{ Medias: medias, }, nil }