Skip to content

Commit

Permalink
Changelog: 0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
sirrobot01 committed Sep 1, 2024
1 parent 74791d6 commit d405e0d
Show file tree
Hide file tree
Showing 11 changed files with 397 additions and 110 deletions.
Empty file.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#### 0.1.0
- Initial Release
- Added Real Debrid Support
- Added Arrs Support
- Added Proxy Support
- Added Basic Authentication for Proxy
- Added Rate Limiting for Debrid Providers

#### 0.1.1
- Added support for "No Blackhole" for Arrs
- Added support for "Cached Only" for Proxy
- Bug Fixes

#### 0.1.2
- Bug fixes
- Code cleanup
- Get available hashes at once

#### 0.1.3

- Searching for infohashes in the xml description/summary/comments
- Added local cache support
- Added max cache size
- Rewrite blackhole.go
- Bug fixes
- Fixed indexer getting disabled
- Fixed blackhole not working
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This is a Golang implementation go Torrent Blackhole with a **Real Debrid Proxy

The proxy is useful in filtering out un-cached Real Debrid torrents

### Changelog

- View the [CHANGELOG.md](CHANGELOG.md) for the latest changes


#### Installation
##### Docker Compose
Expand Down Expand Up @@ -75,7 +79,8 @@ Download the binary from the releases page and run it with the config file.
"username": "username",
"password": "password",
"cached_only": true
}
},
"max_cache_size": 1000
}
```

Expand Down
53 changes: 34 additions & 19 deletions cmd/blackhole.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ import (
"time"
)

type Blackhole struct {
config *common.Config
deb debrid.Service
cache *common.Cache
}

func NewBlackhole(config *common.Config, deb debrid.Service, cache *common.Cache) *Blackhole {
return &Blackhole{
config: config,
deb: deb,
cache: cache,
}

}

func fileReady(path string) bool {
_, err := os.Stat(path)
return !os.IsNotExist(err) // Returns true if the file exists
Expand All @@ -33,7 +48,7 @@ func checkFileLoop(wg *sync.WaitGroup, dir string, file debrid.TorrentFile, read
}
}

func ProcessFiles(arr *debrid.Arr, torrent *debrid.Torrent) {
func (b *Blackhole) processFiles(arr *debrid.Arr, torrent *debrid.Torrent) {
var wg sync.WaitGroup
files := torrent.Files
ready := make(chan debrid.TorrentFile, len(files))
Expand All @@ -52,29 +67,29 @@ func ProcessFiles(arr *debrid.Arr, torrent *debrid.Torrent) {

for r := range ready {
log.Println("File is ready:", r.Name)
CreateSymLink(arr, torrent)
b.createSymLink(arr, torrent)

}
go torrent.Cleanup(true)
fmt.Printf("%s downloaded", torrent.Name)
}

func CreateSymLink(config *debrid.Arr, torrent *debrid.Torrent) {
path := filepath.Join(config.CompletedFolder, torrent.Folder)
func (b *Blackhole) createSymLink(arr *debrid.Arr, torrent *debrid.Torrent) {
path := filepath.Join(arr.CompletedFolder, torrent.Folder)
err := os.MkdirAll(path, os.ModePerm)
if err != nil {
log.Printf("Failed to create directory: %s\n", path)
}
for _, file := range torrent.Files {
// Combine the directory and filename to form a full path
fullPath := filepath.Join(config.CompletedFolder, file.Path)
fullPath := filepath.Join(arr.CompletedFolder, file.Path)

// Create a symbolic link if file doesn't exist
_ = os.Symlink(filepath.Join(config.Debrid.Folder, file.Path), fullPath)
_ = os.Symlink(filepath.Join(arr.Debrid.Folder, file.Path), fullPath)
}
}

func watchFiles(watcher *fsnotify.Watcher, events map[string]time.Time) {
func watcher(watcher *fsnotify.Watcher, events map[string]time.Time) {
for {
select {
case event, ok := <-watcher.Events:
Expand All @@ -96,7 +111,7 @@ func watchFiles(watcher *fsnotify.Watcher, events map[string]time.Time) {
}
}

func processFilesDebounced(arr *debrid.Arr, db debrid.Service, events map[string]time.Time, debouncePeriod time.Duration) {
func (b *Blackhole) processFilesDebounced(arr *debrid.Arr, events map[string]time.Time, debouncePeriod time.Duration) {
ticker := time.NewTicker(1 * time.Second) // Check every second
defer ticker.Stop()

Expand All @@ -105,15 +120,15 @@ func processFilesDebounced(arr *debrid.Arr, db debrid.Service, events map[string
if time.Since(lastEventTime) >= debouncePeriod {
log.Printf("Torrent file detected: %s", file)
// Process the torrent file
torrent, err := db.Process(arr, file)
torrent, err := b.deb.Process(arr, file)
if err != nil && torrent != nil {
// remove torrent file
torrent.Cleanup(true)
_ = torrent.MarkAsFailed()
log.Printf("Error processing torrent file: %s", err)
}
if err == nil && torrent != nil && len(torrent.Files) > 0 {
go ProcessFiles(arr, torrent)
go b.processFiles(arr, torrent)
}
delete(events, file) // remove file from channel

Expand All @@ -122,8 +137,8 @@ func processFilesDebounced(arr *debrid.Arr, db debrid.Service, events map[string
}
}

func StartArr(conf *debrid.Arr, db debrid.Service) {
log.Printf("Watching: %s", conf.WatchFolder)
func (b *Blackhole) startArr(arr *debrid.Arr) {
log.Printf("Watching: %s", arr.WatchFolder)
w, err := fsnotify.NewWatcher()
if err != nil {
log.Println(err)
Expand All @@ -136,19 +151,19 @@ func StartArr(conf *debrid.Arr, db debrid.Service) {
}(w)
events := make(map[string]time.Time)

go watchFiles(w, events)
if err = w.Add(conf.WatchFolder); err != nil {
go watcher(w, events)
if err = w.Add(arr.WatchFolder); err != nil {
log.Println("Error Watching folder:", err)
return
}

processFilesDebounced(conf, db, events, 1*time.Second)
b.processFilesDebounced(arr, events, 1*time.Second)
}

func StartBlackhole(config *common.Config, deb debrid.Service) {
func (b *Blackhole) Start() {
log.Println("[*] Starting Blackhole")
var wg sync.WaitGroup
for _, conf := range config.Arrs {
for _, conf := range b.config.Arrs {
wg.Add(1)
defer wg.Done()
headers := map[string]string{
Expand All @@ -157,14 +172,14 @@ func StartBlackhole(config *common.Config, deb debrid.Service) {
client := common.NewRLHTTPClient(nil, headers)

arr := &debrid.Arr{
Debrid: config.Debrid,
Debrid: b.config.Debrid,
WatchFolder: conf.WatchFolder,
CompletedFolder: conf.CompletedFolder,
Token: conf.Token,
URL: conf.URL,
Client: client,
}
go StartArr(arr, deb)
go b.startArr(arr)
}
wg.Wait()
}
12 changes: 8 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package cmd

import (
"cmp"
"goBlack/common"
"goBlack/debrid"
"sync"
)

func Start(config *common.Config) {

deb := debrid.NewDebrid(config.Debrid)
maxCacheSize := cmp.Or(config.MaxCacheSize, 1000)
cache := common.NewCache(maxCacheSize)

deb := debrid.NewDebrid(config.Debrid, cache)

var wg sync.WaitGroup

if config.Proxy.Enabled {
proxy := NewProxy(*config, deb)
proxy := NewProxy(*config, deb, cache)
wg.Add(1)
go func() {
defer wg.Done()
Expand All @@ -22,10 +25,11 @@ func Start(config *common.Config) {
}

if len(config.Arrs) > 0 {
blackhole := NewBlackhole(config, deb, cache)
wg.Add(1)
go func() {
defer wg.Done()
StartBlackhole(config, deb)
blackhole.Start()
}()
}

Expand Down
Loading

0 comments on commit d405e0d

Please sign in to comment.