add cookie support for membership streams - doesn't crash but don't have any memberships to test
This commit is contained in:
parent
0136bee3e7
commit
080a945d41
|
@ -10,6 +10,8 @@ retry_delay = "10s"
|
|||
|
||||
output_dir = "./videos/{{.Date.Format \"20060102\" }}/{{.Type}}/{{.Name}}-{{.ChannelID}}/"
|
||||
|
||||
youtube_cookies_file = ""
|
||||
|
||||
twitch_client_id = ""
|
||||
twitch_app_token = ""
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ type Config struct {
|
|||
TwitchClientID string `toml:"twitch_client_id"`
|
||||
TwitchAppToken string `toml:"twitch_app_token"`
|
||||
|
||||
YouTubeCookieFile string `toml:"youtube_cookies_file"`
|
||||
|
||||
MaxRetries int `toml:"max_retries"`
|
||||
RetryDelay string `toml:"retry_delay"`
|
||||
|
||||
|
|
|
@ -116,7 +116,12 @@ func download(channel Channel, outputDir string, try int) {
|
|||
var cmd *exec.Cmd
|
||||
|
||||
if channel.Type == "youtube" {
|
||||
cmd = exec.Command("yt-dlp", "-P", dir, "-o", "%(upload_date)s - %(uploader)s - %(title)s.%(ext)s", "-ciw", "--add-metadata", "--hls-use-mpegts", "--no-part", url)
|
||||
if config.YouTubeCookieFile != "" {
|
||||
// a cookie file was specified, make sure yt-dlp knows about it
|
||||
cmd = exec.Command("yt-dlp", "-P", dir, "-o", "%(upload_date)s - %(uploader)s - %(title)s.%(ext)s", "-ciw", "--add-metadata", "--hls-use-mpegts", "--no-part", url)
|
||||
} else {
|
||||
cmd = exec.Command("yt-dlp", "--cookies", config.YouTubeCookieFile,"-P", dir, "-o", "%(upload_date)s - %(uploader)s - %(title)s.%(ext)s", "-ciw", "--add-metadata", "--hls-use-mpegts", "--no-part", url)
|
||||
}
|
||||
} else if channel.Type == "twitch" {
|
||||
cmd = exec.Command("streamlink", "--twitch-disable-hosting", "-o", path.Join(dir, "{time:%Y%m%d} - {author} - {title}.mp4"), url, "best")
|
||||
}
|
||||
|
|
1
go.mod
1
go.mod
|
@ -4,6 +4,7 @@ go 1.17
|
|||
|
||||
require (
|
||||
github.com/BurntSushi/toml v0.4.1 // indirect
|
||||
github.com/MercuryEngineering/CookieMonster v0.0.0-20180304172713-1584578b3403 // indirect
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
|
||||
github.com/nicklaw5/helix v1.25.0 // indirect
|
||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -1,5 +1,7 @@
|
|||
github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
|
||||
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/MercuryEngineering/CookieMonster v0.0.0-20180304172713-1584578b3403 h1:EtZwYyLbkEcIt+B//6sujwRCnHuTEK3qiSypAX5aJeM=
|
||||
github.com/MercuryEngineering/CookieMonster v0.0.0-20180304172713-1584578b3403/go.mod h1:mM6WvakkX2m+NgMiPCfFFjwfH4KzENC07zeGEqq9U7s=
|
||||
github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
||||
|
|
4
main.go
4
main.go
|
@ -11,7 +11,6 @@ import (
|
|||
|
||||
var (
|
||||
outputDirTemplate *template.Template
|
||||
// TODO: add these to the config
|
||||
maxRetryCount int
|
||||
retryDelay time.Duration
|
||||
metadataTimeout = 15 * time.Second // TODO: fine tune
|
||||
|
@ -35,6 +34,9 @@ func main() {
|
|||
// set up twitch
|
||||
setupTwitch(config)
|
||||
|
||||
// set up youtube-specific bits
|
||||
setupYouTube()
|
||||
|
||||
// compile template
|
||||
outputDirTemplate = template.Must(template.New("outputdir").Parse(config.OutputDir))
|
||||
|
||||
|
|
29
youtube.go
29
youtube.go
|
@ -4,7 +4,10 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"regexp"
|
||||
"net/url"
|
||||
"github.com/MercuryEngineering/CookieMonster"
|
||||
)
|
||||
|
||||
type YTThumbnail struct {
|
||||
|
@ -15,10 +18,34 @@ type YTThumbnail struct {
|
|||
|
||||
var (
|
||||
reYtIsLive = regexp.MustCompile("{\"text\":\" watching\"}")
|
||||
|
||||
ytHttpClient http.Client
|
||||
)
|
||||
|
||||
func setupYouTube() {
|
||||
jar, err := cookiejar.New(nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ytHttpClient = http.Client{
|
||||
Jar: jar,
|
||||
}
|
||||
|
||||
// check if we should send YouTube cookies
|
||||
if config.YouTubeCookieFile != "" {
|
||||
cookies, err := cookiemonster.ParseFile(config.YouTubeCookieFile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
urlObj, _ := url.Parse("https://youtube.com")
|
||||
ytHttpClient.Jar.SetCookies(urlObj, cookies)
|
||||
}
|
||||
}
|
||||
|
||||
func ytIsChannelLive(id string) (bool, error) {
|
||||
resp, err := http.Get(fmt.Sprintf("https://www.youtube.com/channel/%s", id))
|
||||
resp, err := ytHttpClient.Get(fmt.Sprintf("https://www.youtube.com/channel/%s", id))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue