Skip to content

Commit 1be778e

Browse files
committed
Hot fix ytdlp needing js to solve captch's
1 parent 4c74234 commit 1be778e

File tree

7 files changed

+281
-116
lines changed

7 files changed

+281
-116
lines changed

MyMusicBoxApi/main.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package main
22

33
import (
4-
"context"
54
"fmt"
6-
"log"
75
"musicboxapi/configuration"
86
"musicboxapi/database"
97
"musicboxapi/http"
@@ -13,45 +11,13 @@ import (
1311

1412
"github.com/gin-contrib/cors"
1513
"github.com/gin-gonic/gin"
16-
"github.com/lrstanley/go-ytdlp"
1714
)
1815

1916
// @title MusicBoxApi API
2017
// @version 1.0
2118
// @BasePath /api/v1
2219
func main() {
2320

24-
procAttr := os.ProcAttr{
25-
// Dir: "/usr/bin",
26-
}
27-
28-
procAttr.Files = []*os.File{os.Stdin, os.Stdout, os.Stderr}
29-
30-
proc, _err := os.StartProcess(
31-
"/usr/bin/yt-dlp-mmb",
32-
[]string{
33-
"yt-dlp-mmb",
34-
"--extractor-args=youtube:player_js_variant=tv",
35-
"--cookies=/home/admin/projects/workspace/MyMusicBoxApi/selenium/cookies_netscape",
36-
"--js-runtimes=deno:/home/admin/.deno/bin",
37-
"--remote-components=ejs:npm",
38-
"https://www.youtube.com/watch?v=Y0ivz1umQ6g",
39-
},
40-
&os.ProcAttr{
41-
Files: []*os.File{
42-
os.Stdin,
43-
os.Stdout,
44-
os.Stderr,
45-
},
46-
},
47-
)
48-
if _err != nil {
49-
log.Fatal(_err)
50-
}
51-
52-
proc.Wait()
53-
54-
return
5521
configuration.LoadConfiguration()
5622

5723
err := database.CreateDatabasConnectionPool()
@@ -66,16 +32,6 @@ func main() {
6632

6733
database.ApplyMigrations()
6834

69-
ytdlp.RemoveInstallCache()
70-
71-
// If yt-dlp isn't installed yet, download and cache it for further use.
72-
options := ytdlp.InstallOptions{
73-
DisableChecksum: true,
74-
AllowVersionMismatch: true,
75-
DownloadURL: "https://github.com/yt-dlp/yt-dlp/releases/download/2026.01.29/yt-dlp_linux",
76-
}
77-
78-
ytdlp.MustInstall(context.TODO(), &options)
7935
setGinMode()
8036

8137
ginEngine := gin.Default()

MyMusicBoxApi/release

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SCRIPTS_FOLDER="$DATABASE_FOLDER/initscripts"
99
IMAGES_FOLDER="$RELEASE_FOLDER/music/images"
1010
COOKIES_FOLDER="$RELEASE_FOLDER/selenium"
1111
MIGRATION_FOLDER="$RELEASE_FOLDER/migration_scripts"
12+
HOTFIX_FOLDER="$RELEASE_FOLDER/hotfix_logs"
1213

1314
echo "=== Setting up release folder ==="
1415
FOLDERS=(
@@ -18,6 +19,7 @@ FOLDERS=(
1819
"$IMAGES_FOLDER"
1920
"$COOKIES_FOLDER"
2021
"$MIGRATION_FOLDER"
22+
"$HOTFIX_FOLDER"
2123
)
2224

2325
for folder in "${FOLDERS[@]}"; do
@@ -37,6 +39,7 @@ cp selenium/* "$COOKIES_FOLDER"
3739
cp migration_scripts/* "$MIGRATION_FOLDER"
3840

3941
echo "=== Building executable ==="
42+
go mod tidy
4043
go build -trimpath -buildvcs=false -ldflags="-s -w" -o "$RELEASE_FOLDER"
4144

4245
echo "=== Reducing executable size ==="

MyMusicBoxApi/run

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/bin/bash
22
echo "=== Setting up folders ==="
33
IMAGES_FOLDER="music_dev/images"
4+
HOTFIX_FOLDER="music_dev/hotfix_logs"
45

56
FOLDERS=(
67
"$IMAGES_FOLDER"
8+
"$HOTFIX_FOLDER"
79
)
810

911
for folder in "${FOLDERS[@]}"; do

MyMusicBoxApi/service/playlist.go

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"strconv"
1212
"strings"
1313
"time"
14-
15-
"github.com/lrstanley/go-ytdlp"
1614
)
1715

1816
func downloadPlaylist(
@@ -26,6 +24,9 @@ func downloadPlaylist(
2624
playlistIdFileName string,
2725
imagesFolder string,
2826
fileExtension string,
27+
logfilesOutputPath string,
28+
logfilesOutputPathError string,
29+
storageFolderName string,
2930
) {
3031
/*
3132
Ignore
@@ -95,21 +96,21 @@ func downloadPlaylist(
9596
_ = os.Rename(oldpath, newpath)
9697
}
9798

98-
defaultSettings := ytdlp.New().
99-
ExtractAudio().
100-
AudioQuality("0").
101-
AudioFormat(fileExtension).
102-
DownloadArchive(archiveFileName).
103-
WriteThumbnail().
104-
ConcurrentFragments(10).
105-
ConvertThumbnails("jpg").
106-
ForceIPv4().
107-
//sudo apt install aria2
108-
Downloader("aria2c").
109-
DownloaderArgs("aria2c:-x 16 -s 16 -j 16").
110-
NoKeepVideo().
111-
Output(storage + "/%(id)s.%(ext)s").
112-
Cookies("selenium/cookies_netscape")
99+
// defaultSettings := ytdlp.New().
100+
// ExtractAudio().
101+
// AudioQuality("0").
102+
// AudioFormat(fileExtension).
103+
// DownloadArchive(archiveFileName).
104+
// WriteThumbnail().
105+
// ConcurrentFragments(10).
106+
// ConvertThumbnails("jpg").
107+
// ForceIPv4().
108+
// //sudo apt install aria2
109+
// Downloader("aria2c").
110+
// DownloaderArgs("aria2c:-x 16 -s 16 -j 16").
111+
// NoKeepVideo().
112+
// Output(storage + "/%(id)s.%(ext)s").
113+
// Cookies("selenium/cookies_netscape")
113114

114115
for id := range downloadCount {
115116
name := names[id]
@@ -121,14 +122,22 @@ func downloadPlaylist(
121122

122123
tasklogTable.UpdateChildTaskLogStatus(childTask)
123124

124-
ytdlpInstance := defaultSettings.Clone()
125-
126-
result, err := ytdlpInstance.Run(context.Background(), fmt.Sprintf("https://www.youtube.com/watch?v=%s", ids[id]))
127-
128-
// outputLogs[ids[id]] = result.Stdout
129-
130-
if err != nil {
131-
json, _ := json.Marshal(result.Stdout)
125+
downloaded := FlatSingleDownload(
126+
archiveFileName,
127+
idsFileName,
128+
namesFileName,
129+
durationFileName,
130+
playlistTitleFileName,
131+
playlistIdFileName,
132+
fmt.Sprintf("https://www.youtube.com/watch?v=%s", ids[id]),
133+
logfilesOutputPath,
134+
logfilesOutputPathError,
135+
storageFolderName,
136+
fileExtension)
137+
138+
if !downloaded {
139+
file, err := os.ReadFile(logfilesOutputPathError)
140+
json, _ := json.Marshal(file)
132141
childTask.OutputLog = json
133142
tasklogTable.ChildTaskLogError(childTask)
134143
logging.Error(fmt.Sprintf("Failed to download %s, error:%s", ids[id], err.Error()))
@@ -156,7 +165,13 @@ func downloadPlaylist(
156165

157166
_ = os.Rename(oldpath, newpath)
158167

159-
json, _ := json.Marshal(result.OutputLogs)
168+
file, err := os.ReadFile(logfilesOutputPath)
169+
170+
if err != nil {
171+
panic(-1564654654)
172+
}
173+
174+
json, _ := json.Marshal(file)
160175

161176
childTask.OutputLog = json
162177

0 commit comments

Comments
 (0)