pair programming follow up
This commit is contained in:
parent
e9f34c977e
commit
0c268039c1
6 changed files with 19 additions and 18 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/lbryio/lbry.go/errors"
|
"github.com/lbryio/lbry.go/errors"
|
||||||
"github.com/lbryio/lbry.go/null"
|
"github.com/lbryio/lbry.go/null"
|
||||||
"github.com/lbryio/lbry.go/util"
|
"github.com/lbryio/lbry.go/util"
|
||||||
|
"github.com/lbryio/lbry.go/ytsync/namer"
|
||||||
"github.com/lbryio/lbry.go/ytsync/sdk"
|
"github.com/lbryio/lbry.go/ytsync/sdk"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
@ -35,12 +36,12 @@ type SyncManager struct {
|
||||||
SingleRun bool
|
SingleRun bool
|
||||||
ChannelProperties *sdk.ChannelProperties
|
ChannelProperties *sdk.ChannelProperties
|
||||||
APIConfig *sdk.APIConfig
|
APIConfig *sdk.APIConfig
|
||||||
namer *Namer
|
namer *namer.Namer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSyncManager() *SyncManager {
|
func NewSyncManager() *SyncManager {
|
||||||
return &SyncManager{
|
return &SyncManager{
|
||||||
namer: NewNamer(),
|
namer: namer.NewNamer(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ const (
|
||||||
func (s *SyncManager) Start() error {
|
func (s *SyncManager) Start() error {
|
||||||
if s.namer == nil {
|
if s.namer == nil {
|
||||||
// TODO: fix me, use NewSyncManager instead
|
// TODO: fix me, use NewSyncManager instead
|
||||||
s.namer = NewNamer()
|
s.namer = namer.NewNamer()
|
||||||
}
|
}
|
||||||
|
|
||||||
syncCount := 0
|
syncCount := 0
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package ytsync
|
package namer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
@ -40,7 +40,8 @@ func (n *Namer) GetNextName(prefix string) string {
|
||||||
|
|
||||||
//if for some reasons the title can't be converted in a valid claim name (too short or not latin) then we use a hash
|
//if for some reasons the title can't be converted in a valid claim name (too short or not latin) then we use a hash
|
||||||
if len(name) < 2 {
|
if len(name) < 2 {
|
||||||
name = fmt.Sprintf("%s-%d", hex.EncodeToString(md5.Sum([]byte(prefix))[:])[:15], attempt)
|
sum := md5.Sum([]byte(prefix))
|
||||||
|
name = fmt.Sprintf("%s-%d", hex.EncodeToString(sum[:])[:15], attempt)
|
||||||
}
|
}
|
||||||
|
|
||||||
n.names[name] = true
|
n.names[name] = true
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/lbryio/lbry.go/jsonrpc"
|
"github.com/lbryio/lbry.go/jsonrpc"
|
||||||
"github.com/lbryio/lbry.go/ytsync"
|
"github.com/lbryio/lbry.go/ytsync/namer"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SyncSummary struct {
|
type SyncSummary struct {
|
||||||
|
@ -12,7 +12,7 @@ type SyncSummary struct {
|
||||||
ClaimName string
|
ClaimName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func publishAndRetryExistingNames(daemon *jsonrpc.Client, title, filename string, amount float64, options jsonrpc.PublishOptions, namer *ytsync.Namer) (*SyncSummary, error) {
|
func publishAndRetryExistingNames(daemon *jsonrpc.Client, title, filename string, amount float64, options jsonrpc.PublishOptions, namer *namer.Namer) (*SyncSummary, error) {
|
||||||
for {
|
for {
|
||||||
name := namer.GetNextName(title)
|
name := namer.GetNextName(title)
|
||||||
response, err := daemon.Publish(name, filename, amount, options)
|
response, err := daemon.Publish(name, filename, amount, options)
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
||||||
"github.com/lbryio/lbry.go/errors"
|
"github.com/lbryio/lbry.go/errors"
|
||||||
"github.com/lbryio/lbry.go/jsonrpc"
|
"github.com/lbryio/lbry.go/jsonrpc"
|
||||||
"github.com/lbryio/lbry.go/ytsync"
|
"github.com/lbryio/lbry.go/ytsync/namer"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
|
@ -174,7 +174,7 @@ func (v *ucbVideo) saveThumbnail() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *ucbVideo) publish(daemon *jsonrpc.Client, claimAddress string, amount float64, channelID string, namer *ytsync.Namer) (*SyncSummary, error) {
|
func (v *ucbVideo) publish(daemon *jsonrpc.Client, claimAddress string, amount float64, channelID string, namer *namer.Namer) (*SyncSummary, error) {
|
||||||
options := jsonrpc.PublishOptions{
|
options := jsonrpc.PublishOptions{
|
||||||
Title: &v.title,
|
Title: &v.title,
|
||||||
Author: strPtr("UC Berkeley"),
|
Author: strPtr("UC Berkeley"),
|
||||||
|
@ -194,9 +194,7 @@ func (v *ucbVideo) Size() *int64 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *ucbVideo) Sync(daemon *jsonrpc.Client, claimAddress string, amount float64, channelID string, maxVideoSize int, claimNames map[string]bool, syncedVideosMux *sync.RWMutex) (*SyncSummary, error) {
|
func (v *ucbVideo) Sync(daemon *jsonrpc.Client, claimAddress string, amount float64, channelID string, maxVideoSize int, namer *namer.Namer) (*SyncSummary, error) {
|
||||||
v.claimNames = claimNames
|
|
||||||
v.syncedVideosMux = syncedVideosMux
|
|
||||||
//download and thumbnail can be done in parallel
|
//download and thumbnail can be done in parallel
|
||||||
err := v.download()
|
err := v.download()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -210,7 +208,7 @@ func (v *ucbVideo) Sync(daemon *jsonrpc.Client, claimAddress string, amount floa
|
||||||
//}
|
//}
|
||||||
//log.Debugln("Created thumbnail for " + v.id)
|
//log.Debugln("Created thumbnail for " + v.id)
|
||||||
|
|
||||||
summary, err := v.publish(daemon, claimAddress, amount, channelID)
|
summary, err := v.publish(daemon, claimAddress, amount, channelID, namer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Prefix("publish error", err)
|
return nil, errors.Prefix("publish error", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
|
|
||||||
"github.com/lbryio/lbry.go/errors"
|
"github.com/lbryio/lbry.go/errors"
|
||||||
"github.com/lbryio/lbry.go/jsonrpc"
|
"github.com/lbryio/lbry.go/jsonrpc"
|
||||||
"github.com/lbryio/lbry.go/ytsync"
|
"github.com/lbryio/lbry.go/ytsync/namer"
|
||||||
|
|
||||||
"github.com/rylio/ytdl"
|
"github.com/rylio/ytdl"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -234,7 +234,7 @@ func (v *YoutubeVideo) triggerThumbnailSave() error {
|
||||||
|
|
||||||
func strPtr(s string) *string { return &s }
|
func strPtr(s string) *string { return &s }
|
||||||
|
|
||||||
func (v *YoutubeVideo) publish(daemon *jsonrpc.Client, claimAddress string, amount float64, channelID string, namer *ytsync.Namer) (*SyncSummary, error) {
|
func (v *YoutubeVideo) publish(daemon *jsonrpc.Client, claimAddress string, amount float64, channelID string, namer *namer.Namer) (*SyncSummary, error) {
|
||||||
if channelID == "" {
|
if channelID == "" {
|
||||||
return nil, errors.Err("a claim_id for the channel wasn't provided") //TODO: this is probably not needed?
|
return nil, errors.Err("a claim_id for the channel wasn't provided") //TODO: this is probably not needed?
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ func (v *YoutubeVideo) Size() *int64 {
|
||||||
return v.size
|
return v.size
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *YoutubeVideo) Sync(daemon *jsonrpc.Client, claimAddress string, amount float64, channelID string, maxVideoSize int, namer *ytsync.Namer) (*SyncSummary, error) {
|
func (v *YoutubeVideo) Sync(daemon *jsonrpc.Client, claimAddress string, amount float64, channelID string, maxVideoSize int, namer *namer.Namer) (*SyncSummary, error) {
|
||||||
v.maxVideoSize = int64(maxVideoSize) * 1024 * 1024
|
v.maxVideoSize = int64(maxVideoSize) * 1024 * 1024
|
||||||
//download and thumbnail can be done in parallel
|
//download and thumbnail can be done in parallel
|
||||||
err := v.download()
|
err := v.download()
|
||||||
|
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"github.com/lbryio/lbry.go/jsonrpc"
|
"github.com/lbryio/lbry.go/jsonrpc"
|
||||||
"github.com/lbryio/lbry.go/stop"
|
"github.com/lbryio/lbry.go/stop"
|
||||||
"github.com/lbryio/lbry.go/util"
|
"github.com/lbryio/lbry.go/util"
|
||||||
|
"github.com/lbryio/lbry.go/ytsync/namer"
|
||||||
"github.com/lbryio/lbry.go/ytsync/sources"
|
"github.com/lbryio/lbry.go/ytsync/sources"
|
||||||
"github.com/mitchellh/go-ps"
|
"github.com/mitchellh/go-ps"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -46,7 +47,7 @@ type video interface {
|
||||||
IDAndNum() string
|
IDAndNum() string
|
||||||
PlaylistPosition() int
|
PlaylistPosition() int
|
||||||
PublishedAt() time.Time
|
PublishedAt() time.Time
|
||||||
Sync(*jsonrpc.Client, string, float64, string, int, *Namer) (*sources.SyncSummary, error)
|
Sync(*jsonrpc.Client, string, float64, string, int, *namer.Namer) (*sources.SyncSummary, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// sorting videos
|
// sorting videos
|
||||||
|
@ -81,7 +82,7 @@ type Sync struct {
|
||||||
claimNames map[string]bool
|
claimNames map[string]bool
|
||||||
grp *stop.Group
|
grp *stop.Group
|
||||||
lbryChannelID string
|
lbryChannelID string
|
||||||
namer *Namer
|
namer *namer.Namer
|
||||||
|
|
||||||
walletMux *sync.Mutex
|
walletMux *sync.Mutex
|
||||||
queue chan video
|
queue chan video
|
||||||
|
|
Loading…
Reference in a new issue