This commit is contained in:
Mukhtar Akere
2024-08-26 02:22:21 +01:00
parent ad1ba7b505
commit 511df1a296
4 changed files with 16 additions and 13 deletions

View File

@@ -20,5 +20,7 @@ RUN CGO_ENABLED=0 GOOS=$(echo $TARGETPLATFORM | cut -d '/' -f1) GOARCH=$(echo $T
FROM scratch
COPY --from=builder /blackhole /blackhole
EXPOSE 8181
# Run
# CMD ["/blackhole", "--config", "/app/config.json"]
CMD ["/blackhole", "--config", "/app/config.json"]

View File

@@ -126,12 +126,12 @@ func StartArr(conf *debrid.Arr, db debrid.Service) {
log.Printf("Watching: %s", conf.WatchFolder)
w, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
log.Println(err)
}
defer func(w *fsnotify.Watcher) {
err := w.Close()
if err != nil {
log.Fatal(err)
log.Println(err)
}
}(w)
events := make(map[string]time.Time)

View File

@@ -13,6 +13,7 @@ import (
"io"
"log"
"net/http"
"os"
"regexp"
"strings"
"sync"
@@ -203,7 +204,7 @@ func ProcessXMLResponse(resp *http.Response, deb debrid.Service) *http.Response
var rss RSS
err = xml.Unmarshal(body, &rss)
if err != nil {
log.Fatalf("Error unmarshalling XML: %v", err)
log.Printf("Error unmarshalling XML: %v", err)
return resp
}
newItems := &SafeItems{}
@@ -220,7 +221,9 @@ func ProcessXMLResponse(resp *http.Response, deb debrid.Service) *http.Response
}(item)
}
wg.Wait()
rss.Channel.Items = newItems.Get()
items := newItems.Get()
log.Printf("Report: %d/%d items are cached", len(items), len(rss.Channel.Items))
rss.Channel.Items = items
// rss.Channel.Items = newItems
modifiedBody, err := xml.MarshalIndent(rss, "", " ")
@@ -230,11 +233,6 @@ func ProcessXMLResponse(resp *http.Response, deb debrid.Service) *http.Response
}
modifiedBody = append([]byte(xml.Header), modifiedBody...)
if err != nil {
log.Fatalf("Error marshalling XML: %v", err)
return resp
}
// Set the modified body back to the response
resp.Body = io.NopCloser(bytes.NewReader(modifiedBody))
resp.ContentLength = int64(len(modifiedBody))
@@ -266,7 +264,7 @@ func StartProxy(config *common.Config, deb debrid.Service) {
return ProcessResponse(resp, deb)
})
port := cmp.Or(cfg.Port, "8181")
port := cmp.Or(os.Getenv("PORT"), cfg.Port, "8181")
proxy.Verbose = cfg.Debug
port = fmt.Sprintf(":%s", port)
log.Printf("Starting proxy server on %s\n", port)

View File

@@ -31,8 +31,13 @@ func (r *RealDebrid) Process(arr *Arr, magnet string) (*Torrent, error) {
if !r.IsAvailable(torrent.Magnet) {
return torrent, fmt.Errorf("torrent is not cached")
}
log.Printf("Torrent: %s is cached", torrent.Name)
}
torrent, err = r.SubmitMagnet(torrent)
if err != nil || torrent.Id == "" {
return nil, err
}
return r.CheckStatus(torrent)
}
@@ -49,10 +54,8 @@ func (r *RealDebrid) IsAvailable(magnet *common.Magnet) bool {
}
hosters, exists := data[strings.ToLower(magnet.InfoHash)]
if !exists || len(hosters) < 1 {
log.Printf("Torrent: %s not cached", magnet.Name)
return false
}
log.Printf("Torrent: %s is cached", magnet.Name)
return true
}