Skip to content

Commit

Permalink
Merge pull request SwapnilSoni1999#259 from phyzical/feature/fix-fall…
Browse files Browse the repository at this point in the history
…back

Fix fallback image
  • Loading branch information
phyzical authored Aug 26, 2024
2 parents 9956d80 + f66cd3b commit 5ed5fe8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 44 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Get [FFMPEG](https://ffmpeg.org/download.html)

[Node.js 18](https://nodejs.org/en/download/package-manager/)

[git not windows](https://formulae.brew.sh/formula/git)
or
[git for windows](https://git-scm.com/download/win)

Note: if you run into issues related to puppeteer chromium download please try `PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm install -g spotify-dl`

#### spotifydl
Expand All @@ -32,8 +36,6 @@ PLEASE NOTE:

#### NPM

Install from [npm](https://www.npmjs.com/package/spotify-dl) registry

```sh
npm install -g https://github.com/swapnilsoni1999/spotify-dl
```
Expand All @@ -57,8 +59,6 @@ sh -c "$(curl -fsSL https://raw.githubusercontent.com/SwapnilSoni1999/spotify-dl

#### Docker



```sh
docker run ghcr.io/swapnilsoni1999/spotify-dl
```
Expand All @@ -71,7 +71,6 @@ cd spotify-dl
docker build -t spotify-dl .
```


<hr>

# Usage
Expand Down
32 changes: 14 additions & 18 deletions lib/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,27 @@ const downloadAndSaveCover = function (uri, filename) {
const mergeMetadata = async (output, songData) => {
const coverFileName = output.slice(0, output.length - 3) + 'jpg';
let coverURL = songData.cover_url;
if (!coverURL) {
coverURL = Constants.YOUTUBE_SEARCH.GENERIC_IMAGE;
}

try {
await downloadAndSaveCover(coverURL, coverFileName);
} catch (_e) {
// image is corrupt or not available try again
logInfo('Album Thumbnail corrupt attempting again');
if (coverURL) {
try {
await downloadAndSaveCover(coverURL, coverFileName);
} catch (_e2) {
// if it fails again just fallback to generic image
logInfo(
'Album Thumbnail corrupt for second time fallback to generic image',
);
} catch (_e) {
// image is corrupt or not available try again
logInfo('Album Thumbnail corrupt attempting again');
try {
await downloadAndSaveCover(coverURL, coverFileName);
} catch (_e2) {
// if it fails again just fallback to generic image
logInfo(
'Album Thumbnail corrupt for second time fallback to generic image',
);
}
}
}

if (!fs.existsSync(coverFileName)) {
await downloadAndSaveCover(
'https://i.ibb.co/PN87XDk/unknown.jpg',
coverFileName,
);
fs.copyFileSync(Constants.YOUTUBE_SEARCH.GENERIC_IMAGE, coverFileName);
}

const dateSplits = splitDates(songData.release_date);
const firstArtist =
songData.artists && songData.artists.length > 0 ? songData.artists[0] : '';
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@swapnilsoni1999/spotify-dl",
"productName": "Spotify Downloader",
"version": "1.2.2",
"version": "1.2.3",
"description": "Spotify Songs, Playlist & Album Downloader",
"main": "app.js",
"bin": {
Expand Down Expand Up @@ -38,7 +38,7 @@
"spotify-web-api-node": "^5.0.0",
"string-similarity": "^4.0.4",
"yt-search": "^2.10.3",
"@distube/ytdl-core": "^4.13.5"
"@distube/ytdl-core": "^4.14.4"
},
"xo": {
"space": true,
Expand All @@ -55,4 +55,4 @@
"prettier": "^2.7.1",
"xo": "^0.56.0"
}
}
}
7 changes: 3 additions & 4 deletions util/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from 'path';

export default {
AUTH: {
SCOPES: {
Expand Down Expand Up @@ -52,10 +54,7 @@ export default {
YOUTUBE_SEARCH: {
// this roughly equates to a max of 30mb
MAX_MINUTES: 15,
GENERIC_IMAGE:
'https://lh3.googleusercontent.com/z6Sl4j9zQ88oUKN' +
'y0G3PAMiVwy8DzQLh_ygyvBXv0zVNUZ_wQPN_n7EAR2By3dhoUpX7kTpaHjRP' +
'ni1MHwKpaBJbpNqdEsHZsH4q',
GENERIC_IMAGE: path.join(process.cwd(), "logo.png"),
VALID_CONTEXTS: ['itemName', 'albumName', 'artistName'],
},
};

0 comments on commit 5ed5fe8

Please sign in to comment.