code cleanup

This commit is contained in:
stefanodvx 2025-04-24 12:20:35 +02:00
parent 917be1687f
commit 5336968e05
34 changed files with 193 additions and 115 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt"
"os"
"github.com/pkg/errors"
ffmpeg "github.com/u2takey/ffmpeg-go"
)
@ -12,7 +13,7 @@ func MergeSegments(
outputPath string,
) (string, error) {
if len(segmentPaths) == 0 {
return "", fmt.Errorf("no segments to merge")
return "", errors.New("no segments to merge")
}
listFilePath := outputPath + ".segments.txt"
listFile, err := os.Create(listFilePath)

View file

@ -6,6 +6,7 @@ import (
"strings"
"github.com/asticode/go-astiav"
"github.com/pkg/errors"
)
func RemuxFile(inputFile string) error {
@ -29,7 +30,7 @@ func RemuxFile(inputFile string) error {
inputCtx := astiav.AllocFormatContext()
if inputCtx == nil {
return fmt.Errorf("failed to alloc input format context")
return errors.New("failed to alloc input format context")
}
defer inputCtx.Free()
@ -59,7 +60,7 @@ func RemuxFile(inputFile string) error {
}
outStream := outCtx.NewStream(nil)
if outStream == nil {
return fmt.Errorf("failed to create new stream in output context")
return errors.New("failed to create new stream in output context")
}
if err := inCP.Copy(outStream.CodecParameters()); err != nil {
return fmt.Errorf("failed to copy codec parameters: %w", err)
@ -69,7 +70,7 @@ func RemuxFile(inputFile string) error {
inToOutIdx[inIdx] = len(inToOutIdx)
}
if len(inToOutIdx) == 0 {
return fmt.Errorf("no supported streams to remux")
return errors.New("no supported streams to remux")
}
if !outCtx.OutputFormat().Flags().Has(astiav.IOFormatFlagNofile) {
@ -89,7 +90,7 @@ func RemuxFile(inputFile string) error {
defer packet.Free()
for {
if err := inputCtx.ReadFrame(packet); err != nil {
if err == astiav.ErrEof {
if errors.Is(err, astiav.ErrEof) {
break
}
return fmt.Errorf("error reading frame: %w", err)

View file

@ -1,13 +1,13 @@
package av
import (
"errors"
"fmt"
"image/jpeg"
"os"
"time"
"github.com/asticode/go-astiav"
"github.com/pkg/errors"
)
func ExtractVideoThumbnail(videoPath string, imagePath string) error {
@ -65,7 +65,7 @@ func ExtractVideoThumbnail(videoPath string, imagePath string) error {
err := formatCtx.ReadFrame(packet)
if err != nil {
if errors.Is(err, astiav.ErrEof) {
return fmt.Errorf("end of file reached before finding video frame")
return errors.New("end of file reached before finding video frame")
}
return fmt.Errorf("failed reading frame: %w", err)
}
@ -113,5 +113,5 @@ func ExtractVideoThumbnail(videoPath string, imagePath string) error {
return nil
}
return fmt.Errorf("timeout while waiting for video frame")
return errors.New("timeout while waiting for video frame")
}

View file

@ -3,14 +3,16 @@ package util
import (
"bytes"
"fmt"
"govd/models"
"io"
"net/http"
"net/url"
"strconv"
"time"
"govd/models"
"github.com/bytedance/sonic"
"github.com/pkg/errors"
)
type EdgeProxyClient struct {
@ -48,7 +50,7 @@ func NewEdgeProxy(
func (c *EdgeProxyClient) Do(req *http.Request) (*http.Response, error) {
if c.proxyURL == "" {
return nil, fmt.Errorf("proxy URL is not set")
return nil, errors.New("proxy URL is not set")
}
targetURL := req.URL.String()

View file

@ -1,8 +1,6 @@
package util
import (
"govd/config"
"govd/models"
"log"
"net"
"net/http"
@ -10,6 +8,9 @@ import (
"strings"
"sync"
"time"
"govd/config"
"govd/models"
)
var (

View file

@ -9,11 +9,11 @@ import (
"os"
"slices"
_ "image/gif"
_ "image/png"
_ "image/gif" // register GIF decoder
_ "image/png" // register PNG decoder
_ "github.com/strukturag/libheif/go/heif"
_ "golang.org/x/image/webp"
_ "github.com/strukturag/libheif/go/heif" // register HEIF decoder
_ "golang.org/x/image/webp" // register WebP decoder
)
var (

View file

@ -85,7 +85,7 @@ func EscapeCaption(str string) string {
}
func GetLastError(err error) error {
var lastErr error = err
var lastErr = err
for {
unwrapped := errors.Unwrap(lastErr)
if unwrapped == nil {

View file

@ -9,12 +9,11 @@ import (
"strings"
"time"
"github.com/pkg/errors"
"govd/enums"
"govd/models"
"github.com/grafov/m3u8"
"github.com/pkg/errors"
)
var httpClient = &http.Client{
@ -89,8 +88,8 @@ func parseMasterPlaylist(
VideoCodec: videoCodec,
AudioCodec: audioCodec,
Bitrate: int64(variant.Bandwidth),
Width: int64(width),
Height: int64(height),
Width: width,
Height: height,
URL: []string{variantURL},
}
variantContent, err := fetchContent(variantURL)
@ -153,7 +152,7 @@ func parseAlternative(
altURL := resolveURL(baseURL, alternative.URI)
audioCodec := getAudioAlternativeCodec(variants, alternative)
format := &models.MediaFormat{
FormatID: fmt.Sprintf("hls-%s", alternative.GroupId),
FormatID: "hls" + alternative.GroupId,
Type: enums.MediaTypeAudio,
AudioCodec: audioCodec,
URL: []string{altURL},