From 98af10fc35f7f5c98191eeb5235a625ac6d6e3e3 Mon Sep 17 00:00:00 2001 From: notpeko <91615020+notpeko@users.noreply.github.com> Date: Sun, 20 Mar 2022 16:17:27 -0300 Subject: [PATCH] Improve handling of DASH urls --- args.go | 2 +- download/parsed_url.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/args.go b/args.go index 1e0d400..5ac3705 100644 --- a/args.go +++ b/args.go @@ -20,7 +20,7 @@ import ( const ( VersionMajor = 1 VersionMinor = 7 - VersionPatch = 0 + VersionPatch = 1 ) var Commit string diff --git a/download/parsed_url.go b/download/parsed_url.go index 2064f8a..103526d 100644 --- a/download/parsed_url.go +++ b/download/parsed_url.go @@ -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")