From cff53125bcae583c40dfc316c123ebe8d50b6073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9da=20HAMADI?= Date: Sat, 23 Apr 2022 18:22:17 +0200 Subject: [PATCH 1/4] lastCheckOnline var unused --- main.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/main.go b/main.go index f2cffdb..956d5d8 100644 --- a/main.go +++ b/main.go @@ -26,9 +26,6 @@ const chaturbateURL = "https://chaturbate.com/" // retriesAfterOnlined tells the retries for stream when disconnected but not really offlined. var retriesAfterOnlined = 0 -// lastCheckOnline logs the last check time. -var lastCheckOnline = time.Now() - // bucket stores the used segment to prevent fetched the duplicates. var bucket []string From 0dca62a97a795caa344dc13545f98bed20162d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9da=20HAMADI?= Date: Sat, 23 Apr 2022 19:15:39 +0200 Subject: [PATCH 2/4] save video in path --- main.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 956d5d8..2be92ff 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,9 @@ var bucket []string // segmentIndex is current stored segment index. var segmentIndex int +// path save video +const savePath = "video" + // var ( errInternal = errors.New("err") @@ -128,9 +131,9 @@ func capture(username string) { // Get the best resolution m3u8 by parsing the HLS source table. m3u8Source := parseHLSSource(hlsSource, baseURL) // Create the master video file. - masterFile, _ := os.OpenFile(filename+".ts", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0777) + masterFile, _ := os.OpenFile("./"+savePath+"/"+filename+".ts", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0777) // - log.Printf("the video will be saved as \"%s\".", filename+".ts") + log.Printf("the video will be saved as \"./"+savePath+"/%s\".", filename+".ts") go combineSegment(masterFile, filename) watchStream(m3u8Source, username, masterFile, filename, baseURL) @@ -196,7 +199,7 @@ func combineSegment(master *os.File, filename string) { continue } - if !pathx.Exists(fmt.Sprintf("%s~%d.ts", filename, index)) { + if !pathx.Exists(fmt.Sprintf("./%s/%s~%d.ts", savePath, filename, index)) { if retry >= 5 { index++ retry = 0 @@ -213,11 +216,11 @@ func combineSegment(master *os.File, filename string) { retry = 0 } // - b, _ := ioutil.ReadFile(fmt.Sprintf("%s~%d.ts", filename, index)) + b, _ := ioutil.ReadFile(fmt.Sprintf("./%s/%s~%d.ts", savePath, filename, index)) master.Write(b) log.Printf("inserting %d segment to the master file. (total: %d)", index, segmentIndex) // - os.Remove(fmt.Sprintf("%s~%d.ts", filename, index)) + os.Remove(fmt.Sprintf("./%s/%s~%d.ts", savePath, filename, index)) // index++ } @@ -232,7 +235,7 @@ func fetchSegment(master *os.File, segment *m3u8.MediaSegment, baseURL string, f return } // - f, err := os.OpenFile(fmt.Sprintf("%s~%d.ts", filename, index), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0777) + f, err := os.OpenFile(fmt.Sprintf("./%s/%s~%d.ts", savePath, filename, index), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0777) if err != nil { panic(err) } @@ -261,6 +264,11 @@ func endpoint(c *cli.Context) error { fmt.Println("Y8888D' YP 88 YD") fmt.Println("---") + // Mkdir video folder + if _, err := os.Stat("./" + savePath); os.IsNotExist(err) { + os.Mkdir("./"+savePath, 0777) + } + for { // Capture the stream if the user is currently online. if getOnlineStatus(c.String("username")) { From 3e0358bf2178f75c6b333d22e1adae6083f6d468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9da=20HAMADI?= Date: Sat, 23 Apr 2022 19:16:49 +0200 Subject: [PATCH 3/4] Add Dockerfile Add docker-compose.yml --- Dockerfile | 11 +++++++++++ docker-compose.yml | 9 +++++++++ 2 files changed, 20 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e6dee2b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:latest + +WORKDIR /usr/src/app + +COPY go.mod go.sum ./ +RUN go mod download && go mod verify + +COPY . . +RUN go build + +CMD [ "sh", "-c", "./chaturbate-dvr -u $USERNAME" ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..721b562 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +version: "3.0" + +services: + chaturbate-dvr: + build: . + environment: + - USERNAME=my_lovely_channel_name + volumes: + - ./video/my_lovely_channel_name:/usr/src/app/video \ No newline at end of file From 02e868274fc3dd919d406284676fb7ce3a58a4e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9da=20HAMADI?= Date: Sat, 23 Apr 2022 19:17:39 +0200 Subject: [PATCH 4/4] Exclude ./video path in .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2cf0a69 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +./video \ No newline at end of file