ytdlp package
This commit is contained in:
@@ -12,6 +12,7 @@ ADD handlers /src/handlers
|
||||
ADD media /src/media
|
||||
ADD originals /src/originals
|
||||
Add playlists /src/playlists
|
||||
Add ytdlp /src/ytdlp
|
||||
ADD go.mod /src/.
|
||||
|
||||
RUN cd /src && go mod tidy
|
||||
|
16
handlers.go
16
handlers.go
@@ -11,13 +11,15 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"ytdlp-site/media"
|
||||
"ytdlp-site/originals"
|
||||
"ytdlp-site/playlists"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"ytdlp-site/media"
|
||||
"ytdlp-site/originals"
|
||||
"ytdlp-site/playlists"
|
||||
"ytdlp-site/ytdlp"
|
||||
)
|
||||
|
||||
type Footer struct {
|
||||
@@ -175,7 +177,7 @@ type Meta struct {
|
||||
|
||||
func getYtdlpTitle(url string, args []string) (string, error) {
|
||||
args = append(args, "--simulate", "--print", "%(title)s", url)
|
||||
stdout, _, err := runYtdlp(args...)
|
||||
stdout, _, err := ytdlp.Run(args...)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return "", err
|
||||
@@ -195,7 +197,7 @@ type PlaylistData struct {
|
||||
|
||||
func getYtdlpPlaylist(url string) (PlaylistData, error) {
|
||||
var data PlaylistData
|
||||
stdout, _, err := runYtdlp("--flat-playlist", "--dump-single-json", url)
|
||||
stdout, _, err := ytdlp.Run("--flat-playlist", "--dump-single-json", url)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return data, err
|
||||
@@ -211,7 +213,7 @@ func getYtdlpPlaylist(url string) (PlaylistData, error) {
|
||||
|
||||
func getYtdlpArtist(url string, args []string) (string, error) {
|
||||
args = append(args, "--simulate", "--print", "%(uploader)s", url)
|
||||
stdout, _, err := runYtdlp(args...)
|
||||
stdout, _, err := ytdlp.Run(args...)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return "", err
|
||||
@@ -221,7 +223,7 @@ func getYtdlpArtist(url string, args []string) (string, error) {
|
||||
|
||||
func getYtdlpExt(url string, args []string) (string, error) {
|
||||
args = append(args, "--simulate", "--print", "%(ext)s", url)
|
||||
stdout, _, err := runYtdlp(args...)
|
||||
stdout, _, err := ytdlp.Run(args...)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return "", err
|
||||
|
13
main.go
13
main.go
@@ -8,11 +8,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
"ytdlp-site/database"
|
||||
"ytdlp-site/handlers"
|
||||
"ytdlp-site/media"
|
||||
"ytdlp-site/originals"
|
||||
"ytdlp-site/playlists"
|
||||
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/labstack/echo/v4"
|
||||
@@ -20,6 +15,13 @@ import (
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
|
||||
"ytdlp-site/database"
|
||||
"ytdlp-site/handlers"
|
||||
"ytdlp-site/media"
|
||||
"ytdlp-site/originals"
|
||||
"ytdlp-site/playlists"
|
||||
"ytdlp-site/ytdlp"
|
||||
)
|
||||
|
||||
var db *gorm.DB
|
||||
@@ -51,6 +53,7 @@ func main() {
|
||||
log.Infof("BuildDate: %s", getBuildDate())
|
||||
|
||||
handlers.Init(log)
|
||||
ytdlp.Init(log)
|
||||
|
||||
gormLogger := logger.New(
|
||||
golog.New(os.Stdout, "\r\n", golog.LstdFlags), // io writer
|
||||
|
12
ytdlp/init.go
Normal file
12
ytdlp/init.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package ytdlp
|
||||
|
||||
import "github.com/sirupsen/logrus"
|
||||
|
||||
var log *logrus.Logger
|
||||
|
||||
func Init(logger *logrus.Logger) error {
|
||||
log = logger.WithFields(logrus.Fields{
|
||||
"component": "ytdlp",
|
||||
}).Logger
|
||||
return nil
|
||||
}
|
@@ -1,13 +1,14 @@
|
||||
package main
|
||||
package ytdlp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// runs ffprobe with the provided args and returns (stdout, stderr, error)
|
||||
func runYtdlp(args ...string) ([]byte, []byte, error) {
|
||||
func Run(args ...string) ([]byte, []byte, error) {
|
||||
ytdlp := "yt-dlp"
|
||||
log.Infoln(ytdlp, strings.Join(args, " "))
|
||||
cmd := exec.Command(ytdlp, args...)
|
||||
@@ -24,3 +25,11 @@ func runYtdlp(args ...string) ([]byte, []byte, error) {
|
||||
log.Infoln("stderr:", stderr.String())
|
||||
return stdout.Bytes(), stderr.Bytes(), err
|
||||
}
|
||||
|
||||
func Clip(src, dst string, from, to float64) error {
|
||||
_, _, err := Run("-i", src,
|
||||
"-ss", fmt.Sprintf("%f", from),
|
||||
"-to", fmt.Sprintf("%f", to),
|
||||
dst)
|
||||
return err
|
||||
}
|
Reference in New Issue
Block a user