Implement logging, console window
This commit is contained in:
@ -15,13 +15,16 @@ func downloadAndConvertSubtitles(subtitlesURLs string) ([]string, error) {
|
||||
urls := strings.Split(subtitlesURLs, ",")
|
||||
|
||||
for _, url := range urls {
|
||||
logger.LogInfo("Subtitle Download", fmt.Sprintf("Downloading subtitle from %s", url))
|
||||
vttPath, err := downloadSubtitle(url)
|
||||
if err != nil {
|
||||
logger.LogError("Subtitle Download", fmt.Sprintf("Error downloading subtitle: %v", err))
|
||||
return nil, fmt.Errorf("error downloading subtitle: %v", err)
|
||||
}
|
||||
|
||||
srtPath, err := convertVTTtoSRT(vttPath)
|
||||
if err != nil {
|
||||
logger.LogError("Subtitle Download", fmt.Sprintf("Error converting subtitle: %v", err))
|
||||
return nil, fmt.Errorf("error converting subtitle: %v", err)
|
||||
}
|
||||
|
||||
@ -32,23 +35,28 @@ func downloadAndConvertSubtitles(subtitlesURLs string) ([]string, error) {
|
||||
}
|
||||
|
||||
func downloadSubtitle(url string) (string, error) {
|
||||
logger.LogInfo("Download Subtitle", fmt.Sprintf("Starting download from %s", url))
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
logger.LogError("Download Subtitle", fmt.Sprintf("Error getting subtitle URL: %v", err))
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
tempFile, err := os.CreateTemp("", "subtitle_*.vtt")
|
||||
if err != nil {
|
||||
logger.LogError("Download Subtitle", fmt.Sprintf("Error creating temp file: %v", err))
|
||||
return "", err
|
||||
}
|
||||
defer tempFile.Close()
|
||||
|
||||
_, err = io.Copy(tempFile, resp.Body)
|
||||
if err != nil {
|
||||
logger.LogError("Download Subtitle", fmt.Sprintf("Error copying to temp file: %v", err))
|
||||
return "", err
|
||||
}
|
||||
|
||||
logger.LogInfo("Download Subtitle", "Subtitle downloaded successfully")
|
||||
return tempFile.Name(), nil
|
||||
}
|
||||
|
||||
@ -56,5 +64,6 @@ func convertVTTtoSRT(vttPath string) (string, error) {
|
||||
srtPath := strings.TrimSuffix(vttPath, ".vtt") + ".srt"
|
||||
s1, _ := astisub.OpenFile(vttPath)
|
||||
s1.Write(srtPath)
|
||||
logger.LogInfo("Convert VTT to SRT", fmt.Sprintf("Converted %s to %s", vttPath, srtPath))
|
||||
return srtPath, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user