@@ -168,49 +168,29 @@ func (d *M3u8Downloader) autoRefreshList() {
168
168
}
169
169
170
170
func (d * M3u8Downloader ) download (item MediaItem ) (string , error ) {
171
-
172
171
wg := & sync.WaitGroup {}
173
172
statusBar := & StatusBar {wg : wg }
174
173
wg .Add (1 )
175
174
176
175
localPath := filepath .Join (d .localDir , item .Name )
177
176
remotePath := item .Path
178
177
179
- if len (d .remotePath ) > 0 {
178
+ downloader , err := sdk .CreateDownloader (d .allocationID , localPath , remotePath ,
179
+ sdk .WithAllocation (d .allocationObj ),
180
+ sdk .WithAuthticket (d .authTicket , d .lookupHash ),
181
+ sdk .WithRxPay (d .rxPay ))
180
182
181
- err := d .allocationObj .DownloadFile (localPath , remotePath , statusBar )
183
+ if err != nil {
184
+ return "" , err
185
+ }
182
186
183
- if err != nil {
184
- return "" , err
185
- }
187
+ err = downloader .Start (statusBar )
186
188
187
- wg .Wait ()
189
+ if err != nil {
190
+ return "" , err
188
191
}
189
192
190
- //TODO: add download ts files from auth ticket
191
- // allocationObj, err = sdk.GetAllocationFromAuthTicket(authticket)
192
- // if err != nil {
193
- // PrintError("Error fetching the allocation", err)
194
- // os.Exit(1)
195
- // }
196
- // at := sdk.InitAuthTicket(authticket)
197
- // filename, err := at.GetFileName()
198
- // if err != nil {
199
- // PrintError("Error getting the filename from authticket", err)
200
- // os.Exit(1)
201
- // }
202
- // if len(lookuphash) == 0 {
203
- // lookuphash, err = at.GetLookupHash()
204
- // if err != nil {
205
- // PrintError("Error getting the lookuphash from authticket", err)
206
- // os.Exit(1)
207
- // }
208
- // }
209
-
210
- // return d.allocationObj.DownloadFromAuthTicket(localpath,
211
- // authticket, lookuphash, filename, rxPay, statusBar)
212
-
213
- //}
193
+ wg .Wait ()
214
194
215
195
return item .Name , nil
216
196
}
0 commit comments