show best format if none are available otherwise
Marco Andronaco andronacomarco@gmail.com
Wed, 16 Oct 2024 13:43:09 +0200
5 files changed,
19 insertions(+),
21 deletions(-)
M
README.md
→
README.md
@@ -7,17 +7,13 @@
https://github.com/birabittoh/FixYouTube-legacy/assets/26506860/e1ad5397-41c8-4073-9b3e-598c66241255 ### Advanced usage -Some services require video previews to be smaller than a certain file size. This app gets the best-looking format by default, so it's not uncommon to have previews that are too big, thus being ignored by crawlers. +Some services require video previews to be smaller than a certain file size. By default, this app selects the best-looking format that fits these criteria. Enter the `/{videoID}/{formatID}` endpoint. -You can change `formatID` to cycle through the available formats for a given video. These formats are also filtered based on file size, in a way that makes them viable Telegram previews. - -In short, if `/{videoID}` does not generate a preview, you can try `/{videoID}/1`, which should be the best-looking format within Telegram's filesize bounds. - -The next values of `formatID` (2 to infinity) are even smaller formats within those bounds. +The default value of `formatID` is `1`, but you can increase it to cycle through the available formats for a given video or set it to `0` to select the best-looking format and ignore file size bounds altogether. -If the video is too long, there might not be small enough formats. In that case, the app returns error 500. +If the video is too long, there might not be small enough formats. In that case, the app effectively behaves like `formatID` is set to `0`. ## Instructions@@ -30,8 +26,8 @@ ### Docker with reverse proxy
Copy the template config file and make your adjustments. My configuration is based on [DuckDNS](http://duckdns.org/) but you can use whatever provider you find [here](https://docs.linuxserver.io/general/swag#docker-compose). ``` -cp docker/swag.env.example docker/swag.env -nano docker/swag.env +cp swag/swag.env.example swag/swag.env +nano swag/swag.env ``` Finally: `docker compose up -d`.
M
docker-compose.yaml
→
docker-compose.yaml
@@ -12,10 +12,10 @@ container_name: swag
cap_add: - NET_ADMIN env_file: - - docker/swag.env + - swag/swag.env volumes: #- /etc/config/swag:/config - - ./docker/gopipe.subdomain.conf:/config/nginx/proxy-confs/gopipe.subdomain.conf:ro + - ./swag/gopipe.subdomain.conf:/config/nginx/proxy-confs/gopipe.subdomain.conf:ro ports: - 443:443 - 80:80
M
src/app/utils.go
→
src/app/utils.go
@@ -21,7 +21,7 @@
func getFormatID(s string) int { formatID, err := strconv.ParseUint(s, 10, 64) if err != nil { - formatID = 0 + formatID = 1 } return int(formatID) }
M
src/app/video.go
→
src/app/video.go
@@ -35,18 +35,20 @@ return time.Until(time.Unix(expireTimestamp, 0))
} func getFormat(video youtube.Video, formatID int) *youtube.Format { - selectFn := formatsSelectFn - if formatID == 0 { - selectFn = formatsSelectFnBest - formatID = 1 + if formatID != 0 { + f := video.Formats.Select(formatsSelectFn) + l := len(f) + if l > 0 { + return &f[(formatID-1)%l] + } } - f := video.Formats.Select(selectFn) - l := len(f) - if l == 0 { - return nil + f := video.Formats.Select(formatsSelectFnBest) + if len(f) > 0 { + return &f[0] } - return &f[(formatID-1)%l] + + return nil } func formatsSelectFn(f youtube.Format) bool {