From 35e772cadc8920991dd66bdbe50c19bec06efa4a Mon Sep 17 00:00:00 2001 From: Lz Date: Sat, 29 Jan 2022 00:16:27 +0800 Subject: [PATCH] Fix/update sha1 with sha256 for file hash (#159) * fix(download): fixed download --live doesn't work with authticet and lookuphash --- cmd/download_m3u8.go | 42 +++++++++++------------------------------- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 14 insertions(+), 34 deletions(-) diff --git a/cmd/download_m3u8.go b/cmd/download_m3u8.go index bc0befa6f..66b0407bc 100644 --- a/cmd/download_m3u8.go +++ b/cmd/download_m3u8.go @@ -168,7 +168,6 @@ func (d *M3u8Downloader) autoRefreshList() { } func (d *M3u8Downloader) download(item MediaItem) (string, error) { - wg := &sync.WaitGroup{} statusBar := &StatusBar{wg: wg} wg.Add(1) @@ -176,41 +175,22 @@ func (d *M3u8Downloader) download(item MediaItem) (string, error) { localPath := filepath.Join(d.localDir, item.Name) remotePath := item.Path - if len(d.remotePath) > 0 { + downloader, err := sdk.CreateDownloader(d.allocationID, localPath, remotePath, + sdk.WithAllocation(d.allocationObj), + sdk.WithAuthticket(d.authTicket, d.lookupHash), + sdk.WithRxPay(d.rxPay)) - err := d.allocationObj.DownloadFile(localPath, remotePath, statusBar) + if err != nil { + return "", err + } - if err != nil { - return "", err - } + err = downloader.Start(statusBar) - wg.Wait() + if err != nil { + return "", err } - //TODO: add download ts files from auth ticket - // allocationObj, err = sdk.GetAllocationFromAuthTicket(authticket) - // if err != nil { - // PrintError("Error fetching the allocation", err) - // os.Exit(1) - // } - // at := sdk.InitAuthTicket(authticket) - // filename, err := at.GetFileName() - // if err != nil { - // PrintError("Error getting the filename from authticket", err) - // os.Exit(1) - // } - // if len(lookuphash) == 0 { - // lookuphash, err = at.GetLookupHash() - // if err != nil { - // PrintError("Error getting the lookuphash from authticket", err) - // os.Exit(1) - // } - // } - - // return d.allocationObj.DownloadFromAuthTicket(localpath, - // authticket, lookuphash, filename, rxPay, statusBar) - - //} + wg.Wait() return item.Name, nil } diff --git a/go.mod b/go.mod index 34a14e05a..0b781da41 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.13 require ( github.com/0chain/errors v1.0.3 - github.com/0chain/gosdk v1.4.1-0.20220105140556-1e37d2ba4e8a + github.com/0chain/gosdk v1.4.1-0.20220127152226-9c642c9955e9 github.com/olekukonko/tablewriter v0.0.5 github.com/spf13/cobra v1.1.1 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index 5b8d3204a..3b58bb870 100644 --- a/go.sum +++ b/go.sum @@ -49,8 +49,8 @@ collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM= github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc= -github.com/0chain/gosdk v1.4.1-0.20220105140556-1e37d2ba4e8a h1:VYZNUfUTdEB3PLT81bkPWBkRNklUymjdUawAYxhWgyw= -github.com/0chain/gosdk v1.4.1-0.20220105140556-1e37d2ba4e8a/go.mod h1:FB2xXhQyIM1vwvQ1jC98wNclbDTBwqrG+Z/IQC0LaBs= +github.com/0chain/gosdk v1.4.1-0.20220127152226-9c642c9955e9 h1:igz4J+VZH10beCmt7SWAdhlH6vtMZ2+jO7XjmUy+WLM= +github.com/0chain/gosdk v1.4.1-0.20220127152226-9c642c9955e9/go.mod h1:FB2xXhQyIM1vwvQ1jC98wNclbDTBwqrG+Z/IQC0LaBs= github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4= github.com/Azure/azure-pipeline-go v0.2.2/go.mod h1:4rQ/NZncSvGqNkkOsNpOU1tgoNuIlp9AfUH5G1tvCHc= github.com/Azure/azure-storage-blob-go v0.7.0/go.mod h1:f9YQKtsG1nMisotuTPpO0tjNuEjKRYAcJU8/ydDI++4=