Skip to content

Commit

Permalink
fix: prevent podcast images from downloading if already archived
Browse files Browse the repository at this point in the history
closes #39
  • Loading branch information
lightpohl committed Apr 11, 2022
1 parent e7c189b commit c1a7440
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
6 changes: 6 additions & 0 deletions bin/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
writeItemMeta,
writeToArchive,
getUrlEmbed,
getIsInArchive,
} from "./util.js";

const pipeline = promisify(stream.pipeline);
Expand All @@ -44,6 +45,11 @@ const download = async ({
return;
}

if (key && archive && getIsInArchive({ key, archive })) {
logMessage("Download exists in archive. Skipping...");
return;
}

let embeddedUrl = null;
if (filterUrlTracking) {
logMessage("Attempting to find embedded URL...");
Expand Down
42 changes: 18 additions & 24 deletions bin/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,22 +215,20 @@ const getItemsToDownload = ({
}),
});

if (!savedArchive.includes(episodeImageArchiveKey)) {
const episodeImageName = getFilename({
item,
feed,
url: episodeAudioUrl,
ext: episodeImageFileExt,
template: episodeTemplate,
});

const outputImagePath = path.resolve(basePath, episodeImageName);
item._extra_downloads.push({
url: episodeImageUrl,
outputPath: outputImagePath,
key: episodeImageArchiveKey,
});
}
const episodeImageName = getFilename({
item,
feed,
url: episodeAudioUrl,
ext: episodeImageFileExt,
template: episodeTemplate,
});

const outputImagePath = path.resolve(basePath, episodeImageName);
item._extra_downloads.push({
url: episodeImageUrl,
outputPath: outputImagePath,
key: episodeImageArchiveKey,
});
}
}

Expand Down Expand Up @@ -295,7 +293,7 @@ const logItemsList = ({

const writeFeedMeta = ({ outputPath, feed, key, archive, override }) => {
if (key && archive && getIsInArchive({ key, archive })) {
logMessage("Feed metadata exists in archive. Skipping write...");
logMessage("Feed metadata exists in archive. Skipping...");
return;
}

Expand All @@ -312,7 +310,7 @@ const writeFeedMeta = ({ outputPath, feed, key, archive, override }) => {
if (override || !fs.existsSync(outputPath)) {
fs.writeFileSync(outputPath, JSON.stringify(output, null, 4));
} else {
logMessage("Feed metadata exists locally. Skipping write...");
logMessage("Feed metadata exists locally. Skipping...");
}

if (key && archive && !getIsInArchive({ key, archive })) {
Expand All @@ -338,9 +336,7 @@ const writeItemMeta = ({
override,
}) => {
if (key && archive && getIsInArchive({ key, archive })) {
logMessage(
`${marker} | Episode metadata exists in archive. Skipping write...`
);
logMessage(`${marker} | Episode metadata exists in archive. Skipping...`);
return;
}

Expand All @@ -355,9 +351,7 @@ const writeItemMeta = ({
if (override || !fs.existsSync(outputPath)) {
fs.writeFileSync(outputPath, JSON.stringify(output, null, 4));
} else {
logMessage(
`${marker} | Episode metadata exists locally. Skipping write...`
);
logMessage(`${marker} | Episode metadata exists locally. Skipping...`);
}

if (key && archive && !getIsInArchive({ key, archive })) {
Expand Down

0 comments on commit c1a7440

Please sign in to comment.