Skip to content

Commit

Permalink
bump yt-dl version, use the logo png ass fallback image instead of ra…
Browse files Browse the repository at this point in the history
…ndom remote image
  • Loading branch information
phyzical committed Aug 26, 2024
1 parent 9956d80 commit e9d08fe
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 39 deletions.
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 e9d08fe

Please sign in to comment.