Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarnathCJD committed Feb 26, 2024
1 parent 80b69c3 commit cbf48d0
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions telegram/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package telegram

import (
"bytes"
"encoding/json"
"fmt"
"math/rand"
"os"
Expand Down Expand Up @@ -541,20 +542,35 @@ func gatherVideoMetadata(path string, attrs []DocumentAttribute) ([]DocumentAttr
// waveform []byte
)

cmd := exec.Command("ffprobe", "-v", "error", "-show_entries", "format_tags=artist,title", "-of", "default=noprint_wrappers=1:nokey=1", path)
// ffprobe -v error -show_entries format_tags=artist,title -of json cv.mp3
cmd := exec.Command("ffprobe", "-v", "error", "-show_entries", "format_tags=artist,title", "-of", "json", path)
out, err := cmd.Output()

cmd_duration := exec.Command("ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", path)
out_duration, err_duration := cmd_duration.Output()

if err == nil {
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
if len(lines) == 2 {
performer = strings.TrimSpace(lines[0])
title = strings.TrimSpace(lines[1])
} else if len(lines) == 1 {
performer = strings.TrimSpace(lines[0])
title = strings.TrimSpace(lines[0])
type ProbeMeta struct {
Format struct {
Tags struct {
Title string `json:"title"`
Artist string `json:"artist"`
} `json:"tags"`
} `json:"format"`
}

var meta ProbeMeta
if err := json.Unmarshal(out, &meta); err == nil {
performer = meta.Format.Tags.Artist
title = meta.Format.Tags.Title
}

if performer == "" {
performer = "Unknown"
}

if title == "" {
title = strings.Replace(filepath.Base(path), filepath.Ext(path), "", 1)
}
}

Expand Down

0 comments on commit cbf48d0

Please sign in to comment.