Skip to content

Commit

Permalink
fix: handle file feeds with missing 'feedUrl'
Browse files Browse the repository at this point in the history
fixes #87
  • Loading branch information
lightpohl committed Nov 1, 2024
1 parent 5d12ebe commit 1e6b89a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
6 changes: 3 additions & 3 deletions bin/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const download = async (options) => {
const downloadItemsAsync = async ({
addMp3MetadataFlag,
archive,
archiveUrl,
archivePrefix,
attempts,
basePath,
bitrate,
Expand Down Expand Up @@ -215,7 +215,7 @@ const downloadItemsAsync = async ({
alwaysPostprocess,
marker,
key: getArchiveKey({
prefix: archiveUrl,
prefix: archivePrefix,
name: getArchiveFilename({
name: item.title,
pubDate: item.pubDate,
Expand Down Expand Up @@ -300,7 +300,7 @@ const downloadItemsAsync = async ({
override,
item,
key: getArchiveKey({
prefix: archiveUrl,
prefix: archivePrefix,
name: getArchiveFilename({
pubDate: item.pubDate,
name: item.title,
Expand Down
19 changes: 13 additions & 6 deletions bin/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,15 @@ const main = async () => {
? await getUrlFeed(url, parserConfig)
: await getFileFeed(file, parserConfig);

const { hostname, pathname } = new URL(feed.feedUrl || url);
const archiveUrl = `${hostname}${pathname}`;
const archivePrefix = (() => {
if (feed.feedUrl || url) {
const { hostname, pathname } = new URL(feed.feedUrl || url);
return `${hostname}${pathname}`;
}

return feed.title || file;
})();

const basePath = _path.resolve(
process.cwd(),
getFolderName({ feed, template: outDir })
Expand Down Expand Up @@ -152,7 +159,7 @@ const main = async () => {
override,
marker: podcastImageUrl,
key: getArchiveKey({
prefix: archiveUrl,
prefix: archivePrefix,
name: `${
feed.title ? `${feed.title}.image` : "image"
}${podcastImageFileExt}`,
Expand Down Expand Up @@ -181,7 +188,7 @@ const main = async () => {
override,
feed,
key: getArchiveKey({
prefix: archiveUrl,
prefix: archivePrefix,
name: `${feed.title ? `${feed.title}.meta` : "meta"}.json`,
}),
outputPath: outputMetaPath,
Expand All @@ -201,7 +208,7 @@ const main = async () => {

const targetItems = getItemsToDownload({
archive,
archiveUrl,
archivePrefix,
basePath,
feed,
limit,
Expand Down Expand Up @@ -231,7 +238,7 @@ const main = async () => {
const { numEpisodesDownloaded, hasErrors } = await downloadItemsAsync({
addMp3MetadataFlag,
archive,
archiveUrl,
archivePrefix,
attempts,
basePath,
bitrate,
Expand Down
8 changes: 4 additions & 4 deletions bin/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const getLoopControls = ({ offset, length, reverse }) => {

const getItemsToDownload = ({
archive,
archiveUrl,
archivePrefix,
basePath,
feed,
limit,
Expand Down Expand Up @@ -216,7 +216,7 @@ const getItemsToDownload = ({
const { url: episodeAudioUrl, ext: audioFileExt } =
getEpisodeAudioUrlAndExt(feed.items[i], episodeSourceOrder);
const key = getArchiveKey({
prefix: archiveUrl,
prefix: archivePrefix,
name: getArchiveFilename({
pubDate,
name: title,
Expand All @@ -239,7 +239,7 @@ const getItemsToDownload = ({
if (episodeImageUrl) {
const episodeImageFileExt = getUrlExt(episodeImageUrl);
const episodeImageArchiveKey = getArchiveKey({
prefix: archiveUrl,
prefix: archivePrefix,
name: getArchiveFilename({
pubDate,
name: title,
Expand Down Expand Up @@ -276,7 +276,7 @@ const getItemsToDownload = ({
if (episodeTranscriptUrl) {
const episodeTranscriptFileExt = getUrlExt(episodeTranscriptUrl);
const episodeTranscriptArchiveKey = getArchiveKey({
prefix: archiveUrl,
prefix: archivePrefix,
name: getArchiveFilename({
pubDate,
name: title,
Expand Down

0 comments on commit 1e6b89a

Please sign in to comment.