Skip to content

Commit

Permalink
Merge pull request #422 from wader/depecration-cleanup
Browse files Browse the repository at this point in the history
Cleaup some ioutil use and error strings
  • Loading branch information
wader authored Jan 13, 2024
2 parents 7be06ed + bc67f86 commit 552cabc
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions internal/ydls/ydls.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -466,7 +465,7 @@ func (ydls *YDLS) downloadRSS(
if ydlResult.Info.Thumbnail == "" && webpageRawURL != "" {
resp, respErr := options.HTTPClient.Get(webpageRawURL)
if respErr == nil {
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
resp.Body.Close()
linkIconRawURL, _ = linkicon.Find(webpageRawURL, string(body))
}
Expand Down Expand Up @@ -610,14 +609,14 @@ func (ydls *YDLS) downloadFormat(
}
} else {
if s.Required {
return DownloadResult{}, fmt.Errorf("Found no required %s source stream", s.Media)
return DownloadResult{}, fmt.Errorf("found no required %s source stream", s.Media)
}
log.Printf("Found no optional %s source stream, skipping", s.Media)
}
}

if len(streamDownloads) == 0 {
return DownloadResult{}, fmt.Errorf("No useful source streams found")
return DownloadResult{}, fmt.Errorf("no useful source streams found")
}

type downloadProbeResult struct {
Expand Down Expand Up @@ -718,7 +717,7 @@ func (ydls *YDLS) downloadFormat(
}
} else {
if sdm.stream.Required {
return DownloadResult{}, fmt.Errorf("No media found for required %v stream (%s:%s)",
return DownloadResult{}, fmt.Errorf("no media found for required %v stream (%s:%s)",
sdm.stream.Media, probeAudioCodec, probeVideoCodec)
}
log.Printf("No media found for optional %v stream (%s:%s)",
Expand All @@ -745,7 +744,7 @@ func (ydls *YDLS) downloadFormat(
}

if len(ffmpegMaps) == 0 {
return DownloadResult{}, fmt.Errorf("No media found")
return DownloadResult{}, fmt.Errorf("no media found")
}

if !options.RequestOptions.Format.SubtitleCodecs.Empty() && len(ydlResult.Info.Subtitles) > 0 {
Expand Down Expand Up @@ -777,15 +776,15 @@ func (ydls *YDLS) downloadFormat(
}

if subtitlesTempDir == "" {
tempDir, tempDirErr := ioutil.TempDir("", "ydls-subtitle")
tempDir, tempDirErr := os.MkdirTemp("", "ydls-subtitle")
if tempDirErr != nil {
return DownloadResult{}, fmt.Errorf("failed to create subtitles tempdir: %s", tempDirErr)
}
subtitlesTempDir = tempDir
}

subtitleFile := filepath.Join(subtitlesTempDir, fmt.Sprintf("%s.%s", subtitle.Language, subtitle.Ext))
if err := ioutil.WriteFile(subtitleFile, subtitle.Bytes, 0600); err != nil {
if err := os.WriteFile(subtitleFile, subtitle.Bytes, 0600); err != nil {
return DownloadResult{}, fmt.Errorf("failed to write subtitle file: %s", err)
}

Expand Down

0 comments on commit 552cabc

Please sign in to comment.