Skip to content

Commit d8f68b6

Browse files
authored
Merge pull request #50 from deadblue/develop
Bump version to 0.7.3.
2 parents bbc0c98 + 0f96534 commit d8f68b6

File tree

12 files changed

+40
-15
lines changed

12 files changed

+40
-15
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.

file.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (i *fileIterator) Items() iter.Seq2[int, *File] {
212212
}
213213

214214
// FileIterate list files under directory, whose id is |dirId|.
215-
func (a *Agent) FileIterate(dirId string) (it Iterator[*File], err error) {
215+
func (a *Agent) FileIterate(dirId string) (it Iterator[File], err error) {
216216
fi := &fileIterator{
217217
llc: a.llc,
218218
dirId: dirId,
@@ -225,7 +225,7 @@ func (a *Agent) FileIterate(dirId string) (it Iterator[*File], err error) {
225225
}
226226

227227
// FileWithStar lists files with star.
228-
func (a *Agent) FileWithStar(options ...*option.FileListOptions) (it Iterator[*File], err error) {
228+
func (a *Agent) FileWithStar(options ...*option.FileListOptions) (it Iterator[File], err error) {
229229
fi := &fileIterator{
230230
llc: a.llc,
231231
mode: 2,
@@ -245,7 +245,7 @@ func (a *Agent) FileWithStar(options ...*option.FileListOptions) (it Iterator[*F
245245
// the given keyword.
246246
func (a *Agent) FileSearch(
247247
dirId, keyword string, options ...*option.FileListOptions,
248-
) (it Iterator[*File], err error) {
248+
) (it Iterator[File], err error) {
249249
fi := &fileIterator{
250250
llc: a.llc,
251251
dirId: dirId,
@@ -266,7 +266,7 @@ func (a *Agent) FileSearch(
266266
// FileLabeled lists files which has specific label.
267267
func (a *Agent) FileWithLabel(
268268
labelId string, options ...*option.FileListOptions,
269-
) (it Iterator[*File], err error) {
269+
) (it Iterator[File], err error) {
270270
fi := &fileIterator{
271271
llc: a.llc,
272272
mode: 4,

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+
}

iterator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ type Iterator[T any] interface {
1616
Count() int
1717

1818
// Items return an index-item sequence.
19-
Items() iter.Seq2[int, T]
19+
Items() iter.Seq2[int, *T]
2020
}

label.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (i *labelIterator) Items() iter.Seq2[int, *Label] {
102102
}
103103
}
104104

105-
func (a *Agent) LabelIterate() (it Iterator[*Label], err error) {
105+
func (a *Agent) LabelIterate() (it Iterator[Label], err error) {
106106
li := &labelIterator{
107107
llc: a.llc,
108108
offset: 0,

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/api/qrcode.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99

1010
const (
1111
qrcodeTokenUrl = "https://qrcodeapi.115.com/api/1.0/%s/1.0/token"
12-
qrcodeImageUrl = "https://qrcodeapi.115.com/api/1.0/%s/1.0/qrcode?qrfrom=1&client=0&uid=%s"
1312
qrcodeLoginUrl = "https://passportapi.115.com/app/1.0/%s/1.0/login/qrcode"
13+
14+
qrcodeImageUrl = "https://qrcodeapi.115.com/api/1.0/web/1.0/qrcode?qrfrom=1&client=0&uid=%s"
1415
)
1516

1617
type QrcodeTokenSpec struct {
@@ -46,6 +47,6 @@ func (s *QrcodeLoginSpec) Init(app, uid string) *QrcodeLoginSpec {
4647
return s
4748
}
4849

49-
func QrcodeImageUrl(app, uid string) string {
50-
return fmt.Sprintf(qrcodeImageUrl, app, uid)
50+
func QrcodeImageUrl(uid string) string {
51+
return fmt.Sprintf(qrcodeImageUrl, uid)
5152
}

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

offline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (i *offlineIterator) Items() iter.Seq2[int, *OfflineTask] {
101101
}
102102

103103
// OfflineIterate returns an iterator to access all offline tasks.
104-
func (a *Agent) OfflineIterate() (it Iterator[*OfflineTask], err error) {
104+
func (a *Agent) OfflineIterate() (it Iterator[OfflineTask], err error) {
105105
oi := &offlineIterator{
106106
llc: a.llc,
107107
page: 1,

0 commit comments

Comments
 (0)