forked from AYehia0/soundcloud-dl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: - Speeding up by using go feature : concurrency. - Prompting for Yes/No. TODO : - One single bar for the download pool.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// get list of DownloadTrack of all the urls in the playlist | ||
// with the number of urls in the playlist | ||
|
||
package soundcloud | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"log" | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/AYehia0/soundcloud-dl/pkg/client" | ||
) | ||
|
||
type Id struct { | ||
Id int `json:"id"` | ||
} | ||
|
||
type Tracktmp struct { | ||
Tracks []Id `json:"tracks"` | ||
} | ||
|
||
// get all the urls inside the playlist | ||
func GetPlaylistTracks(track *SoundData, clientId string) []SoundData { | ||
ids := make([]string, 0) | ||
trackIds := Tracktmp{} | ||
plApiUrl := GetTrackInfoAPIUrl(track.PermalinkUrl, clientId) | ||
|
||
statusCode, data, err := client.Get(plApiUrl) | ||
|
||
if err != nil || statusCode != http.StatusOK { | ||
return nil | ||
} | ||
|
||
//fmt.Println(string(data)) | ||
json.Unmarshal(data, &trackIds) | ||
|
||
for _, t := range trackIds.Tracks { | ||
ids = append(ids, strconv.Itoa(t.Id)) | ||
} | ||
|
||
tApiUrl := GetTracksByIdsApiUrl(ids, clientId) | ||
|
||
statusCode, data, err = client.Get(tApiUrl) | ||
|
||
if err != nil || statusCode != http.StatusOK { | ||
return nil | ||
} | ||
|
||
sounds := make([]SoundData, 0) | ||
|
||
dec := json.NewDecoder(bytes.NewReader(data)) | ||
if err := dec.Decode(&sounds); err != nil { | ||
log.Println("Error decoding json: ", err) | ||
return nil | ||
} | ||
|
||
return sounds | ||
} |