Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
fix: replace removed release download with new track download
Browse files Browse the repository at this point in the history
  • Loading branch information
menzerath committed Oct 28, 2021
1 parent ed9360b commit 8fe5efb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions monstercat/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
)

// DownloadFormat describes in what kind of formats we can download a release
// DownloadFormat describes in what kind of formats we can download a catalog item
type DownloadFormat string

// define all known download formats
Expand All @@ -17,13 +17,13 @@ const (
DownloadReleaseFormatWAV = "wav"
)

// DownloadRelease downloads the given release as ZIP file in the requested format and stores it at the given path
func (client Client) DownloadRelease(release Release, downloadFormat DownloadFormat, downloadPath string) error {
// DownloadCatalogItem downloads the given catalog item in the requested format and stores it at the given path
func (client Client) DownloadCatalogItem(catalogItem CatalogItem, downloadFormat DownloadFormat, downloadPath string) error {
if !client.IsLoggedIn() {
return ErrorClientNotLoggedIn
}

request, err := http.NewRequest("GET", fmt.Sprintf(endpointDownloadRelease, release.ID, downloadFormat), http.NoBody)
request, err := http.NewRequest("GET", fmt.Sprintf(endpointDownloadCatalogItem, catalogItem.Release.ID, catalogItem.ID, downloadFormat), http.NoBody)
if err != nil {
return err
}
Expand Down Expand Up @@ -58,5 +58,3 @@ func (client Client) DownloadRelease(release Release, downloadFormat DownloadFor

return nil
}

// TODO: add download function for a single catalog item
2 changes: 1 addition & 1 deletion monstercat/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func Test_DownloadRelease(t *testing.T) {
client := NewClient()

err := client.DownloadRelease(Release{}, DownloadReleaseFormatMP3, "./file.zip")
err := client.DownloadCatalogItem(CatalogItem{}, DownloadReleaseFormatMP3, "./file.mp3")
assert.Error(t, err)
assert.Equal(t, ErrorClientNotLoggedIn, err)
}
2 changes: 1 addition & 1 deletion monstercat/monstercat.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const (
endpointLogin = "https://www.monstercat.com/api/sign-in"
endpointCatalog = "https://www.monstercat.com/api/catalog/browse"

endpointDownloadRelease = "https://www.monstercat.com/api/release/%s/download?format=%s"
endpointDownloadCatalogItem = "https://www.monstercat.com/api/release/%s/track-download/%s?format=%s"

authenticationCookieName = "cid"
)
Expand Down

0 comments on commit 8fe5efb

Please sign in to comment.