Skip to content

Commit

Permalink
close #109. adds reason field to bad files list
Browse files Browse the repository at this point in the history
  • Loading branch information
aetaric committed Oct 9, 2024
1 parent 668603e commit 553fdfb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
30 changes: 16 additions & 14 deletions check/checkrr.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (c *Checkrr) checkFile(path string) {
data, err := ffprobe.ProbeURL(ctx, path)
if err != nil {
log.WithFields(log.Fields{"FFProbe": "failed", "Type": detectedFileType}).Warnf("Error getting data: %v - %v", err, path)
c.deleteFile(path)
c.deleteFile(path, "data problem")
data, buf, err = nil, nil, nil
return
} else {
Expand All @@ -275,14 +275,14 @@ func (c *Checkrr) checkFile(path string) {
for _, codec := range c.removeVideo {
if stream.CodecName == codec {
log.WithFields(log.Fields{"Format": data.Format.FormatLongName, "Type": detectedFileType, "FFProbe": true, "Codec": stream.CodecName}).Infof("Detected %s. Removing.", string(data.FirstVideoStream().CodecName))
c.deleteFile(path)
c.deleteFile(path, "video codec")
return
}
}
for _, codec := range c.removeAudio {
if stream.CodecName == codec {
log.WithFields(log.Fields{"Format": data.Format.FormatLongName, "Type": detectedFileType, "FFProbe": true, "Codec": stream.CodecName}).Infof("Detected %s. Removing.", string(data.FirstVideoStream().CodecName))
c.deleteFile(path)
c.deleteFile(path, "audio codec")
return
}
}
Expand All @@ -291,12 +291,12 @@ func (c *Checkrr) checkFile(path string) {
if err == nil {
if streamlang == language {
log.WithFields(log.Fields{"Format": data.Format.FormatLongName, "Type": detectedFileType, "FFProbe": true, "Codec": stream.CodecName, "Language": streamlang}).Infof("Detected %s. Removing.", string(streamlang))
c.deleteFile(path)
c.deleteFile(path, "audio lang")
return
}
} else {
log.WithFields(log.Fields{"Format": data.Format.FormatLongName, "Type": detectedFileType, "FFProbe": true, "Codec": stream.CodecName, "Language": "unknown"}).Warn("Error getting audio stream language")
c.deleteFile(path)
//c.deleteFile(path, audio lang")
}
}
}
Expand All @@ -308,14 +308,14 @@ func (c *Checkrr) checkFile(path string) {
for _, codec := range c.removeAudio {
if stream.CodecName == codec {
log.WithFields(log.Fields{"Format": data.Format.FormatLongName, "Type": detectedFileType, "FFProbe": true, "Codec": stream.CodecName}).Infof("Detected %s. Removing.", string(data.FirstVideoStream().CodecName))
c.deleteFile(path)
c.deleteFile(path, "audio codec")
return
}
}
}
} else {
log.WithFields(log.Fields{"Format": data.Format.FormatLongName, "Type": detectedFileType, "FFProbe": true, "Codec": "unknown"}).Infof("No Audio Stream detected for audio file: %s. Removing.", string(path))
c.deleteFile(path)
c.deleteFile(path, "no audio in video")
return
}
}
Expand Down Expand Up @@ -351,19 +351,19 @@ func (c *Checkrr) checkFile(path string) {
c.notifications.Notify("Unknown file detected", fmt.Sprintf("\"%v\" is not a Video, Audio, Image, Subtitle, or Plaintext file.", path), "unknowndetected", path)
c.Stats.UnknownFileCount++
c.Stats.Write("UnknownFiles", c.Stats.UnknownFileCount)
c.deleteFile(path)
c.deleteFile(path, "not recognized")
return
}
}

func (c *Checkrr) deleteFile(path string) {
func (c *Checkrr) deleteFile(path string, reason string) {
for _, sonarr := range c.sonarr {
if sonarr.Process && sonarr.MatchPath(path) {
sonarr.RemoveFile(path)
c.notifications.Notify("File Reacquire", fmt.Sprintf("\"%v\" was sent to sonarr to be reacquired", path), "reacquire", path)
c.Stats.SonarrSubmissions++
c.Stats.Write("Sonarr", c.Stats.SonarrSubmissions)
c.recordBadFile(path, "sonarr")
c.recordBadFile(path, "sonarr", reason)
return
}
}
Expand All @@ -373,7 +373,7 @@ func (c *Checkrr) deleteFile(path string) {
c.notifications.Notify("File Reacquire", fmt.Sprintf("\"%v\" was sent to radarr to be reacquired", path), "reacquire", path)
c.Stats.RadarrSubmissions++
c.Stats.Write("Radarr", c.Stats.RadarrSubmissions)
c.recordBadFile(path, "radarr")
c.recordBadFile(path, "radarr", reason)
return
}
}
Expand All @@ -383,15 +383,15 @@ func (c *Checkrr) deleteFile(path string) {
c.notifications.Notify("File Reacquire", fmt.Sprintf("\"%v\" was sent to lidarr to be reacquired", path), "reacquire", path)
c.Stats.LidarrSubmissions++
c.Stats.Write("Lidarr", c.Stats.LidarrSubmissions)
c.recordBadFile(path, "lidarr")
c.recordBadFile(path, "lidarr", reason)
return
}
}
log.WithFields(log.Fields{"Unknown File": true}).Infof("Couldn't find a target for file \"%v\". File is unknown.", path)
c.recordBadFile(path, "unknown")
c.recordBadFile(path, "unknown", reason)
}

func (c *Checkrr) recordBadFile(path string, fileType string) {
func (c *Checkrr) recordBadFile(path string, fileType string, reason string) {

bad := BadFile{}
if fileType != "unknown" {
Expand All @@ -403,6 +403,7 @@ func (c *Checkrr) recordBadFile(path string, fileType string) {
bad.Service = fileType
bad.FileExt = filepath.Ext(path)
bad.Date = time.Now().UTC().Unix() // put this in UTC for the webui to render in local later
bad.Reason = reason

err := c.DB.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("Checkrr-files"))
Expand All @@ -429,6 +430,7 @@ type BadFile struct {
Reacquire bool `json:"reacquire"`
Service string `json:"service"`
Date int64 `json:"date"`
Reason string `json:"reason"`
}

// TODO: if h2non/filetype#120 ever gets completed, remove this logic
Expand Down
2 changes: 2 additions & 0 deletions webserver/src/components/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const columns = [
{ field: 'date', headerName: 'Date Added', flex: 0.15},
{ field: 'path', headerName: 'Path', flex: 1},
{ field: 'ext', headerName: 'File Extension', flex: 0.15,},
{ field: 'reason', headerName: 'Reason', flex: 0.15},
{ field: 'reacquire', headerName: 'Reacquired', flex: 0.15},
{ field: 'service', headerName: 'Service', flex: 0.13},
];
Expand Down Expand Up @@ -55,6 +56,7 @@ export default function DataTable() {
id: i + 1,
date: timeConverter(l.Data.Date),
path: l.Path,
reason: l.Data.reason,
ext: l.Data.fileExt,
reacquire: l.Data.reacquire,
service: l.Data.service,
Expand Down

0 comments on commit 553fdfb

Please sign in to comment.