Skip to content

Commit 1f43c9c

Browse files
committed
Add support for --without-wget arg
1 parent c115825 commit 1f43c9c

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# monstercat-dl
1+
# :musical_note: monstercat-dl
22

33
Download Monstercat songs from your Terminal app!
44

@@ -8,6 +8,8 @@ To get monstercat-dl working correctly, you will need this:
88
- [wget](https://www.gnu.org/software/wget/) (on macOS `brew install wget`)
99
- [php](https://php.net) >= 7.0
1010

11+
:warning: If you don't want to use `wget` and prefer `php` native functions, use `--without-get` argument.
12+
1113
## Usage
1214

1315
First, browse [monstercat.com](https://www.monstercat.com) and find the release you wish to download.
@@ -20,12 +22,12 @@ We just need the release ID, in this case: `MCEP157`.
2022
Download all songs in this release with this simple command:
2123

2224
```bash
23-
php monstercat-dl.php MCEP157
25+
php monstercat-dl.phar MCEP157
2426
```
2527

2628
You can download more songs at once by adding other release IDs at the end of the command:
2729
```bash
28-
php monstercat-dl.php MCEP157 MCX006 MCS778
30+
php monstercat-dl.phar MCEP157 MCX006 MCS778
2931
```
3032

3133
All songs will be downloaded in your current directory, you can `cd` into another one.

src/monstercat-dl.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function getAlbum(string $key): Array
5151
function ($key) { return is_numeric($key); },
5252
ARRAY_FILTER_USE_KEY
5353
);
54+
$blobs = [];
5455

5556
foreach ($releases as $key => $releaseID) {
5657
$release = new Release($releaseID);
@@ -63,8 +64,29 @@ function ($key) { return is_numeric($key); },
6364

6465
if ($album->getStatus() === 200) {
6566
foreach ($album->getMusics() as $music) {
66-
exec("wget " . $music->getDownloadLink() . " -O \"" . $music->getFileName() . ".mp3\"");
67+
$blobs[$music->getFileName()] = $music->getDownloadLink();
68+
echo ' - ' . $music->getFileName() . PHP_EOL;
6769
}
6870
}
6971
}
72+
73+
echo PHP_EOL;
74+
}
75+
76+
foreach ($blobs as $name => $url) {
77+
if (isset($args['without-wget'])) {
78+
echo "[Downloading] `$name`... ";
79+
if (
80+
file_put_contents(
81+
$name . '.mp3',
82+
file_get_contents($url)
83+
)
84+
) {
85+
echo 'Ok' . PHP_EOL;
86+
} else {
87+
echo 'FAILED' . PHP_EOL;
88+
}
89+
} else {
90+
exec("wget $url -O \"$name.mp3\"");
91+
}
7092
}

0 commit comments

Comments
 (0)