Skip to content

Commit 4998154

Browse files
committed
Update for the V2 API
1 parent e4a070e commit 4998154

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

Diff for: src/app/Monstercat/Music.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ class Music
66
{
77
private $title;
88
private $artist;
9-
private $album;
10-
private $hash;
9+
private $releaseId;
10+
private $trackId;
1111

12-
public function __construct(string $title, string $artist, string $album, string $hash)
12+
public function __construct(string $title, string $artist, string $releaseId, string $trackId)
1313
{
1414
$this->title = $title;
1515
$this->artist = $artist;
16-
$this->album = $album;
17-
$this->hash = $hash;
16+
$this->releaseId = $releaseId;
17+
$this->trackId = $trackId;
1818
}
1919

2020
/**
@@ -32,6 +32,6 @@ public function getFileName(): string
3232
*/
3333
public function getDownloadLink(): string
3434
{
35-
return "https://blobcache.monstercat.com/blobs/$this->hash";
35+
return "https://connect.monstercat.com/v2/release/$this->releaseId/track-stream/$this->trackId";
3636
}
3737
}

Diff for: src/app/Monstercat/Release.php

+22-4
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,25 @@ class Release
1010
private $title;
1111
private $renderedArtists;
1212
private $status;
13+
private $tracks = [];
1314

1415
public function __construct(string $catalogId)
1516
{
1617
$data = $this->getInfo($catalogId);
1718

1819
if (sizeof($data) > 0) {
19-
$this->id = $data['_id'];
20-
$this->title = $data['title'];
21-
$this->renderedArtists = $data['renderedArtists'];
20+
$this->id = $data['release']['id'];
21+
$this->title = $data['release']['title'];
22+
$this->renderedArtists = $data['release']['artistsTitle'];
23+
24+
foreach ($data['tracks'] as $track) {
25+
$this->tracks[] = new Music(
26+
$track['title'],
27+
$track['artistsTitle'],
28+
$data['release']['id'],
29+
$track['id']
30+
);
31+
}
2232
} else {
2333
echo "Error while gettin $catalogId information: code ${$this->status}" . PHP_EOL;
2434
}
@@ -32,7 +42,7 @@ private function getInfo(string $catalogId): Array
3242
{
3343
$url = new Url();
3444
$result = json_decode(
35-
$url->get("https://connect.monstercat.com/api/catalog/release/$catalogId"),
45+
$url->get("https://connect.monstercat.com/v2/catalog/release/$catalogId"),
3646
true
3747
);
3848

@@ -54,6 +64,14 @@ public function getId(): string
5464
return $this->id;
5565
}
5666

67+
/**
68+
* Return found tracks
69+
*/
70+
public function getTracks(): array
71+
{
72+
return $this->tracks;
73+
}
74+
5775
/**
5876
* Get the release name
5977
* @return string The release name

Diff for: src/monstercat-dl.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ function ($key) { return is_numeric($key); },
6060
echo '[FOUND] ' . $release->getTitle() . ' - ' .
6161
$release->getRenderedArtists() . PHP_EOL;
6262

63-
$album = new Album($release->getId(), $release->getTitle());
63+
$tracks = $release->getTracks();
6464

65-
if ($album->getStatus() === 200) {
66-
foreach ($album->getMusics() as $music) {
67-
$blobs[$music->getFileName()] = $music->getDownloadLink();
68-
echo ' - ' . $music->getFileName() . PHP_EOL;
69-
}
65+
foreach ($tracks as $track) {
66+
$blobs[$track->getFileName()] = $track->getDownloadLink();
67+
echo ' - ' . $track->getFileName() . PHP_EOL;
7068
}
7169
}
7270

0 commit comments

Comments
 (0)