Skip to content

Commit 2a2523f

Browse files
committed
Update video logic.
1 parent 34d7146 commit 2a2523f

File tree

6 files changed

+27
-3
lines changed

6 files changed

+27
-3
lines changed

agent.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ type Agent struct {
2020

2121
// Common parameters
2222
common types.CommonParams
23+
24+
// Is agent use web credential?
25+
isWeb bool
2326
}
2427

2528
// Default creates an Agent with default settings.

internal/protocol/cookie.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package protocol
22

3+
import "strings"
4+
35
const (
46
CookieUrl = "https://115.com"
57

@@ -14,3 +16,8 @@ var (
1416
".anxia.com",
1517
}
1618
)
19+
20+
func IsWebCredential(uid string) bool {
21+
parts := strings.Split(uid, "_")
22+
return len(parts) == 3 && parts[1][0] == 'A'
23+
}

login.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (a *Agent) CredentialImport(cr *Credential) (err error) {
3535
protocol.CookieNameSEID: cr.SEID,
3636
}
3737
a.llc.ImportCookies(cookies, protocol.CookieDomains...)
38-
return a.afterSignIn()
38+
return a.afterSignIn(cr.UID)
3939
}
4040

4141
// CredentialExport exports current credentials for future-use.
@@ -46,11 +46,12 @@ func (a *Agent) CredentialExport(cr *Credential) {
4646
cr.SEID = cookies[protocol.CookieNameSEID]
4747
}
4848

49-
func (a *Agent) afterSignIn() (err error) {
49+
func (a *Agent) afterSignIn(uid string) (err error) {
5050
// Call UploadInfo API to get userId and userKey
5151
spec := (&api.UploadInfoSpec{}).Init()
5252
if err = a.llc.CallApi(spec, context.Background()); err == nil {
5353
a.common.SetUserInfo(spec.Result.UserId, spec.Result.UserKey)
54+
a.isWeb = protocol.IsWebCredential(uid)
5455
}
5556
return
5657
}

lowlevel/errors/media.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package errors
2+
3+
import "errors"
4+
5+
var (
6+
ErrUnsupportedPlatform = errors.New("unsupported platform")
7+
)

media.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ type VideoTicket struct {
4545

4646
// VideoCreateTicket creates a PlayTicket to play the cloud video.
4747
func (a *Agent) VideoCreateTicket(pickcode string, ticket *VideoTicket) (err error) {
48+
if !a.isWeb {
49+
return errors.ErrUnsupportedPlatform
50+
}
4851
spec := (&api.VideoPlayWebSpec{}).Init(pickcode)
4952
if err = a.llc.CallApi(spec, context.Background()); err != nil {
5053
return
@@ -63,6 +66,9 @@ func (a *Agent) VideoCreateTicket(pickcode string, ticket *VideoTicket) (err err
6366
ticket.Url = video.PlayUrl
6467
}
6568
}
69+
ticket.Headers = map[string]string{
70+
"User-Agent": a.llc.GetUserAgent(),
71+
}
6672
return
6773
}
6874

qrcode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (a *Agent) qrcodeSignIn(session *QrcodeSession) (err error) {
8585
if err = a.llc.CallApi(spec, context.Background()); err != nil {
8686
return
8787
}
88-
return a.afterSignIn()
88+
return a.afterSignIn(spec.Result.Cookie.UID)
8989
}
9090

9191
// QrcodePoll polls the session state, and automatically sin

0 commit comments

Comments
 (0)