-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 989b32d
Showing
4 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Docker Image CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: BuildX Install | ||
uses: docker/setup-buildx-action@v3 | ||
id: buildx | ||
with: | ||
install: true | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ghcr.io/${{ github.repository }} | ||
tags: | | ||
type=raw,value=latest,enable={{is_default_branch}} | ||
type=sha,format=long,prefix= | ||
- name: Build and push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM --platform=$BUILDPLATFORM golang:1.22 as builder | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
|
||
WORKDIR "/app" | ||
COPY index.html index.html | ||
COPY server.go server.go | ||
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ | ||
go build -o server server.go | ||
|
||
FROM jauderho/yt-dlp:latest | ||
WORKDIR "/app" | ||
COPY --from=builder /app/server . | ||
|
||
ENTRYPOINT [] | ||
CMD "/app/server" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<html> | ||
<head> | ||
<style> | ||
body { | ||
text-align: center; | ||
} | ||
form { | ||
margin-top: 10%; | ||
margin-left: 15%; | ||
margin-right:15%; | ||
width: 70%; | ||
} | ||
input { | ||
font-size: xx-large; | ||
} | ||
input[type=text] { | ||
width: 50%; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<form action="" method="post"> | ||
<input type="text" name="link" /> | ||
<input type="submit" value="Download" /> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package main | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
//go:embed index.html | ||
var index []byte | ||
|
||
func main() { | ||
cliCmd := append( | ||
strings.Split(os.Getenv("EXEC"), " "), | ||
"-x", | ||
"--audio-format", | ||
"mp3", | ||
"--audio-quality", | ||
"0") | ||
|
||
bind := os.Getenv("BIND") | ||
|
||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method == http.MethodGet { | ||
w.Write(index) | ||
return | ||
} | ||
|
||
cli := append(cliCmd, r.FormValue("link")) | ||
cmd := exec.Command(cli[0], cli[1:]...) | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
_ = cmd.Run() | ||
|
||
var file string | ||
_ = filepath.Walk(".", func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if info.IsDir() { | ||
return nil | ||
} | ||
if matched, err := filepath.Match("*.mp3", filepath.Base(path)); err != nil { | ||
return err | ||
} else if matched { | ||
file = path | ||
} | ||
return nil | ||
}) | ||
|
||
f, _ := os.Open(file) | ||
defer func() { | ||
f.Close() | ||
os.Remove(file) | ||
}() | ||
|
||
w.Header().Set("Content-Type", "audio/mpeg") | ||
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment;filename="%s"`, filepath.Base(file))) | ||
w.WriteHeader(http.StatusOK) | ||
io.Copy(w, f) | ||
}) | ||
|
||
http.ListenAndServe(bind, nil) | ||
} |