Tracking synced videos #115
3 changed files with 46 additions and 18 deletions
|
@ -17,12 +17,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type SyncContext struct {
|
type SyncContext struct {
|
||||||
DryRun bool
|
DryRun bool
|
||||||
KeepCache bool
|
KeepCache bool
|
||||||
TempDir string
|
ReflectStreams bool
|
||||||
LbrynetAddr string
|
TempDir string
|
||||||
ChannelID string
|
LbrynetAddr string
|
||||||
PublishBid float64
|
ChannelID string
|
||||||
|
PublishBid float64
|
||||||
YouTubeSourceConfig *YouTubeSourceConfig
|
YouTubeSourceConfig *YouTubeSourceConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +58,7 @@ func AddCommand(rootCmd *cobra.Command) {
|
||||||
}
|
}
|
||||||
cmd.Flags().BoolVar(&syncContext.DryRun, "dry-run", false, "Display information about the stream publishing, but do not publish the stream")
|
cmd.Flags().BoolVar(&syncContext.DryRun, "dry-run", false, "Display information about the stream publishing, but do not publish the stream")
|
||||||
cmd.Flags().BoolVar(&syncContext.KeepCache, "keep-cache", false, "Don't delete local files after publishing.")
|
cmd.Flags().BoolVar(&syncContext.KeepCache, "keep-cache", false, "Don't delete local files after publishing.")
|
||||||
|
cmd.Flags().BoolVar(&syncContext.ReflectStreams, "reflect-streams", true, "Require published streams to be reflected.")
|
||||||
cmd.Flags().StringVar(&syncContext.TempDir, "temp-dir", getEnvDefault("TEMP_DIR", ""), "directory to use for temporary files")
|
cmd.Flags().StringVar(&syncContext.TempDir, "temp-dir", getEnvDefault("TEMP_DIR", ""), "directory to use for temporary files")
|
||||||
cmd.Flags().Float64Var(&syncContext.PublishBid, "publish-bid", 0.01, "Bid amount for the stream claim")
|
cmd.Flags().Float64Var(&syncContext.PublishBid, "publish-bid", 0.01, "Bid amount for the stream claim")
|
||||||
cmd.Flags().StringVar(&syncContext.LbrynetAddr, "lbrynet-address", getEnvDefault("LBRYNET_ADDRESS", ""), "JSONRPC address of the local LBRYNet daemon")
|
cmd.Flags().StringVar(&syncContext.LbrynetAddr, "lbrynet-address", getEnvDefault("LBRYNET_ADDRESS", ""), "JSONRPC address of the local LBRYNet daemon")
|
||||||
|
@ -119,15 +121,19 @@ func localCmd(cmd *cobra.Command, args []string) {
|
||||||
log.Debugf("Object to be published: %v", processedVideo)
|
log.Debugf("Object to be published: %v", processedVideo)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
done, err := publisher.Publish(*processedVideo)
|
doneReflectingCh, err := publisher.Publish(*processedVideo, syncContext.ReflectStreams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error publishing video: %v", err)
|
log.Errorf("Error publishing video: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = <-done
|
if syncContext.ReflectStreams {
|
||||||
if err != nil {
|
err = <-doneReflectingCh
|
||||||
log.Errorf("Error while wating for stream to reflect: %v", err)
|
if err != nil {
|
||||||
|
log.Errorf("Error while wating for stream to reflect: %v", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Debugln("Not waiting for stream to reflect.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,13 +233,14 @@ func getAbbrevDescription(v SourceVideo) string {
|
||||||
return v.SourceURL
|
return v.SourceURL
|
||||||
}
|
}
|
||||||
|
|
||||||
maxLength := 2800
|
additionalDescription := "\n...\n" + v.SourceURL
|
||||||
|
maxLength := 2800 - len(additionalDescription)
|
||||||
|
|
||||||
description := strings.TrimSpace(*v.Description)
|
description := strings.TrimSpace(*v.Description)
|
||||||
additionalDescription := "\n" + v.SourceURL
|
|
||||||
if len(description) > maxLength {
|
if len(description) > maxLength {
|
||||||
description = description[:maxLength]
|
description = description[:maxLength]
|
||||||
}
|
}
|
||||||
return description + "\n..." + additionalDescription
|
return description + additionalDescription
|
||||||
}
|
}
|
||||||
|
|
||||||
type VideoSource interface {
|
type VideoSource interface {
|
||||||
|
@ -242,5 +249,5 @@ type VideoSource interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type VideoPublisher interface {
|
type VideoPublisher interface {
|
||||||
Publish(video PublishableVideo) (chan error, error)
|
Publish(video PublishableVideo, reflectStream bool) (chan error, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ func NewLocalSDKPublisher(sdkAddr, channelID string, publishBid float64) (*Local
|
||||||
return &publisher, nil
|
return &publisher, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *LocalSDKPublisher) Publish(video PublishableVideo) (chan error, error) {
|
func (p *LocalSDKPublisher) Publish(video PublishableVideo, reflectStream bool) (chan error, error) {
|
||||||
streamCreateOptions := jsonrpc.StreamCreateOptions {
|
streamCreateOptions := jsonrpc.StreamCreateOptions {
|
||||||
ClaimCreateOptions: jsonrpc.ClaimCreateOptions {
|
ClaimCreateOptions: jsonrpc.ClaimCreateOptions {
|
||||||
Title: &video.Title,
|
Title: &video.Title,
|
||||||
|
@ -67,6 +67,10 @@ func (p *LocalSDKPublisher) Publish(video PublishableVideo) (chan error, error)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !reflectStream {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
done := make(chan error, 1)
|
done := make(chan error, 1)
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
|
@ -88,8 +92,9 @@ func (p *LocalSDKPublisher) Publish(video PublishableVideo) (chan error, error)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if !fileStatus.UploadingToReflector {
|
if !fileStatus.UploadingToReflector {
|
||||||
log.Warn("Stream is not being uploaded to a reflector. Check your lbrynet settings if this is a mistake.")
|
log.Error("Stream is not being uploaded to a reflector. Check your lbrynet settings if this is a mistake.")
|
||||||
break
|
done <- errors.New("Stream is not being reflected (check lbrynet settings).")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
log.Infof("Stream reflector progress: %d%%", fileStatus.ReflectorProgress)
|
log.Infof("Stream reflector progress: %d%%", fileStatus.ReflectorProgress)
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
- LBRY SDK (what do we actually need this for?)
|
- LBRY SDK (what do we actually need this for?)
|
||||||
- youtube-dl
|
- youtube-dl
|
||||||
- enough space to cache stuff
|
- enough space to cache stuff
|
||||||
|
- YouTube data API key
|
||||||
|
|
||||||
|
|
||||||
## Process
|
## Process
|
||||||
|
@ -15,6 +16,21 @@
|
||||||
- or easier, just error if no channel
|
- or easier, just error if no channel
|
||||||
- enough lbc in wallet?
|
- enough lbc in wallet?
|
||||||
|
|
||||||
|
### Getting a YouTube API key
|
||||||
|
|
||||||
|
To access the YouTube data API, you will first need some kind of google account.
|
||||||
|
|
||||||
|
The API has two methods of authentication, OAuth2 and API keys. This application uses API keys.
|
||||||
|
These API keys are basically like passwords, and so once obtained, they should not be shared.
|
||||||
|
|
||||||
|
The instructions for obtaining an API key are copied below from [here](https://developers.google.com/youtube/registering_an_application):
|
||||||
|
|
||||||
|
|
||||||
|
1. Open the [Credentials page](https://console.developers.google.com/apis/credentials) in the API Console.
|
||||||
|
2. Create an API key in the Console by clicking **Create credentials > API key**. You can restrict the key before using it in production by clicking **Restrict key** and selecting one of the **Restrictions**.
|
||||||
|
|
||||||
|
To keep your API keys secure, follow the [best practices for securely using API keys](https://cloud.google.com/docs/authentication/api-keys).
|
||||||
|
|
||||||
### Options to figure out what's already synced
|
### Options to figure out what's already synced
|
||||||
|
|
||||||
- simplest: assume nothing is synced yet
|
- simplest: assume nothing is synced yet
|
||||||
|
@ -50,4 +66,4 @@
|
||||||
|
|
||||||
### Debugging
|
### Debugging
|
||||||
|
|
||||||
- dry-running the whole thing
|
- dry-running the whole thing
|
||||||
|
|
Loading…
Reference in a new issue