Skip to content

Commit

Permalink
Improve handling of DASH urls
Browse files Browse the repository at this point in the history
  • Loading branch information
notpeko committed Mar 20, 2022
1 parent d027723 commit 98af10f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion args.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
const (
VersionMajor = 1
VersionMinor = 7
VersionPatch = 0
VersionPatch = 1
)

var Commit string
Expand Down
21 changes: 21 additions & 0 deletions download/parsed_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,32 @@ func parseDownloadURL(rawUrl string) (*parsedURL, error) {
findField = func(name string) string {
for i := 0; i < len(fields); i += 2 {
if fields[i] == name {
//handle trailing slash
if i + 1 == len(fields) {
return ""
}
return fields[i + 1]
}
}
return ""
}
hasSq := false
for i := 0; i < len(fields); i += 2 {
if fields[i] == "sq" {
hasSq = true
}
}
if hasSq {
val := findField("sq")
if strings.HasSuffix(p.raw, "/sq/" + val) {
//strip sq value and separating / from url
p.raw = p.raw[:len(p.raw) - (len(val) + 1)]
} else if !strings.HasSuffix(p.raw, "/sq") {
return nil, fmt.Errorf("URL has 'sq' parameter but it's not the last")
}
} else {
p.raw = p.raw + "/sq"
}
}

id := findField("id")
Expand Down

0 comments on commit 98af10f

Please sign in to comment.