add support for channel claimid
This commit is contained in:
parent
f23e24c029
commit
e560b590f5
3 changed files with 41 additions and 3 deletions
|
@ -110,6 +110,7 @@ func (s *SyncManager) Start() error {
|
|||
APIConfig: s.apiConfig,
|
||||
YoutubeChannelID: s.syncProperties.YoutubeChannelID,
|
||||
LbryChannelName: lbryChannelName,
|
||||
lbryChannelID: channels[0].ChannelClaimID,
|
||||
StopOnError: s.stopOnError,
|
||||
MaxTries: s.maxTries,
|
||||
ConcurrentVideos: s.concurrentVideos,
|
||||
|
@ -143,6 +144,7 @@ func (s *SyncManager) Start() error {
|
|||
APIConfig: s.apiConfig,
|
||||
YoutubeChannelID: c.ChannelId,
|
||||
LbryChannelName: c.DesiredChannelName,
|
||||
lbryChannelID: c.ChannelClaimID,
|
||||
StopOnError: s.stopOnError,
|
||||
MaxTries: s.maxTries,
|
||||
ConcurrentVideos: s.concurrentVideos,
|
||||
|
|
29
sdk/api.go
29
sdk/api.go
|
@ -39,6 +39,7 @@ type YoutubeChannel struct {
|
|||
Address string `json:"address"`
|
||||
Currency string `json:"currency"`
|
||||
} `json:"fee"`
|
||||
ChannelClaimID string `json:"channel_claim_id"`
|
||||
}
|
||||
|
||||
func (a *APIConfig) FetchChannels(status string, cp *SyncProperties) ([]YoutubeChannel, error) {
|
||||
|
@ -117,6 +118,34 @@ func (a *APIConfig) SetChannelStatus(channelID string, status string, failureRea
|
|||
return nil, nil, errors.Err("invalid API response. Status code: %d", res.StatusCode)
|
||||
}
|
||||
|
||||
func (a *APIConfig) SetChannelClaimID(channelID string, channelClaimID string) error {
|
||||
type apiChannelStatusResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Error null.String `json:"error"`
|
||||
Data string `json:"data"`
|
||||
}
|
||||
endpoint := a.ApiURL + "/yt/set_channel_claim_id"
|
||||
res, _ := http.PostForm(endpoint, url.Values{
|
||||
"channel_id": {channelID},
|
||||
"auth_token": {a.ApiToken},
|
||||
"channel_claim_id": {channelClaimID},
|
||||
})
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
var response apiChannelStatusResponse
|
||||
err := json.Unmarshal(body, &response)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !response.Error.IsNull() {
|
||||
return errors.Err(response.Error.String)
|
||||
}
|
||||
if response.Data != "ok" {
|
||||
return errors.Err("Unexpected API response")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
VideoStatusPublished = "published"
|
||||
VideoStatusFailed = "failed"
|
||||
|
|
13
setup.go
13
setup.go
|
@ -190,6 +190,10 @@ func (s *Sync) ensureChannelOwnership() error {
|
|||
isChannelMine := false
|
||||
for _, channel := range *channels {
|
||||
if channel.Name == s.LbryChannelName {
|
||||
//TODO: eventually get rid of this when the whole db is filled
|
||||
if s.lbryChannelID == "" {
|
||||
err = s.Manager.apiConfig.SetChannelClaimID(s.YoutubeChannelID, s.lbryChannelID)
|
||||
}
|
||||
s.lbryChannelID = channel.ClaimID
|
||||
isChannelMine = true
|
||||
} else {
|
||||
|
@ -197,7 +201,7 @@ func (s *Sync) ensureChannelOwnership() error {
|
|||
}
|
||||
}
|
||||
if isChannelMine {
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
channelBidAmount := channelClaimAmount
|
||||
|
@ -211,7 +215,10 @@ func (s *Sync) ensureChannelOwnership() error {
|
|||
balance := decimal.Decimal(*balanceResp)
|
||||
|
||||
if balance.LessThan(decimal.NewFromFloat(channelBidAmount)) {
|
||||
s.addCredits(channelBidAmount + 0.1)
|
||||
err = s.addCredits(channelBidAmount + 0.1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
c, err := s.daemon.ChannelNew(s.LbryChannelName, channelBidAmount)
|
||||
|
@ -219,7 +226,7 @@ func (s *Sync) ensureChannelOwnership() error {
|
|||
return err
|
||||
}
|
||||
s.lbryChannelID = c.ClaimID
|
||||
return nil
|
||||
return s.Manager.apiConfig.SetChannelClaimID(s.YoutubeChannelID, s.lbryChannelID)
|
||||
}
|
||||
|
||||
func allUTXOsConfirmed(utxolist *jsonrpc.UTXOListResponse) bool {
|
||||
|
|
Loading…
Reference in a new issue