mirror of
https://github.com/teacat/chaturbate-dvr.git
synced 2025-10-29 16:59:59 +00:00
commit
39bec77ad4
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
./video
|
||||
11
Dockerfile
Normal file
11
Dockerfile
Normal file
@ -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" ]
|
||||
9
docker-compose.yml
Normal file
9
docker-compose.yml
Normal file
@ -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
|
||||
23
main.go
23
main.go
@ -26,15 +26,15 @@ 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
|
||||
|
||||
// segmentIndex is current stored segment index.
|
||||
var segmentIndex int
|
||||
|
||||
// path save video
|
||||
const savePath = "video"
|
||||
|
||||
//
|
||||
var (
|
||||
errInternal = errors.New("err")
|
||||
@ -131,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)
|
||||
@ -199,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
|
||||
@ -216,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++
|
||||
}
|
||||
@ -235,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)
|
||||
}
|
||||
@ -264,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")) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user