From cbe3a2191ce1622f50d93d004df3e32f76ae2353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Fri, 3 Jul 2020 22:44:13 +0800 Subject: [PATCH 01/26] 1 --- static/files/template/download-tree.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/files/template/download-tree.html b/static/files/template/download-tree.html index e3c026e55..cfb05096c 100644 --- a/static/files/template/download-tree.html +++ b/static/files/template/download-tree.html @@ -18,7 +18,7 @@
{{ node.Size | bytes }} - {{ ago(node.Modified) }}
-
{{ node.Size | bytes }} - {{ ago(node.Modified) }}
From b983f49ad6bd7782309a42e066dcee2f465fc574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Sat, 1 Aug 2020 15:07:51 +0800 Subject: [PATCH 04/26] 4 --- engine/ffmpeg/ffmpeg.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/engine/ffmpeg/ffmpeg.go b/engine/ffmpeg/ffmpeg.go index fd7b79090..29da2cf04 100644 --- a/engine/ffmpeg/ffmpeg.go +++ b/engine/ffmpeg/ffmpeg.go @@ -4,6 +4,7 @@ import ( _ "errors" "fmt" "github.com/xfrr/goffmpeg/ffmpeg" + "log" "github.com/xfrr/goffmpeg/transcoder" ) @@ -14,6 +15,7 @@ type Ff struct { } func Tomp4(inputPath, outputPath string) { + log.Println("input-output:", inputPath, outputPath) // Create new instance of transcoder trans := new(transcoder.Transcoder) //trans.MediaFile().SetVideoCodec("xvid") @@ -24,7 +26,7 @@ func Tomp4(inputPath, outputPath string) { trans.MediaFile().SetVideoBitRate("400k") trans.MediaFile().SetFrameRate(25) - fmt.Print(err) + log.Println("err:", err) // Handle error... // Start transcoder process without checking progress From b632d270eccca9d955d30c033bef6b390fe7f977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Sat, 1 Aug 2020 15:08:06 +0800 Subject: [PATCH 05/26] 4 --- engine/ffmpeg/ffmpeg.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/engine/ffmpeg/ffmpeg.go b/engine/ffmpeg/ffmpeg.go index 29da2cf04..f45a3a0b2 100644 --- a/engine/ffmpeg/ffmpeg.go +++ b/engine/ffmpeg/ffmpeg.go @@ -3,7 +3,6 @@ package ffmpeg import ( _ "errors" "fmt" - "github.com/xfrr/goffmpeg/ffmpeg" "log" "github.com/xfrr/goffmpeg/transcoder" @@ -19,8 +18,8 @@ func Tomp4(inputPath, outputPath string) { // Create new instance of transcoder trans := new(transcoder.Transcoder) //trans.MediaFile().SetVideoCodec("xvid") - f := ffmpeg.Configuration{FfprobeBin: "E:/worktool/ffmpeg/bin/ffprobe.exe ", FfmpegBin: "E:/worktool/ffmpeg/bin/ffmpeg.exe "} - trans.SetConfiguration(f) + //f := ffmpeg.Configuration{FfprobeBin: "E:/worktool/ffmpeg/bin/ffprobe.exe ", FfmpegBin: "E:/worktool/ffmpeg/bin/ffmpeg.exe "} + //trans.SetConfiguration(f) err := trans.Initialize(inputPath, outputPath) trans.MediaFile().SetResolution("480x320") trans.MediaFile().SetVideoBitRate("400k") From 46da0e376fc9d7a3689b88105dd55cbf3f5a66f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Sat, 1 Aug 2020 15:25:31 +0800 Subject: [PATCH 06/26] 5 --- engine/ffmpeg/ffmpeg.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/engine/ffmpeg/ffmpeg.go b/engine/ffmpeg/ffmpeg.go index f45a3a0b2..d91e4d139 100644 --- a/engine/ffmpeg/ffmpeg.go +++ b/engine/ffmpeg/ffmpeg.go @@ -14,18 +14,19 @@ type Ff struct { } func Tomp4(inputPath, outputPath string) { + outputPath = outputPath + ".mp4" log.Println("input-output:", inputPath, outputPath) // Create new instance of transcoder trans := new(transcoder.Transcoder) - //trans.MediaFile().SetVideoCodec("xvid") //f := ffmpeg.Configuration{FfprobeBin: "E:/worktool/ffmpeg/bin/ffprobe.exe ", FfmpegBin: "E:/worktool/ffmpeg/bin/ffmpeg.exe "} //trans.SetConfiguration(f) err := trans.Initialize(inputPath, outputPath) + log.Println("err:", err) + trans.MediaFile().SetVideoCodec("xvid") trans.MediaFile().SetResolution("480x320") trans.MediaFile().SetVideoBitRate("400k") trans.MediaFile().SetFrameRate(25) - log.Println("err:", err) // Handle error... // Start transcoder process without checking progress From d47cceeb188e0a167efa228c4f6626de77a7fae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Sat, 1 Aug 2020 15:40:07 +0800 Subject: [PATCH 07/26] 6 --- engine/ffmpeg/ffmpeg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/ffmpeg/ffmpeg.go b/engine/ffmpeg/ffmpeg.go index d91e4d139..23dd827cc 100644 --- a/engine/ffmpeg/ffmpeg.go +++ b/engine/ffmpeg/ffmpeg.go @@ -22,7 +22,7 @@ func Tomp4(inputPath, outputPath string) { //trans.SetConfiguration(f) err := trans.Initialize(inputPath, outputPath) log.Println("err:", err) - trans.MediaFile().SetVideoCodec("xvid") + //trans.MediaFile().SetVideoCodec("xvid") trans.MediaFile().SetResolution("480x320") trans.MediaFile().SetVideoBitRate("400k") trans.MediaFile().SetFrameRate(25) From c85dd952edf5d9537b3066a0f51d65ed5180cbb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Sat, 1 Aug 2020 18:03:35 +0800 Subject: [PATCH 08/26] 7 --- engine/engine.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/engine/engine.go b/engine/engine.go index a16e3a8e2..1c33da744 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -279,9 +279,7 @@ func genEnv(dir, path, hash, ttype, api string, size int64, ts int64) []string { } func (e *Engine) Tomp4(input, output string) error { - e.RLock() ffmpeg.Tomp4(input, output) - e.RLock() return nil } From afad9909354f8b4bcfdb46bdf9b73cfd7808f58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Sat, 1 Aug 2020 18:05:56 +0800 Subject: [PATCH 09/26] 8 --- engine/ffmpeg/ffmpeg.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/engine/ffmpeg/ffmpeg.go b/engine/ffmpeg/ffmpeg.go index 23dd827cc..c28a3730b 100644 --- a/engine/ffmpeg/ffmpeg.go +++ b/engine/ffmpeg/ffmpeg.go @@ -1,9 +1,9 @@ package ffmpeg import ( - _ "errors" "fmt" "log" + "sync" "github.com/xfrr/goffmpeg/transcoder" ) @@ -30,16 +30,17 @@ func Tomp4(inputPath, outputPath string) { // Handle error... // Start transcoder process without checking progress - done := trans.Run(true) - fmt.Print(done) - // This channel is used to wait for the process to end - progress := trans.Output() - - // Example of printing transcoding progress - for msg := range progress { - fmt.Println(msg) - } - - err = <-done + var mutex sync.RWMutex + // Start transcoder process without checking progress + go func() { + mutex.RLock() + done := trans.Run(true) + fmt.Print(done) + progress := trans.Output() + for msg := range progress { + fmt.Println(msg) + } + mutex.RUnlock() + }() } From 8caf23541873331c7ee3dae0d0af3c7d45aafafd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=A4=E7=8B=90=E5=86=B2?= Date: Sun, 2 Aug 2020 20:15:27 +0800 Subject: [PATCH 10/26] Update ffmpeg.go 9 --- engine/ffmpeg/ffmpeg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/ffmpeg/ffmpeg.go b/engine/ffmpeg/ffmpeg.go index c28a3730b..4bdc00e9a 100644 --- a/engine/ffmpeg/ffmpeg.go +++ b/engine/ffmpeg/ffmpeg.go @@ -23,7 +23,7 @@ func Tomp4(inputPath, outputPath string) { err := trans.Initialize(inputPath, outputPath) log.Println("err:", err) //trans.MediaFile().SetVideoCodec("xvid") - trans.MediaFile().SetResolution("480x320") + trans.MediaFile().SetResolution("320x240") trans.MediaFile().SetVideoBitRate("400k") trans.MediaFile().SetFrameRate(25) From 2aeccd4e850ac009982f1e253e938f9c92f7b568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Tue, 4 Aug 2020 22:27:51 +0800 Subject: [PATCH 11/26] 10 --- engine/engine.go | 1 - engine/ffmpeg/ffmpeg.go | 51 +++++++++++++++--------- server/server.go | 1 + server/server_files.go | 13 ++++++ static/files/template/download-tree.html | 6 +-- 5 files changed, 49 insertions(+), 23 deletions(-) diff --git a/engine/engine.go b/engine/engine.go index 1c33da744..81c41da1a 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -36,7 +36,6 @@ type Engine struct { client *torrent.Client closeSync chan struct{} config Config - ff ffmpeg.Ff ts map[string]*Torrent bttracker []string doneThreshold time.Duration diff --git a/engine/ffmpeg/ffmpeg.go b/engine/ffmpeg/ffmpeg.go index c28a3730b..ee75c988c 100644 --- a/engine/ffmpeg/ffmpeg.go +++ b/engine/ffmpeg/ffmpeg.go @@ -2,45 +2,58 @@ package ffmpeg import ( "fmt" + "github.com/xfrr/goffmpeg/ffmpeg" + "github.com/xfrr/goffmpeg/models" + "github.com/xfrr/goffmpeg/transcoder" "log" + "path" "sync" - - "github.com/xfrr/goffmpeg/transcoder" ) -type Ff struct { - input string - output string -} +var mm = make(map[string]<-chan models.Progress) +var mutex sync.RWMutex func Tomp4(inputPath, outputPath string) { - outputPath = outputPath + ".mp4" log.Println("input-output:", inputPath, outputPath) - // Create new instance of transcoder + mutex.RLock() + defer mutex.RUnlock() + if t := mm[inputPath]; t != nil { + log.Println("is doing ", inputPath) + return + } + + outputPath = outputPath + ".mp4" trans := new(transcoder.Transcoder) - //f := ffmpeg.Configuration{FfprobeBin: "E:/worktool/ffmpeg/bin/ffprobe.exe ", FfmpegBin: "E:/worktool/ffmpeg/bin/ffmpeg.exe "} - //trans.SetConfiguration(f) + + fpath := ffmpeg.Configuration{FfprobeBin: "E:/worktool/ffmpeg/bin/ffprobe.exe ", FfmpegBin: "E:/worktool/ffmpeg/bin/ffmpeg.exe "} + trans.SetConfiguration(fpath) err := trans.Initialize(inputPath, outputPath) log.Println("err:", err) - //trans.MediaFile().SetVideoCodec("xvid") - trans.MediaFile().SetResolution("480x320") + trans.MediaFile().SetResolution("320x240") trans.MediaFile().SetVideoBitRate("400k") trans.MediaFile().SetFrameRate(25) - // Handle error... - - // Start transcoder process without checking progress - var mutex sync.RWMutex - // Start transcoder process without checking progress go func() { - mutex.RLock() done := trans.Run(true) fmt.Print(done) progress := trans.Output() + mm[inputPath] = progress for msg := range progress { fmt.Println(msg) } - mutex.RUnlock() + delete(mm, inputPath) }() } + +func ListProgress() map[string]float64 { + res := make(map[string]float64) + for transs := range mm { + out := mm[transs] + num := <-out + filenameWithSuffix := path.Base(transs) + ".mp4" + fmt.Println("get file", filenameWithSuffix) + res[filenameWithSuffix] = num.Progress + } + return res +} diff --git a/server/server.go b/server/server.go index cb4bcc7a7..31de00d23 100644 --- a/server/server.go +++ b/server/server.go @@ -74,6 +74,7 @@ type Server struct { state struct { velox.State sync.Mutex + ffm []*ffm Config engine.Config SearchProviders scraper.Config Downloads *fsNode diff --git a/server/server_files.go b/server/server_files.go index 16376e12c..5a0a131b7 100644 --- a/server/server_files.go +++ b/server/server_files.go @@ -1,6 +1,7 @@ package server import ( + "cloud-torrent/engine/ffmpeg" "errors" "fmt" "io/ioutil" @@ -20,9 +21,15 @@ type fsNode struct { Name string Size int64 Modified time.Time + Process float64 Children []*fsNode } +type ffm struct { + File string + Size float64 +} + func (s *Server) listFiles() *fsNode { rootDir := s.state.Config.DownloadDirectory root := &fsNode{} @@ -84,8 +91,14 @@ func list(path string, info os.FileInfo, node *fsNode, n *int) error { if (*n) > fileNumberLimit { return errors.New("Over file limit") //limit number of files walked } + m := ffmpeg.ListProgress() + p := m[info.Name()] node.Name = info.Name() node.Size = info.Size() + if p != 0.00 { + fmt.Println(p) + node.Process = p + } node.Modified = info.ModTime() if !info.IsDir() { return nil diff --git a/static/files/template/download-tree.html b/static/files/template/download-tree.html index 8e4afb676..adfee3224 100644 --- a/static/files/template/download-tree.html +++ b/static/files/template/download-tree.html @@ -9,12 +9,12 @@
{{ node.Name }} {{ node.Name }} - + - + {{ node.Process }}
{{ node.Size | bytes }} - {{ ago(node.Modified) }}
@@ -29,6 +29,6 @@
+ src="'template/download-tree.html'">
\ No newline at end of file From b43cb287a831d5763f83db3ebbc8970d569cf432 Mon Sep 17 00:00:00 2001 From: ningqi Date: Wed, 5 Aug 2020 19:58:51 +0800 Subject: [PATCH 12/26] 12 --- engine/ffmpeg/ffmpeg.go | 40 ++++++++++++++---------- server/server_files.go | 8 ++--- static/files/js/downloads-controller.js | 2 +- static/files/template/download-tree.html | 12 +++---- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/engine/ffmpeg/ffmpeg.go b/engine/ffmpeg/ffmpeg.go index 5f65373eb..1136c2a3d 100644 --- a/engine/ffmpeg/ffmpeg.go +++ b/engine/ffmpeg/ffmpeg.go @@ -2,33 +2,35 @@ package ffmpeg import ( "fmt" - "github.com/xfrr/goffmpeg/models" "github.com/xfrr/goffmpeg/transcoder" "log" "path" "sync" + "time" ) -var mm = make(map[string]<-chan models.Progress) +var mm = make(map[string]float64) + var mutex sync.RWMutex func Tomp4(inputPath, outputPath string) { log.Println("input-output:", inputPath, outputPath) + outputPath = outputPath + ".mp4" mutex.RLock() + key := path.Base(outputPath) defer mutex.RUnlock() - if t := mm[inputPath]; t != nil { + if t := mm[key]; t != 0 { log.Println("is doing ", inputPath) return } - outputPath = outputPath + ".mp4" trans := new(transcoder.Transcoder) //fpath := ffmpeg.Configuration{FfprobeBin: "E:/worktool/ffmpeg/bin/ffprobe.exe ", FfmpegBin: "E:/worktool/ffmpeg/bin/ffmpeg.exe "} //trans.SetConfiguration(fpath) err := trans.Initialize(inputPath, outputPath) log.Println("err:", err) - trans.MediaFile().SetResolution("320x240") + //trans.MediaFile().SetResolution("320x240") //trans.MediaFile().SetVideoCodec("xvid") trans.MediaFile().SetResolution("320x240") trans.MediaFile().SetVideoBitRate("400k") @@ -38,23 +40,29 @@ func Tomp4(inputPath, outputPath string) { done := trans.Run(true) fmt.Print(done) progress := trans.Output() - mm[inputPath] = progress for msg := range progress { + mm[key] = msg.Progress fmt.Println(msg) + time.Sleep(time.Second * 5) } - delete(mm, inputPath) + delete(mm, key) }() } -func ListProgress() map[string]float64 { - res := make(map[string]float64) - for transs := range mm { - out := mm[transs] - num := <-out - filenameWithSuffix := path.Base(transs) + ".mp4" - fmt.Println("get file", filenameWithSuffix) - res[filenameWithSuffix] = num.Progress +func ListProgress(key string) float64 { + //res := make(map[string]float64) + //for transs := range mm { + // out := mm[transs] + // num := <-out + // filenameWithSuffix := path.Base(transs) + ".mp4" + // fmt.Println("get file", filenameWithSuffix) + // res[filenameWithSuffix] = num.Progress + //} + //return res + if out := mm[key]; out != 0 { + return out } - return res + return 0 + } diff --git a/server/server_files.go b/server/server_files.go index 5a0a131b7..1d6412587 100644 --- a/server/server_files.go +++ b/server/server_files.go @@ -91,14 +91,10 @@ func list(path string, info os.FileInfo, node *fsNode, n *int) error { if (*n) > fileNumberLimit { return errors.New("Over file limit") //limit number of files walked } - m := ffmpeg.ListProgress() - p := m[info.Name()] + m := ffmpeg.ListProgress(info.Name()) + node.Process = m node.Name = info.Name() node.Size = info.Size() - if p != 0.00 { - fmt.Println(p) - node.Process = p - } node.Modified = info.ModTime() if !info.IsDir() { return nil diff --git a/static/files/js/downloads-controller.js b/static/files/js/downloads-controller.js index 339165d84..ccaa9e966 100644 --- a/static/files/js/downloads-controller.js +++ b/static/files/js/downloads-controller.js @@ -36,7 +36,7 @@ app.controller("NodeController", function($scope, $rootScope, $http, $timeout) { n.$closed = $scope.agoHrs(n.Modified) > 24; $scope.audioPreview = /\.(mp3|m4a)$/.test(path); $scope.imagePreview = /\.(jpe?g|png|gif)$/.test(path); - $scope.videoPreview = /\.(mp4|mkv|mov)$/.test(path); + $scope.videoPreview = /\.(avi|wmv|mpeg|mp4|m4v|mov|asf|flv|f4v|rmvb|rm|3gp|vob)$/.test(path); //search for this file var torrents = $rootScope.state.Torrents; diff --git a/static/files/template/download-tree.html b/static/files/template/download-tree.html index adfee3224..31664a088 100644 --- a/static/files/template/download-tree.html +++ b/static/files/template/download-tree.html @@ -9,12 +9,12 @@
{{ node.Name }} {{ node.Name }} - - - - - - {{ node.Process }} + + + + + + {{ node.Process }}
{{ node.Size | bytes }} - {{ ago(node.Modified) }}
From 55daee5ac58f45d581e96cfdb9106bf4aa37c140 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 5 Aug 2020 08:45:25 -0400 Subject: [PATCH 13/26] 131313131313131313131313 --- engine/ffmpeg/ffmpeg.go | 1 - 1 file changed, 1 deletion(-) diff --git a/engine/ffmpeg/ffmpeg.go b/engine/ffmpeg/ffmpeg.go index 1136c2a3d..d50ef392e 100644 --- a/engine/ffmpeg/ffmpeg.go +++ b/engine/ffmpeg/ffmpeg.go @@ -43,7 +43,6 @@ func Tomp4(inputPath, outputPath string) { for msg := range progress { mm[key] = msg.Progress fmt.Println(msg) - time.Sleep(time.Second * 5) } delete(mm, key) }() From 27c4f23e2b4991855d12a72bdca1c21a7fb06992 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 5 Aug 2020 08:51:43 -0400 Subject: [PATCH 14/26] 14 --- engine/ffmpeg/ffmpeg.go | 1 - 1 file changed, 1 deletion(-) diff --git a/engine/ffmpeg/ffmpeg.go b/engine/ffmpeg/ffmpeg.go index d50ef392e..c97841f51 100644 --- a/engine/ffmpeg/ffmpeg.go +++ b/engine/ffmpeg/ffmpeg.go @@ -6,7 +6,6 @@ import ( "log" "path" "sync" - "time" ) var mm = make(map[string]float64) From 346c4075bf306a550de619c4561e18aebd2940cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Fri, 7 Aug 2020 20:36:59 +0800 Subject: [PATCH 15/26] 14 --- static/files/template/download-tree.html | 2 +- static/files/template/downloads.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/static/files/template/download-tree.html b/static/files/template/download-tree.html index 31664a088..47708dd80 100644 --- a/static/files/template/download-tree.html +++ b/static/files/template/download-tree.html @@ -28,7 +28,7 @@
-
\ No newline at end of file diff --git a/static/files/template/downloads.html b/static/files/template/downloads.html index 10cf2ffbb..a4f5b4cbd 100644 --- a/static/files/template/downloads.html +++ b/static/files/template/downloads.html @@ -17,7 +17,7 @@
-
From 3bb2994e1d7382614016b70e6c90debc2786a028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Sat, 8 Aug 2020 16:38:10 +0800 Subject: [PATCH 16/26] 15 --- engine/config.go | 3 +++ engine/engine.go | 7 ++++++- main.go | 2 +- static/files/js/config-controller.js | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/engine/config.go b/engine/config.go index 7ef3a8789..677597901 100644 --- a/engine/config.go +++ b/engine/config.go @@ -24,6 +24,7 @@ const ( const ( defaultTrackerListURL = "https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt" defaultScraperURL = "https://raw.githubusercontent.com/boypt/simple-torrent/master/scraper-config.json" + fileSuffix = "avi|wmv|mpeg|mp4|m4v|mov|asf|flv|f4v|rmvb|rm|3gp|vob|jpe?g|png|gif|mp3|m4a" ) type Config struct { @@ -49,6 +50,7 @@ type Config struct { ProxyURL string RssURL string ScraperURL string + FileSuffix string } func InitConf(specPath string) (*Config, error) { @@ -71,6 +73,7 @@ func InitConf(specPath string) (*Config, error) { viper.SetDefault("IncomingPort", 50007) viper.SetDefault("TrackerListURL", defaultTrackerListURL) viper.SetDefault("ScraperURL", defaultScraperURL) + viper.SetDefault("FileSuffix", fileSuffix) // user specific config path if stat, err := os.Stat(specPath); stat != nil && err == nil { diff --git a/engine/engine.go b/engine/engine.go index 81c41da1a..94afdaf0f 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -14,6 +14,7 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "strings" "sync" "time" @@ -332,7 +333,11 @@ func (e *Engine) StartTorrent(infohash string) error { if t.t.Info() != nil { // start file by setting the priority for _, f := range t.t.Files() { - f.SetPriority(torrent.PiecePriorityNormal) + if regexp.MustCompile(e.config.FileSuffix).MatchString(f.Path()) { + f.SetPriority(torrent.PiecePriorityNormal) + } else { + f.SetPriority(torrent.PiecePriorityNone) + } } // call to DownloadAll cause StartFile/StopFile not working diff --git a/main.go b/main.go index 319f19ae5..e0a685089 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ var VERSION = "0.0.0-src" //set with ldflags func main() { s := server.Server{ - Title: "SimpleTorrent", + Title: "开始", Port: 3000, } diff --git a/static/files/js/config-controller.js b/static/files/js/config-controller.js index b7b8c239f..e03f6026b 100644 --- a/static/files/js/config-controller.js +++ b/static/files/js/config-controller.js @@ -20,7 +20,8 @@ app.controller("ConfigController", function ($scope, $rootScope, storage, api) { "ProxyURL", "TrackerListURL", "AlwaysAddTrackers", - "RssURL" + "RssURL", + "FileSuffix" ]; $scope.configTip = { From 665ca2d97db27fe0ead0ba4d54fdbb5f812172ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Sat, 8 Aug 2020 19:51:43 +0800 Subject: [PATCH 17/26] 16 --- engine/engine.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/engine.go b/engine/engine.go index 94afdaf0f..26ac35e18 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -326,14 +326,14 @@ func (e *Engine) StartTorrent(infohash string) error { t.Started = true t.StartedAt = time.Now() for _, f := range t.Files { - if f != nil { + if regexp.MustCompile(e.config.FileSuffix).MatchString(strings.ToLower(f.Path)) { f.Started = true } } if t.t.Info() != nil { // start file by setting the priority for _, f := range t.t.Files() { - if regexp.MustCompile(e.config.FileSuffix).MatchString(f.Path()) { + if regexp.MustCompile(e.config.FileSuffix).MatchString(strings.ToLower(f.Path())) { f.SetPriority(torrent.PiecePriorityNormal) } else { f.SetPriority(torrent.PiecePriorityNone) From ddd91901e994d04bb5ce539b74c416634a7c4231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Sat, 8 Aug 2020 20:10:24 +0800 Subject: [PATCH 18/26] 17 --- engine/engine.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/engine/engine.go b/engine/engine.go index 26ac35e18..7b42b662c 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -326,6 +326,7 @@ func (e *Engine) StartTorrent(infohash string) error { t.Started = true t.StartedAt = time.Now() for _, f := range t.Files { + fmt.Println("==========", regexp.MustCompile(e.config.FileSuffix).MatchString(strings.ToLower(f.Path)), f.Path) if regexp.MustCompile(e.config.FileSuffix).MatchString(strings.ToLower(f.Path)) { f.Started = true } @@ -333,6 +334,7 @@ func (e *Engine) StartTorrent(infohash string) error { if t.t.Info() != nil { // start file by setting the priority for _, f := range t.t.Files() { + fmt.Println("-----------", regexp.MustCompile(e.config.FileSuffix).MatchString(strings.ToLower(f.Path())), f.Path()) if regexp.MustCompile(e.config.FileSuffix).MatchString(strings.ToLower(f.Path())) { f.SetPriority(torrent.PiecePriorityNormal) } else { From 6f37ed7f053df64ee4f6592d4040ed99dcc3b5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Sat, 8 Aug 2020 20:32:55 +0800 Subject: [PATCH 19/26] 18 --- static/files/js/downloads-controller.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/static/files/js/downloads-controller.js b/static/files/js/downloads-controller.js index ccaa9e966..689488fc8 100644 --- a/static/files/js/downloads-controller.js +++ b/static/files/js/downloads-controller.js @@ -34,9 +34,9 @@ app.controller("NodeController", function($scope, $rootScope, $http, $timeout) { } var path = (n.$path = pathArray.join("/")); n.$closed = $scope.agoHrs(n.Modified) > 24; - $scope.audioPreview = /\.(mp3|m4a)$/.test(path); - $scope.imagePreview = /\.(jpe?g|png|gif)$/.test(path); - $scope.videoPreview = /\.(avi|wmv|mpeg|mp4|m4v|mov|asf|flv|f4v|rmvb|rm|3gp|vob)$/.test(path); + $scope.audioPreview = /\.(mp3|m4a)$/i.test(path); + $scope.imagePreview = /\.(jpe?g|png|gif)$/i.test(path); + $scope.videoPreview = /\.(avi|wmv|mpeg|mp4|m4v|mov|asf|flv|f4v|rmvb|rm|3gp|vob)$/i.test(path); //search for this file var torrents = $rootScope.state.Torrents; From 506ad9b9fca10bcd69a1d7828bbec1091eef4680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Sat, 8 Aug 2020 20:47:04 +0800 Subject: [PATCH 20/26] 19 --- engine/engine.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/engine/engine.go b/engine/engine.go index 7b42b662c..26ac35e18 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -326,7 +326,6 @@ func (e *Engine) StartTorrent(infohash string) error { t.Started = true t.StartedAt = time.Now() for _, f := range t.Files { - fmt.Println("==========", regexp.MustCompile(e.config.FileSuffix).MatchString(strings.ToLower(f.Path)), f.Path) if regexp.MustCompile(e.config.FileSuffix).MatchString(strings.ToLower(f.Path)) { f.Started = true } @@ -334,7 +333,6 @@ func (e *Engine) StartTorrent(infohash string) error { if t.t.Info() != nil { // start file by setting the priority for _, f := range t.t.Files() { - fmt.Println("-----------", regexp.MustCompile(e.config.FileSuffix).MatchString(strings.ToLower(f.Path())), f.Path()) if regexp.MustCompile(e.config.FileSuffix).MatchString(strings.ToLower(f.Path())) { f.SetPriority(torrent.PiecePriorityNormal) } else { From bd0d3f3a8ceee96701649335192700a860bc426b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Tue, 18 Aug 2020 22:10:39 +0800 Subject: [PATCH 21/26] 20 --- engine/engine.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/engine/engine.go b/engine/engine.go index 26ac35e18..43f5fef38 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -333,6 +333,8 @@ func (e *Engine) StartTorrent(infohash string) error { if t.t.Info() != nil { // start file by setting the priority for _, f := range t.t.Files() { + log.Println(f.Path()) + log.Println(regexp.MustCompile(e.config.FileSuffix).MatchString(strings.ToLower(f.Path()))) if regexp.MustCompile(e.config.FileSuffix).MatchString(strings.ToLower(f.Path())) { f.SetPriority(torrent.PiecePriorityNormal) } else { @@ -341,7 +343,7 @@ func (e *Engine) StartTorrent(infohash string) error { } // call to DownloadAll cause StartFile/StopFile not working - // t.t.DownloadAll() + // t.t.DownloadAll() } return nil } From 986ccbc8707e042c3824aeacd7136f92cee6bfe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cgnq=EF=BC=9B?= Date: Sat, 10 Apr 2021 20:57:58 +0800 Subject: [PATCH 22/26] 202 --- server/server_files.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/server_files.go b/server/server_files.go index 1d6412587..11a40c04a 100644 --- a/server/server_files.go +++ b/server/server_files.go @@ -15,7 +15,7 @@ import ( "github.com/jpillora/archive" ) -const fileNumberLimit = 1000 +const fileNumberLimit = 100000 type fsNode struct { Name string From d844d7414b0eb258bb3823634e29542191bc4dca Mon Sep 17 00:00:00 2001 From: cgnq Date: Sat, 27 Nov 2021 21:58:05 +0800 Subject: [PATCH 23/26] 12 --- engine/ffmpeg/ffmpeg.go | 3 ++ engine/ffmpeg/ffmpeg_win.go | 67 ++++++++++++++++++++++++ static/files/js/downloads-controller.js | 8 +++ static/files/template/download-tree.html | 1 + 4 files changed, 79 insertions(+) create mode 100644 engine/ffmpeg/ffmpeg_win.go diff --git a/engine/ffmpeg/ffmpeg.go b/engine/ffmpeg/ffmpeg.go index c97841f51..9f6d012bc 100644 --- a/engine/ffmpeg/ffmpeg.go +++ b/engine/ffmpeg/ffmpeg.go @@ -1,3 +1,6 @@ +//go:build !windows +// +build !windows + package ffmpeg import ( diff --git a/engine/ffmpeg/ffmpeg_win.go b/engine/ffmpeg/ffmpeg_win.go new file mode 100644 index 000000000..f543d0948 --- /dev/null +++ b/engine/ffmpeg/ffmpeg_win.go @@ -0,0 +1,67 @@ +package ffmpeg + +import ( + "fmt" + "github.com/xfrr/goffmpeg/ffmpeg" + "github.com/xfrr/goffmpeg/transcoder" + "log" + "path" + "sync" +) + +var mm = make(map[string]float64) + +var mutex sync.RWMutex + +func Tomp4(inputPath, outputPath string) { + log.Println("input-output:", inputPath, outputPath) + outputPath = outputPath + ".mp4" + mutex.RLock() + key := path.Base(outputPath) + defer mutex.RUnlock() + if t := mm[key]; t != 0 { + log.Println("is doing ", inputPath) + return + } + + trans := new(transcoder.Transcoder) + + fpath := ffmpeg.Configuration{FfprobeBin: "E:/worktool/ffmpeg/bin/ffprobe.exe ", FfmpegBin: "E:/worktool/ffmpeg/bin/ffmpeg.exe "} + trans.SetConfiguration(fpath) + err := trans.Initialize(inputPath, outputPath) + log.Println("err:", err) + //trans.MediaFile().SetResolution("320x240") + //trans.MediaFile().SetVideoCodec("xvid") + trans.MediaFile().SetResolution("320x240") + trans.MediaFile().SetVideoBitRate("400k") + trans.MediaFile().SetFrameRate(25) + + go func() { + done := trans.Run(true) + fmt.Print(done) + progress := trans.Output() + for msg := range progress { + mm[key] = msg.Progress + fmt.Println(msg) + } + delete(mm, key) + }() + +} + +func ListProgress(key string) float64 { + //res := make(map[string]float64) + //for transs := range mm { + // out := mm[transs] + // num := <-out + // filenameWithSuffix := path.Base(transs) + ".mp4" + // fmt.Println("get file", filenameWithSuffix) + // res[filenameWithSuffix] = num.Progress + //} + //return res + if out := mm[key]; out != 0 { + return out + } + return 0 + +} diff --git a/static/files/js/downloads-controller.js b/static/files/js/downloads-controller.js index 689488fc8..b2b84fc56 100644 --- a/static/files/js/downloads-controller.js +++ b/static/files/js/downloads-controller.js @@ -112,4 +112,12 @@ app.controller("NodeController", function($scope, $rootScope, $http, $timeout) { $scope.tomp4 = function() { $http.get("api/tomp4?input=" + n.$path+"&output="+n.$path); }; + $scope.toaria = function() { + console.log() + $http.post("http://raspberrypi:6800/jsonrpc", '{"jsonrpc": "2.0", "method": "aria2.addUri","id": "QXJpYU5nXzE2MzgwMjA0NDFfMC42MzAwMTQ5MDIyNTY4NzY2","params": [["https://oloking.xyz/download/'+n.$path+'"],{}]}', + { + transformRequest: [] + }) + }; + }); diff --git a/static/files/template/download-tree.html b/static/files/template/download-tree.html index 47708dd80..ad68b8682 100644 --- a/static/files/template/download-tree.html +++ b/static/files/template/download-tree.html @@ -14,6 +14,7 @@ + {{ node.Process }} From 9c7adb700483eb7550c233a94b222bf8ad8d1de0 Mon Sep 17 00:00:00 2001 From: cgnq Date: Sat, 27 Nov 2021 22:06:45 +0800 Subject: [PATCH 24/26] 123 --- engine/ffmpeg/ffmpeg_win.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/engine/ffmpeg/ffmpeg_win.go b/engine/ffmpeg/ffmpeg_win.go index f543d0948..00b2d3f80 100644 --- a/engine/ffmpeg/ffmpeg_win.go +++ b/engine/ffmpeg/ffmpeg_win.go @@ -1,3 +1,6 @@ +//go:build windows +// +build windows + package ffmpeg import ( From b2d97de0b81594dd39ec39ec7976bcd67cc6c15a Mon Sep 17 00:00:00 2001 From: cgnq Date: Thu, 2 Dec 2021 21:49:21 +0800 Subject: [PATCH 25/26] 1234 --- static/files/js/downloads-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/files/js/downloads-controller.js b/static/files/js/downloads-controller.js index b2b84fc56..9c72e1133 100644 --- a/static/files/js/downloads-controller.js +++ b/static/files/js/downloads-controller.js @@ -114,7 +114,7 @@ app.controller("NodeController", function($scope, $rootScope, $http, $timeout) { }; $scope.toaria = function() { console.log() - $http.post("http://raspberrypi:6800/jsonrpc", '{"jsonrpc": "2.0", "method": "aria2.addUri","id": "QXJpYU5nXzE2MzgwMjA0NDFfMC42MzAwMTQ5MDIyNTY4NzY2","params": [["https://oloking.xyz/download/'+n.$path+'"],{}]}', + $http.post("https://raspberrypi:6800/jsonrpc", '{"jsonrpc": "2.0", "method": "aria2.addUri","id": "QXJpYU5nXzE2MzgwMjA0NDFfMC42MzAwMTQ5MDIyNTY4NzY2","params": [["https://oloking.xyz/download/'+n.$path+'"],{}]}', { transformRequest: [] }) From 3c7a4fc2c00498d52638aabcdb35bf63945fbd48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=A4=E7=8B=90=E5=86=B2?= Date: Sun, 28 Jul 2024 14:24:52 +0800 Subject: [PATCH 26/26] Update server_http.go --- server/server_http.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/server/server_http.go b/server/server_http.go index 229c51705..3cdf2d3b9 100644 --- a/server/server_http.go +++ b/server/server_http.go @@ -9,7 +9,7 @@ import ( ) func (s *Server) webHandle(w http.ResponseWriter, r *http.Request) { - //handle realtime client library + // serve realtime client library if r.URL.Path == "/js/velox.js" { velox.JS.ServeHTTP(w, r) return @@ -18,32 +18,42 @@ func (s *Server) webHandle(w http.ResponseWriter, r *http.Request) { s.rssh.ServeHTTP(w, r) return } - //handle realtime client connections + // serve realtime client connection if r.URL.Path == "/sync" { conn, err := velox.Sync(&s.state, w, r) if err != nil { log.Printf("sync failed: %s", err) return } + + // use mutex to protect access to state.Users + s.state.Lock() s.state.Users[conn.ID()] = r.RemoteAddr s.state.Push() + s.state.Unlock() + conn.Wait() + + // use mutex to protect access to state.Users + s.state.Lock() delete(s.state.Users, conn.ID()) s.state.Push() + s.state.Unlock() + return } - //search + // search if strings.HasPrefix(r.URL.Path, "/search") { s.scraperh.ServeHTTP(w, r) return } - //api call + // API calls if strings.HasPrefix(r.URL.Path, "/api/") { w.Header().Set("Access-Control-Allow-Headers", "authorization") s.restAPIhandle(w, r) return } - //no match, assume static file + // no matching path, assume static file s.files.ServeHTTP(w, r) }