Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/TemplateEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { plugin } from "src/store";
import { get } from "svelte/store";
import type { Episode } from "src/types/Episode";
import getUrlExtension from "./utility/getUrlExtension";
import { formatDate } from "./utility/formatDate";

type TagValue = string | ((...args: string[]) => string);

Expand Down Expand Up @@ -103,7 +104,7 @@ export function NoteTemplateEngine(template: string, episode: Episode) {
addTag("url", episode.url);
addTag("date", (format?: string) =>
episode.episodeDate
? window.moment(episode.episodeDate).format(format ?? "YYYY-MM-DD")
? formatDate(episode.episodeDate, format ?? "YYYY-MM-DD")
: "",
);
addTag(
Expand Down Expand Up @@ -153,7 +154,7 @@ export function FilePathTemplateEngine(template: string, episode: Episode) {
});
addTag("date", (format?: string) =>
episode.episodeDate
? window.moment(episode.episodeDate).format(format ?? "YYYY-MM-DD")
? formatDate(episode.episodeDate, format ?? "YYYY-MM-DD")
: "",
);

Expand Down Expand Up @@ -189,7 +190,7 @@ export function DownloadPathTemplateEngine(template: string, episode: Episode) {
});
addTag("date", (format?: string) =>
episode.episodeDate
? window.moment(episode.episodeDate).format(format ?? "YYYY-MM-DD")
? formatDate(episode.episodeDate, format ?? "YYYY-MM-DD")
: "",
);

Expand Down Expand Up @@ -221,7 +222,7 @@ export function TranscriptTemplateEngine(
});
addTag("date", (format?: string) =>
episode.episodeDate
? window.moment(episode.episodeDate).format(format ?? "YYYY-MM-DD")
? formatDate(episode.episodeDate, format ?? "YYYY-MM-DD")
: "",
);
addTag("transcript", transcription);
Expand Down
36 changes: 27 additions & 9 deletions src/iTunesAPIConsumer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { requestUrl } from "obsidian";
import type { PodcastFeed } from "./types/PodcastFeed";
import { requestWithTimeout, NetworkError } from "./utility/networkRequest";

interface iTunesResult {
collectionName: string;
feedUrl: string;
artworkUrl100: string;
collectionId: string;
}

interface iTunesSearchResponse {
results: iTunesResult[];
}

export async function queryiTunesPodcasts(query: string): Promise<PodcastFeed[]> {
const url = new URL("https://itunes.apple.com/search?");
Expand All @@ -8,13 +19,20 @@ export async function queryiTunesPodcasts(query: string): Promise<PodcastFeed[]>
url.searchParams.append("limit", "3");
url.searchParams.append("kind", "podcast");

const res = await requestUrl({ url: url.href });
const data = res.json.results;
try {
const response = await requestWithTimeout(url.href, { timeoutMs: 15000 });
const data = response.json as iTunesSearchResponse;

return data.map((d: { collectionName: string, feedUrl: string, artworkUrl100: string, collectionId: string }) => ({
title: d.collectionName,
url: d.feedUrl,
artworkUrl: d.artworkUrl100,
collectionId: d.collectionId
}));
return (data.results || []).map((d) => ({
title: d.collectionName,
url: d.feedUrl,
artworkUrl: d.artworkUrl100,
collectionId: d.collectionId,
}));
} catch (error) {
if (error instanceof NetworkError) {
console.error(`iTunes search failed: ${error.message}`);
}
return [];
}
}
7 changes: 7 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
hidePlayedEpisodes,
volume,
} from "src/store";
import { blobUrlManager } from "src/utility/createMediaUrlObjectFromFilePath";
import { Plugin, type WorkspaceLeaf } from "obsidian";
import { API } from "src/API/API";
import type { IAPI } from "src/API/IAPI";
Expand Down Expand Up @@ -374,6 +375,12 @@ export default class PodNotes extends Plugin implements IPodNotes {
this.currentEpisodeController?.off();
this.hidePlayedEpisodesController?.off();
this.volumeUnsubscribe?.();

// Clean up any active blob URLs to prevent memory leaks
blobUrlManager.revokeAll();

// Detach all leaves of this view type to prevent duplicates on reload
this.app.workspace.detachLeavesOfType(VIEW_TYPE);
}

async loadSettings() {
Expand Down
25 changes: 18 additions & 7 deletions src/opml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { get } from "svelte/store";
function TimerNotice(heading: string, initialMessage: string) {
let currentMessage = initialMessage;
const startTime = Date.now();
let stopTime: number;
let stopTime: number | undefined;
let intervalId: ReturnType<typeof setInterval> | undefined;
const notice = new Notice(initialMessage, 0);

function formatMsg(message: string): string {
Expand All @@ -19,20 +20,30 @@ function TimerNotice(heading: string, initialMessage: string) {
notice.setMessage(formatMsg(currentMessage));
}

const interval = setInterval(() => {
notice.setMessage(formatMsg(currentMessage));
}, 1000);

function getTime(): string {
return formatTime(stopTime ? stopTime - startTime : Date.now() - startTime);
}

function clearTimer() {
if (intervalId !== undefined) {
clearInterval(intervalId);
intervalId = undefined;
}
}

intervalId = setInterval(() => {
notice.setMessage(formatMsg(currentMessage));
}, 1000);

return {
update,
hide: () => notice.hide(),
hide: () => {
clearTimer();
notice.hide();
},
stop: () => {
stopTime = Date.now();
clearInterval(interval);
clearTimer();
},
};
}
Expand Down
Loading