updated
This commit is contained in:
parent
28023bfd3c
commit
337045befc
6
go.mod
6
go.mod
@ -7,9 +7,3 @@ require (
|
|||||||
github.com/gorilla/websocket v1.5.3
|
github.com/gorilla/websocket v1.5.3
|
||||||
github.com/grafov/m3u8 v0.12.1
|
github.com/grafov/m3u8 v0.12.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/PuerkitoBio/goquery v1.10.3 // indirect
|
|
||||||
github.com/andybalholm/cascadia v1.3.3 // indirect
|
|
||||||
golang.org/x/net v0.39.0 // indirect
|
|
||||||
)
|
|
||||||
|
|||||||
71
go.sum
71
go.sum
@ -1,77 +1,6 @@
|
|||||||
github.com/PuerkitoBio/goquery v1.10.3 h1:pFYcNSqHxBD06Fpj/KsbStFRsgRATgnf3LeXiUkhzPo=
|
|
||||||
github.com/PuerkitoBio/goquery v1.10.3/go.mod h1:tMUX0zDMHXYlAQk6p35XxQMqMweEKB7iK7iLNd4RH4Y=
|
|
||||||
github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=
|
|
||||||
github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA=
|
|
||||||
github.com/gofrs/uuid/v5 v5.3.2 h1:2jfO8j3XgSwlz/wHqemAEugfnTlikAYHhnqQ8Xh4fE0=
|
github.com/gofrs/uuid/v5 v5.3.2 h1:2jfO8j3XgSwlz/wHqemAEugfnTlikAYHhnqQ8Xh4fE0=
|
||||||
github.com/gofrs/uuid/v5 v5.3.2/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
|
github.com/gofrs/uuid/v5 v5.3.2/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
|
||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
|
||||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/grafov/m3u8 v0.12.1 h1:DuP1uA1kvRRmGNAZ0m+ObLv1dvrfNO0TPx0c/enNk0s=
|
github.com/grafov/m3u8 v0.12.1 h1:DuP1uA1kvRRmGNAZ0m+ObLv1dvrfNO0TPx0c/enNk0s=
|
||||||
github.com/grafov/m3u8 v0.12.1/go.mod h1:nqzOkfBiZJENr52zTVd/Dcl03yzphIMbJqkXGu+u080=
|
github.com/grafov/m3u8 v0.12.1/go.mod h1:nqzOkfBiZJENr52zTVd/Dcl03yzphIMbJqkXGu+u080=
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
|
||||||
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
|
||||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
|
||||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
|
||||||
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
|
||||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
|
||||||
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
|
||||||
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
|
||||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
|
||||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
|
||||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
|
||||||
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
|
||||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
|
||||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
|
||||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
|
||||||
golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY=
|
|
||||||
golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
|
||||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
|
||||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
|
||||||
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
||||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
||||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
||||||
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
|
||||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
|
||||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
|
||||||
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
|
|
||||||
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
|
||||||
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
|
|
||||||
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
|
||||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
|
||||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
|
||||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
|
||||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
|
||||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
|
||||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
|
||||||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
|
||||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
|
|||||||
805
main.go
805
main.go
@ -1,15 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -18,139 +15,179 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/PuerkitoBio/goquery"
|
|
||||||
"github.com/grafov/m3u8"
|
"github.com/grafov/m3u8"
|
||||||
)
|
)
|
||||||
|
|
||||||
/* ───────────────────────────────
|
|
||||||
Gemeinsame Typen & Utilities
|
|
||||||
─────────────────────────────── */
|
|
||||||
|
|
||||||
var roomDossierRegexp = regexp.MustCompile(`window\.initialRoomDossier = "(.*?)"`)
|
var roomDossierRegexp = regexp.MustCompile(`window\.initialRoomDossier = "(.*?)"`)
|
||||||
|
|
||||||
type Status int
|
// HTTPClient kapselt http.Client + Header/Cookies (wie internal.Req im DVR)
|
||||||
|
type HTTPClient struct {
|
||||||
const (
|
client *http.Client
|
||||||
StatusUnknown Status = iota
|
userAgent string
|
||||||
StatusPublic
|
|
||||||
StatusPrivate
|
|
||||||
StatusOffline
|
|
||||||
StatusNotExist
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s Status) String() string {
|
|
||||||
switch s {
|
|
||||||
case StatusPublic:
|
|
||||||
return "PUBLIC"
|
|
||||||
case StatusPrivate:
|
|
||||||
return "PRIVATE"
|
|
||||||
case StatusOffline:
|
|
||||||
return "OFFLINE"
|
|
||||||
case StatusNotExist:
|
|
||||||
return "NOTEXIST"
|
|
||||||
default:
|
|
||||||
return "UNKNOWN"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ───────────────────────────────
|
// gemeinsamen HTTP-Client erzeugen
|
||||||
main
|
func NewHTTPClient(userAgent string) *HTTPClient {
|
||||||
─────────────────────────────── */
|
if userAgent == "" {
|
||||||
|
// Default, falls kein UA übergeben wird
|
||||||
|
userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
|
||||||
|
}
|
||||||
|
|
||||||
|
return &HTTPClient{
|
||||||
|
client: &http.Client{
|
||||||
|
Timeout: 10 * time.Second,
|
||||||
|
},
|
||||||
|
userAgent: userAgent,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Request-Erstellung mit User-Agent + Cookies
|
||||||
|
func (h *HTTPClient) NewRequest(ctx context.Context, method, url, cookieStr string) (*http.Request, error) {
|
||||||
|
req, err := http.NewRequestWithContext(ctx, method, url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Basis-Header, die immer gesetzt werden
|
||||||
|
if h.userAgent != "" {
|
||||||
|
req.Header.Set("User-Agent", h.userAgent)
|
||||||
|
} else {
|
||||||
|
req.Header.Set("User-Agent", "Mozilla/5.0")
|
||||||
|
}
|
||||||
|
req.Header.Set("Accept", "*/*")
|
||||||
|
|
||||||
|
// Cookie-String wie "name=value; foo=bar"
|
||||||
|
addCookiesFromString(req, cookieStr)
|
||||||
|
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Seite laden + einfache Erkennung von Schutzseiten (Cloudflare / Age-Gate)
|
||||||
|
func (h *HTTPClient) FetchPage(ctx context.Context, url, cookieStr string) (string, error) {
|
||||||
|
req, err := h.NewRequest(ctx, http.MethodGet, url, cookieStr)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
data, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
body := string(data)
|
||||||
|
|
||||||
|
// Etwas aussagekräftigere Fehler als nur "room dossier nicht gefunden"
|
||||||
|
if strings.Contains(body, "<title>Just a moment...</title>") {
|
||||||
|
return "", errors.New("Schutzseite von Cloudflare erhalten (\"Just a moment...\") – kein Room-HTML")
|
||||||
|
}
|
||||||
|
if strings.Contains(body, "Verify your age") {
|
||||||
|
return "", errors.New("Altersverifikationsseite erhalten – kein Room-HTML")
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return "", fmt.Errorf("HTTP %d beim Laden von %s", resp.StatusCode, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
return body, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- main ---
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
fmt.Println("Verwendung:")
|
fmt.Println("Verwendung: recorder.exe [--http-cookie \"<Cookie>\"] [--user-agent \"<UA>\"] [--domain \"https://chaturbate.com/\"] <Chaturbate-URL oder Benutzername> [best] [-o <Pfad/zieldatei.ts>] [-f]")
|
||||||
fmt.Println(" recorder.exe <Chaturbate-URL oder Benutzername> [-o <zieldatei.ts>]")
|
os.Exit(1)
|
||||||
fmt.Println(" recorder.exe <MyFreeCams-URL wie https://www.myfreecams.com/#name> [-o <zieldatei.mp4>]")
|
}
|
||||||
fmt.Println(" recorder.exe --site mfc <username> [-o <zieldatei.mp4>]")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// optionales -o
|
var (
|
||||||
outputPathArg := ""
|
httpCookie string
|
||||||
site := "" // "", "mfc"
|
outputPath string
|
||||||
args := os.Args[1:]
|
urlArg string
|
||||||
clean := make([]string, 0, len(args))
|
userAgent string
|
||||||
for i := 0; i < len(args); i++ {
|
domain = "https://chaturbate.com/" // Standard wie beim DVR
|
||||||
if args[i] == "-o" && i+1 < len(args) {
|
)
|
||||||
outputPathArg = args[i+1]
|
|
||||||
i++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if args[i] == "--site" && i+1 < len(args) {
|
|
||||||
site = strings.ToLower(args[i+1])
|
|
||||||
i++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
clean = append(clean, args[i])
|
|
||||||
}
|
|
||||||
if len(clean) == 0 {
|
|
||||||
fmt.Println("Fehlendes Ziel (Benutzername oder URL).")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
arg := clean[0]
|
|
||||||
|
|
||||||
// Dispatch: MyFreeCams?
|
args := os.Args[1:]
|
||||||
if site == "mfc" || strings.Contains(arg, "myfreecams.com/#") {
|
|
||||||
username := extractMFCUsername(arg)
|
|
||||||
if username == "" {
|
|
||||||
fmt.Println("Konnte MFC-Username nicht erkennen.")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
if err := runMFC(username, outputPathArg); err != nil {
|
|
||||||
fmt.Println("❌ MFC-Fehler:", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sonst: Chaturbate (bestehender Flow) :contentReference[oaicite:1]{index=1}
|
for i := 0; i < len(args); i++ {
|
||||||
username := extractCBUsername(arg)
|
a := args[i]
|
||||||
outputPath := outputPathArg
|
|
||||||
if outputPath == "" {
|
|
||||||
outputPath = fmt.Sprintf("%s_%s.ts", username, time.Now().Format("20060102_150405"))
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx := context.Background()
|
switch a {
|
||||||
body, err := fetchPage("https://chaturbate.com/" + username)
|
case "--http-cookie":
|
||||||
if err != nil {
|
if i+1 >= len(args) {
|
||||||
fmt.Println("❌ Fehler beim Laden der Seite:", err)
|
fmt.Println("Fehlender Wert nach --http-cookie")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
httpCookie = args[i+1]
|
||||||
|
i++
|
||||||
|
|
||||||
hlsURL, err := ParseStream(body)
|
case "--user-agent":
|
||||||
if err != nil {
|
if i+1 >= len(args) {
|
||||||
fmt.Println("❌ Stream nicht gefunden oder offline:", err)
|
fmt.Println("Fehlender Wert nach --user-agent")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
userAgent = args[i+1]
|
||||||
|
i++
|
||||||
|
|
||||||
playlist, err := FetchPlaylist(ctx, hlsURL)
|
case "--domain":
|
||||||
if err != nil {
|
if i+1 >= len(args) {
|
||||||
fmt.Println("❌ Fehler beim Abrufen der Playlist:", err)
|
fmt.Println("Fehlender Wert nach --domain")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
domain = args[i+1]
|
||||||
|
i++
|
||||||
|
|
||||||
file, err := os.Create(outputPath)
|
case "-o":
|
||||||
if err != nil {
|
if i+1 >= len(args) {
|
||||||
fmt.Println("❌ Datei konnte nicht erstellt werden:", err)
|
fmt.Println("Fehlender Wert nach -o")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
defer file.Close()
|
outputPath = args[i+1]
|
||||||
|
i++
|
||||||
|
|
||||||
fmt.Println("📡 Aufnahme gestartet:", outputPath)
|
case "-f":
|
||||||
|
// nur für Kompatibilität, wird ignoriert
|
||||||
|
|
||||||
err = playlist.WatchSegments(ctx, func(b []byte, _ float64) error {
|
case "best":
|
||||||
_, err := file.Write(b)
|
// wird ignoriert, wir wählen sowieso beste Qualität
|
||||||
if err != nil {
|
|
||||||
fmt.Println("❌ Fehler beim Schreiben in Datei:", err)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
default:
|
||||||
fmt.Println("❌ Aufnahmefehler:", err)
|
// erste „normale“ Angabe ist die URL / der Benutzername
|
||||||
}
|
if urlArg == "" {
|
||||||
|
urlArg = a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if urlArg == "" {
|
||||||
|
fmt.Println("Keine URL / kein Benutzername angegeben.")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
username := extractUsername(urlArg)
|
||||||
|
username = strings.Trim(username, "/\\")
|
||||||
|
|
||||||
|
if outputPath == "" {
|
||||||
|
outputPath = fmt.Sprintf("%s_%s.ts", username, time.Now().Format("20060102_150405"))
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
// HIER User-Agent an den Client durchreichen
|
||||||
|
hc := NewHTTPClient(userAgent)
|
||||||
|
|
||||||
|
if err := RecordStream(ctx, hc, domain, username, outputPath, httpCookie); err != nil {
|
||||||
|
fmt.Println("❌ Aufnahmefehler:", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TS -> MP4 remuxen (wie gehabt)
|
||||||
mp4Out := outputPath
|
mp4Out := outputPath
|
||||||
ext := filepath.Ext(outputPath)
|
ext := filepath.Ext(outputPath)
|
||||||
if ext != ".mp4" {
|
if ext != ".mp4" {
|
||||||
@ -173,427 +210,118 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ───────────────────────────────
|
// --- DVR-ähnlicher Recorder-Ablauf ---
|
||||||
MyFreeCams (Port von myfreecams.py)
|
// Entspricht grob dem RecordStream aus dem Channel-Snippet:
|
||||||
─────────────────────────────── */
|
func RecordStream(
|
||||||
|
ctx context.Context,
|
||||||
|
hc *HTTPClient,
|
||||||
|
domain string,
|
||||||
|
username string,
|
||||||
|
outputPath string,
|
||||||
|
httpCookie string,
|
||||||
|
) error {
|
||||||
|
// 1) Seite laden
|
||||||
|
// Domain sauber zusammenbauen (mit/ohne Slash)
|
||||||
|
base := strings.TrimRight(domain, "/")
|
||||||
|
pageURL := base + "/" + username
|
||||||
|
|
||||||
type MyFreeCams struct {
|
body, err := hc.FetchPage(ctx, pageURL, httpCookie)
|
||||||
Username string
|
|
||||||
Attrs map[string]string
|
|
||||||
VideoURL string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMyFreeCams(username string) *MyFreeCams {
|
// 2) HLS-URL aus roomDossier extrahieren (wie DVR.ParseStream)
|
||||||
return &MyFreeCams{
|
hlsURL, err := ParseStream(body)
|
||||||
Username: username,
|
|
||||||
Attrs: map[string]string{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MyFreeCams) GetWebsiteURL() string {
|
|
||||||
return "https://www.myfreecams.com/#" + m.Username
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MyFreeCams) GetVideoURL(refresh bool) (string, error) {
|
|
||||||
if !refresh && m.VideoURL != "" {
|
|
||||||
return m.VideoURL, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prüfen, ob alle benötigten Attribute vorhanden sind
|
|
||||||
if _, ok := m.Attrs["data-cam-preview-model-id-value"]; !ok {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
sid := m.Attrs["data-cam-preview-server-id-value"]
|
|
||||||
midBase := m.Attrs["data-cam-preview-model-id-value"]
|
|
||||||
isWzobs := strings.ToLower(m.Attrs["data-cam-preview-is-wzobs-value"]) == "true"
|
|
||||||
|
|
||||||
midInt, err := strconv.Atoi(midBase)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("model-id parse error: %w", err)
|
return fmt.Errorf("stream-parsing: %w", err)
|
||||||
}
|
|
||||||
mid := 100000000 + midInt
|
|
||||||
a := ""
|
|
||||||
if isWzobs {
|
|
||||||
a = "a_"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
playlistURL := fmt.Sprintf("https://previews.myfreecams.com/hls/NxServer/%s/ngrp:mfc_%s%d.f4v_mobile_mhp1080_previewurl/playlist.m3u8", sid, a, mid)
|
// 3) Playlist holen (wie stream.GetPlaylist im DVR)
|
||||||
|
playlist, err := FetchPlaylist(ctx, hc, hlsURL, httpCookie)
|
||||||
// Validieren (HTTP 200) & ggf. auf gewünschte Auflösung verlinken
|
|
||||||
u, err := getWantedResolutionPlaylist(playlistURL)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return fmt.Errorf("playlist abrufen: %w", err)
|
||||||
}
|
}
|
||||||
m.VideoURL = u
|
fmt.Printf("Stream-Qualität: %dp @ %dfps\n", playlist.Resolution, playlist.Framerate)
|
||||||
return m.VideoURL, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MyFreeCams) GetStatus() (Status, error) {
|
// 4) Datei öffnen
|
||||||
// 1) share-Seite prüfen (existiert/nicht existiert)
|
file, err := os.Create(outputPath)
|
||||||
shareURL := "https://share.myfreecams.com/" + m.Username
|
|
||||||
resp, err := http.Get(shareURL)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return StatusUnknown, err
|
return fmt.Errorf("datei erstellen: %w", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() {
|
||||||
|
_ = file.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
if resp.StatusCode == 404 {
|
fmt.Println("📡 Aufnahme gestartet:", outputPath)
|
||||||
return StatusNotExist, nil
|
|
||||||
}
|
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
return StatusUnknown, fmt.Errorf("HTTP %d", resp.StatusCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
// wir brauchen sowohl Bytes (für Suche) als auch Reader (für HTML)
|
// 5) Segmente „watchen“ – analog zu WatchSegments + HandleSegment im DVR
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
err = playlist.WatchSegments(ctx, hc, httpCookie, func(b []byte, duration float64) error {
|
||||||
if err != nil {
|
// Hier wäre im DVR ch.HandleSegment – bei dir einfach in eine Datei schreiben
|
||||||
return StatusUnknown, err
|
if _, err := file.Write(b); err != nil {
|
||||||
}
|
return fmt.Errorf("schreibe segment: %w", err)
|
||||||
|
|
||||||
// 2) „tracking.php?“ suchen und prüfen, ob model_id vorhanden ist
|
|
||||||
start := bytes.Index(bodyBytes, []byte("https://www.myfreecams.com/php/tracking.php?"))
|
|
||||||
if start == -1 {
|
|
||||||
// ohne tracking Parameter -> behandeln wie nicht existent
|
|
||||||
return StatusNotExist, nil
|
|
||||||
}
|
|
||||||
end := bytes.IndexByte(bodyBytes[start:], '"')
|
|
||||||
if end == -1 {
|
|
||||||
return StatusUnknown, errors.New("tracking url parse failed")
|
|
||||||
}
|
|
||||||
raw := string(bodyBytes[start : start+end])
|
|
||||||
u, err := url.Parse(raw)
|
|
||||||
if err != nil {
|
|
||||||
return StatusUnknown, fmt.Errorf("tracking url invalid: %w", err)
|
|
||||||
}
|
|
||||||
qs := u.Query()
|
|
||||||
if qs.Get("model_id") == "" {
|
|
||||||
return StatusNotExist, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3) HTML parsen und <div class="campreview" ...> Attribute auslesen
|
|
||||||
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(bodyBytes))
|
|
||||||
if err != nil {
|
|
||||||
return StatusUnknown, err
|
|
||||||
}
|
|
||||||
|
|
||||||
params := doc.Find(".campreview").First()
|
|
||||||
if params.Length() == 0 {
|
|
||||||
// keine campreview -> offline
|
|
||||||
return StatusOffline, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
attrs := map[string]string{}
|
|
||||||
params.Each(func(_ int, s *goquery.Selection) {
|
|
||||||
for _, a := range []string{
|
|
||||||
"data-cam-preview-server-id-value",
|
|
||||||
"data-cam-preview-model-id-value",
|
|
||||||
"data-cam-preview-is-wzobs-value",
|
|
||||||
} {
|
|
||||||
if v, ok := s.Attr(a); ok {
|
|
||||||
attrs[a] = v
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// Könntest hier z.B. auch Dauer/Größe loggen, wenn du möchtest
|
||||||
|
_ = duration // aktuell unbenutzt
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
m.Attrs = attrs
|
|
||||||
|
|
||||||
// 4) Versuchen, VideoURL (Preview-HLS) zu ermitteln
|
|
||||||
uStr, err := m.GetVideoURL(true)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return StatusUnknown, err
|
return fmt.Errorf("watch segments: %w", err)
|
||||||
}
|
}
|
||||||
if uStr != "" {
|
|
||||||
return StatusPublic, nil
|
return nil
|
||||||
}
|
|
||||||
// campreview vorhanden, aber keine playable url -> „PRIVATE“
|
|
||||||
return StatusPrivate, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func runMFC(username string, outArg string) error {
|
// --- helper ---
|
||||||
mfc := NewMyFreeCams(username)
|
func extractUsername(input string) string {
|
||||||
st, err := mfc.GetStatus()
|
input = strings.TrimSpace(input)
|
||||||
if err != nil {
|
input = strings.TrimPrefix(input, "https://")
|
||||||
return err
|
input = strings.TrimPrefix(input, "http://")
|
||||||
}
|
input = strings.TrimPrefix(input, "www.")
|
||||||
fmt.Println("MFC Status:", st)
|
if strings.HasPrefix(input, "chaturbate.com/") {
|
||||||
|
input = strings.TrimPrefix(input, "chaturbate.com/")
|
||||||
|
}
|
||||||
|
|
||||||
if st != StatusPublic {
|
// alles nach dem ersten Slash abschneiden (Pfadteile, /, etc.)
|
||||||
return fmt.Errorf("Stream ist nicht öffentlich (Status: %s)", st)
|
if idx := strings.IndexAny(input, "/?#"); idx != -1 {
|
||||||
}
|
input = input[:idx]
|
||||||
m3u8URL, err := mfc.GetVideoURL(false)
|
}
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if m3u8URL == "" {
|
|
||||||
return errors.New("keine m3u8 URL gefunden")
|
|
||||||
}
|
|
||||||
|
|
||||||
return handleM3U8Mode(m3u8URL, outArg)
|
// zur Sicherheit evtl. übrig gebliebene Slash/Backslash trimmen
|
||||||
|
return strings.Trim(input, "/\\")
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ───────────────────────────────
|
|
||||||
Gemeinsame HLS/M3U8-Helper
|
|
||||||
─────────────────────────────── */
|
|
||||||
|
|
||||||
func getWantedResolutionPlaylist(playlistURL string) (string, error) {
|
// Cookie-Hilfsfunktion (wie ParseCookies + AddCookie im DVR)
|
||||||
// Holt eine URL; wenn MASTER, wähle beste Variante; wenn MEDIA, gib die URL zurück.
|
func addCookiesFromString(req *http.Request, cookieStr string) {
|
||||||
resp, err := http.Get(playlistURL)
|
if cookieStr == "" {
|
||||||
if err != nil {
|
return
|
||||||
return "", err
|
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
pairs := strings.Split(cookieStr, ";")
|
||||||
if resp.StatusCode != 200 {
|
for _, pair := range pairs {
|
||||||
return "", fmt.Errorf("HTTP %d beim Abruf der m3u8", resp.StatusCode)
|
parts := strings.SplitN(strings.TrimSpace(pair), "=", 2)
|
||||||
}
|
if len(parts) != 2 {
|
||||||
|
|
||||||
playlist, listType, err := m3u8.DecodeFrom(resp.Body, true)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("m3u8 parse: %w", err)
|
|
||||||
}
|
|
||||||
if listType == m3u8.MEDIA {
|
|
||||||
return playlistURL, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
master := playlist.(*m3u8.MasterPlaylist)
|
|
||||||
var bestURI string
|
|
||||||
var bestWidth int
|
|
||||||
var bestFramerate float64
|
|
||||||
|
|
||||||
for _, v := range master.Variants {
|
|
||||||
if v == nil {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Resolution kommt als "WxH" – uns ist Höhe egal, nehmen die zweite Zahl als "Breite" (wie in deiner CB-Logik gemacht).
|
name := strings.TrimSpace(parts[0])
|
||||||
w := 0
|
value := strings.TrimSpace(parts[1])
|
||||||
if v.Resolution != "" {
|
if name == "" {
|
||||||
parts := strings.Split(v.Resolution, "x")
|
continue
|
||||||
if len(parts) == 2 {
|
|
||||||
if ww, err := strconv.Atoi(parts[1]); err == nil {
|
|
||||||
w = ww
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fr := 30.0
|
|
||||||
if v.FrameRate > 0 {
|
|
||||||
fr = v.FrameRate
|
|
||||||
} else if strings.Contains(v.Name, "FPS:60") {
|
|
||||||
fr = 60
|
|
||||||
}
|
|
||||||
if w > bestWidth || (w == bestWidth && fr > bestFramerate) {
|
|
||||||
bestWidth = w
|
|
||||||
bestFramerate = fr
|
|
||||||
bestURI = v.URI
|
|
||||||
}
|
}
|
||||||
|
req.AddCookie(&http.Cookie{
|
||||||
|
Name: name,
|
||||||
|
Value: value,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
if bestURI == "" {
|
|
||||||
return "", errors.New("Master-Playlist ohne gültige Varianten")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Absolutieren
|
|
||||||
root := playlistURL[:strings.LastIndex(playlistURL, "/")+1]
|
|
||||||
if strings.HasPrefix(bestURI, "http://") || strings.HasPrefix(bestURI, "https://") {
|
|
||||||
return bestURI, nil
|
|
||||||
}
|
|
||||||
return root + bestURI, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleM3U8Mode(m3u8URL, outArg string) error {
|
// ParseStream entspricht der DVR-Variante (roomDossier → hls_source)
|
||||||
// Minimalvalidierung
|
func ParseStream(html string) (string, error) {
|
||||||
u, err := url.Parse(m3u8URL)
|
|
||||||
if err != nil || (u.Scheme != "http" && u.Scheme != "https") {
|
|
||||||
return fmt.Errorf("ungültige URL: %q", m3u8URL)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Erreichbarkeit kurz prüfen
|
|
||||||
resp, err := http.Get(m3u8URL)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Abruf fehlgeschlagen: %w", err)
|
|
||||||
}
|
|
||||||
io.Copy(io.Discard, resp.Body)
|
|
||||||
resp.Body.Close()
|
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
return fmt.Errorf("HTTP %d beim Abruf der m3u8", resp.StatusCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ausgabedatei bestimmen
|
|
||||||
outFile := strings.TrimSpace(outArg)
|
|
||||||
if outFile == "" {
|
|
||||||
def := "mfc_" + time.Now().Format("20060102_150405") + ".mp4"
|
|
||||||
fmt.Printf("Name der MP4-Datei (Enter für %s): ", def)
|
|
||||||
if s := readLine(); s != "" {
|
|
||||||
outFile = s
|
|
||||||
} else {
|
|
||||||
outFile = def
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Überschreiben?
|
|
||||||
if fileExists(outFile) {
|
|
||||||
fmt.Print("Die Datei existiert bereits. Überschreiben? [y/N] ")
|
|
||||||
a := strings.ToLower(strings.TrimSpace(readLine()))
|
|
||||||
if a != "y" && a != "j" {
|
|
||||||
return errors.New("abgebrochen")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── 1) Live-fähiges, fragmentiertes MP4 schreiben (copy) ──────────
|
|
||||||
// WICHTIG: -bsf:a aac_adtstoasc setzen + explizit mappen
|
|
||||||
fmt.Println("📦 Starte Download mit ffmpeg:", outFile)
|
|
||||||
cmd := exec.Command(
|
|
||||||
"ffmpeg",
|
|
||||||
"-nostdin", "-y",
|
|
||||||
"-fflags", "+genpts",
|
|
||||||
"-i", m3u8URL,
|
|
||||||
"-map", "0:v:0", "-map", "0:a:0?",
|
|
||||||
"-c:v", "copy",
|
|
||||||
"-c:a", "copy",
|
|
||||||
"-bsf:a", "aac_adtstoasc",
|
|
||||||
"-movflags", "+frag_keyframe+empty_moov+default_base_moof",
|
|
||||||
"-f", "mp4",
|
|
||||||
outFile,
|
|
||||||
)
|
|
||||||
cmd.Stdin = os.Stdin
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
return fmt.Errorf("ffmpeg fehlgeschlagen: %w", err)
|
|
||||||
}
|
|
||||||
fmt.Println("✅ Download abgeschlossen:", outFile)
|
|
||||||
|
|
||||||
// ── 2) Finales Remux in +faststart (für blitzschnelles Öffnen) ────
|
|
||||||
fmt.Println("🔁 Remux in finales MP4 (faststart)…")
|
|
||||||
if err := remuxMP4Faststart(outFile); err != nil {
|
|
||||||
fmt.Println("⚠️ Remux-Fehler:", err)
|
|
||||||
} else {
|
|
||||||
fmt.Println("✅ Remux abgeschlossen:", outFile)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// remuxMP4Faststart remuxt ein (ggf. fragmentiertes) MP4 in finales MP4 mit +faststart.
|
|
||||||
// 1. Versuch: copy/copy. Wenn danach kein Audio vorhanden ist, 2. Versuch mit AAC-Reencode.
|
|
||||||
func remuxMP4Faststart(inPath string) error {
|
|
||||||
base := strings.TrimSuffix(inPath, filepath.Ext(inPath))
|
|
||||||
tmp := base + ".remux.mp4"
|
|
||||||
|
|
||||||
hadAudioBefore, _ := hasAudioTrack(inPath) // nur zur Info/Fallback
|
|
||||||
|
|
||||||
// 1) Copy-Remux
|
|
||||||
if err := runCmd("ffmpeg",
|
|
||||||
"-y",
|
|
||||||
"-i", inPath,
|
|
||||||
"-map", "0:v:0", "-map", "0:a:0?",
|
|
||||||
"-c:v", "copy",
|
|
||||||
"-c:a", "copy",
|
|
||||||
"-movflags", "+faststart",
|
|
||||||
tmp,
|
|
||||||
); err != nil {
|
|
||||||
return fmt.Errorf("ffmpeg remux (copy) fehlgeschlagen: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
hasAudioAfter, _ := hasAudioTrack(tmp)
|
|
||||||
if !hasAudioAfter && hadAudioBefore {
|
|
||||||
// 2) Fallback: remux mit Audio-Reencode (wem auch immer copy schiefging)
|
|
||||||
_ = os.Remove(tmp)
|
|
||||||
if err := runCmd("ffmpeg",
|
|
||||||
"-y",
|
|
||||||
"-i", inPath,
|
|
||||||
"-map", "0:v:0", "-map", "0:a:0?",
|
|
||||||
"-c:v", "copy",
|
|
||||||
"-c:a", "aac", "-b:a", "192k",
|
|
||||||
"-movflags", "+faststart",
|
|
||||||
tmp,
|
|
||||||
); err != nil {
|
|
||||||
return fmt.Errorf("ffmpeg remux (aac-fallback) fehlgeschlagen: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Original durch remuxtes ersetzen
|
|
||||||
if err := os.Remove(inPath); err != nil {
|
|
||||||
return fmt.Errorf("remux ok, aber konnte Original nicht entfernen: %w", err)
|
|
||||||
}
|
|
||||||
if err := os.Rename(tmp, inPath); err != nil {
|
|
||||||
return fmt.Errorf("remux ok, aber konnte Zieldatei nicht umbenennen: %w", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func runCmd(name string, args ...string) error {
|
|
||||||
cmd := exec.Command(name, args...)
|
|
||||||
cmd.Stdin = os.Stdin
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
return cmd.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
// hasAudioTrack prüft mit ffprobe, ob mind. ein Audiostream vorhanden ist.
|
|
||||||
func hasAudioTrack(path string) (bool, error) {
|
|
||||||
// ffprobe -v error -select_streams a -show_entries stream=index -of csv=p=0 <file>
|
|
||||||
out := &bytes.Buffer{}
|
|
||||||
cmd := exec.Command("ffprobe",
|
|
||||||
"-v", "error",
|
|
||||||
"-select_streams", "a",
|
|
||||||
"-show_entries", "stream=index",
|
|
||||||
"-of", "csv=p=0",
|
|
||||||
path,
|
|
||||||
)
|
|
||||||
cmd.Stdout = out
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
// Wenn irgendwas zurückkommt, gibt's Audio
|
|
||||||
return strings.TrimSpace(out.String()) != "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ───────────────────────────────
|
|
||||||
Chaturbate-Helpers (aus deiner Datei)
|
|
||||||
─────────────────────────────── */
|
|
||||||
|
|
||||||
func extractCBUsername(input string) string { // :contentReference[oaicite:2]{index=2}
|
|
||||||
input = strings.TrimPrefix(input, "https://")
|
|
||||||
input = strings.TrimPrefix(input, "http://")
|
|
||||||
input = strings.TrimPrefix(input, "www.")
|
|
||||||
if strings.HasPrefix(input, "chaturbate.com/") {
|
|
||||||
return strings.TrimPrefix(input, "chaturbate.com/")
|
|
||||||
}
|
|
||||||
return strings.TrimSpace(input)
|
|
||||||
}
|
|
||||||
|
|
||||||
func fetchPage(u string) (string, error) { // :contentReference[oaicite:3]{index=3}
|
|
||||||
client := http.Client{Timeout: 10 * time.Second}
|
|
||||||
req, err := http.NewRequest("GET", u, nil)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
req.Header.Set("User-Agent", "Mozilla/5.0")
|
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
return "", fmt.Errorf("HTTP %d: %s", resp.StatusCode, u)
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(data), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ParseStream(html string) (string, error) { // :contentReference[oaicite:4]{index=4}
|
|
||||||
matches := roomDossierRegexp.FindStringSubmatch(html)
|
matches := roomDossierRegexp.FindStringSubmatch(html)
|
||||||
if len(matches) < 2 {
|
if len(matches) == 0 {
|
||||||
return "", errors.New("room dossier nicht gefunden")
|
return "", errors.New("room dossier nicht gefunden")
|
||||||
}
|
}
|
||||||
encoded := matches[1]
|
|
||||||
|
|
||||||
decoded, err := strconv.Unquote(`"` + strings.ReplaceAll(encoded, `\\u`, `\u`) + `"`)
|
// DVR-Style Unicode-Decode
|
||||||
|
decoded, err := strconv.Unquote(
|
||||||
|
strings.Replace(strconv.Quote(matches[1]), `\\u`, `\u`, -1),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Unicode-decode failed: %w", err)
|
return "", fmt.Errorf("Unicode-decode failed: %w", err)
|
||||||
}
|
}
|
||||||
@ -610,19 +338,31 @@ func ParseStream(html string) (string, error) { // :contentReference[oaicite:4]{
|
|||||||
return rd.HLSSource, nil
|
return rd.HLSSource, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Playlist struct { // :contentReference[oaicite:5]{index=5}
|
// --- Playlist/WatchSegments wie gehabt ---
|
||||||
|
type Playlist struct {
|
||||||
PlaylistURL string
|
PlaylistURL string
|
||||||
RootURL string
|
RootURL string
|
||||||
Resolution int
|
Resolution int
|
||||||
Framerate int
|
Framerate int
|
||||||
}
|
}
|
||||||
|
|
||||||
func FetchPlaylist(ctx context.Context, hlsSource string) (*Playlist, error) { // :contentReference[oaicite:6]{index=6}
|
type Resolution struct {
|
||||||
|
Framerate map[int]string
|
||||||
|
Width int
|
||||||
|
}
|
||||||
|
|
||||||
|
// nimmt jetzt *HTTPClient entgegen
|
||||||
|
func FetchPlaylist(ctx context.Context, hc *HTTPClient, hlsSource, httpCookie string) (*Playlist, error) {
|
||||||
if hlsSource == "" {
|
if hlsSource == "" {
|
||||||
return nil, errors.New("HLS-URL leer")
|
return nil, errors.New("HLS-URL leer")
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := http.Get(hlsSource)
|
req, err := hc.NewRequest(ctx, http.MethodGet, hlsSource, httpCookie)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Fehler beim Erstellen der Playlist-Request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := hc.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Fehler beim Laden der Playlist: %w", err)
|
return nil, fmt.Errorf("Fehler beim Laden der Playlist: %w", err)
|
||||||
}
|
}
|
||||||
@ -678,10 +418,14 @@ func FetchPlaylist(ctx context.Context, hlsSource string) (*Playlist, error) { /
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Playlist) WatchSegments(ctx context.Context, handler func([]byte, float64) error) error { // :contentReference[oaicite:7]{index=7}
|
// nutzt ebenfalls *HTTPClient
|
||||||
|
func (p *Playlist) WatchSegments(
|
||||||
|
ctx context.Context,
|
||||||
|
hc *HTTPClient,
|
||||||
|
httpCookie string,
|
||||||
|
handler func([]byte, float64) error,
|
||||||
|
) error {
|
||||||
var lastSeq int64 = -1
|
var lastSeq int64 = -1
|
||||||
client := http.Client{Timeout: 10 * time.Second}
|
|
||||||
|
|
||||||
emptyRounds := 0
|
emptyRounds := 0
|
||||||
const maxEmptyRounds = 5
|
const maxEmptyRounds = 5
|
||||||
|
|
||||||
@ -692,7 +436,13 @@ func (p *Playlist) WatchSegments(ctx context.Context, handler func([]byte, float
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.Get(p.PlaylistURL)
|
// Playlist holen
|
||||||
|
req, err := hc.NewRequest(ctx, http.MethodGet, p.PlaylistURL, httpCookie)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Fehler beim Erstellen der Playlist-Request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := hc.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
emptyRounds++
|
emptyRounds++
|
||||||
if emptyRounds >= maxEmptyRounds {
|
if emptyRounds >= maxEmptyRounds {
|
||||||
@ -701,6 +451,7 @@ func (p *Playlist) WatchSegments(ctx context.Context, handler func([]byte, float
|
|||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
playlist, listType, err := m3u8.DecodeFrom(resp.Body, true)
|
playlist, listType, err := m3u8.DecodeFrom(resp.Body, true)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
|
||||||
@ -728,7 +479,13 @@ func (p *Playlist) WatchSegments(ctx context.Context, handler func([]byte, float
|
|||||||
newSegment = true
|
newSegment = true
|
||||||
|
|
||||||
segmentURL := p.RootURL + segment.URI
|
segmentURL := p.RootURL + segment.URI
|
||||||
segResp, err := client.Get(segmentURL)
|
|
||||||
|
segReq, err := hc.NewRequest(ctx, http.MethodGet, segmentURL, httpCookie)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
segResp, err := hc.client.Do(segReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -756,29 +513,3 @@ func (p *Playlist) WatchSegments(ctx context.Context, handler func([]byte, float
|
|||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ───────────────────────────────
|
|
||||||
Kleine Helper
|
|
||||||
─────────────────────────────── */
|
|
||||||
|
|
||||||
func extractMFCUsername(input string) string {
|
|
||||||
if strings.Contains(input, "myfreecams.com/#") {
|
|
||||||
i := strings.Index(input, "#")
|
|
||||||
if i >= 0 && i < len(input)-1 {
|
|
||||||
return strings.TrimSpace(input[i+1:])
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return strings.TrimSpace(input)
|
|
||||||
}
|
|
||||||
|
|
||||||
func readLine() string {
|
|
||||||
r := bufio.NewReader(os.Stdin)
|
|
||||||
s, _ := r.ReadString('\n')
|
|
||||||
return strings.TrimRight(s, "\r\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
func fileExists(path string) bool {
|
|
||||||
_, err := os.Stat(path)
|
|
||||||
return err == nil
|
|
||||||
}
|
|
||||||
|
|||||||
BIN
recorder.exe
BIN
recorder.exe
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user