「なに聴く」でポッドキャストを聴く

  • 投稿:
  • 更新:2026年9月 3日
  • by
  • in

th_Gemini_Generated_Image_wj723awj723awj72.png

ポッドキャストサービスの「Podmean」と Google Apps Script(GAS)を利用して、「なに聴く」でポッドキャストを聴く方法です。
Podmean はアプリとしても利用できますが、RSSで番組の情報を公開しているので、このRSSをGASに食わせて、GoogleDriveに番組をダウンロードできます。
とりあえず、以下にスクリプトを載せておくので、必要なRSSのURLとGoogleDriveのファイルIDを設定すれば動きます。(PODCAST_FEEDSは適当に編集してください)
定期実行に設定すれば、自動でGoogleDriveの指定フォルダに最新の番組がダウンロードされます。

RSSは Podmean にログインして、対象の番組を表示するとTOPのバナー部分にURLの表示(最後が.rss で終わっているURL)があります。

GoogleDriveのフォルダIDは、GoogleDriveでそのフォルダを開いた時のURLの一番最後の「/」スラッシュ以下がフォルダIDになります。

// 【設定】RSSフィードのURLと、保存先GoogleドライブのフォルダIDを指定
const PODCAST_FEEDS = [
 {
 name: "大久保佳代子とらぶぶらLOVE",
 url: "https://feeds.megaphone.fm/TBS5907234265",
 folderId: "ここに自分のGoogleDriveのフォルダIDを設定"
 },
 {
 name: "TENGA茶屋",
 url: "https://feed.sonicbowl.cloud/rss/c9efdf20-a543-4db4-bc5b-fe1d42323a0b/",
 folderId: "ここに自分のGoogleDriveのフォルダIDを設定"
 },
 {
 name: "OVER THE SUN",
 url: "https://feeds.megaphone.fm/TBS3429819532",
 folderId: "ここに自分のGoogleDriveのフォルダIDを設定"
 }
];
function checkAndDownloadPodcasts() {
 const properties = PropertiesService.getScriptProperties();
 PODCAST_FEEDS.forEach(feed => {
 try {
 // 1. RSSフィードを取得
 const response = UrlFetchApp.fetch(feed.url);
 const xml = response.getContentText();
 const document = XmlService.parse(xml);
 const root = document.getRootElement();
 const channel = root.getChild('channel');
 const items = channel.getChildren('item');
 // フィードにエピソードが1つもない場合はスキップ
 if (items.length === 0) return;
 // 2. 最も新しいエピソード(先頭のitem)のみを取得
 const latestItem = items[0];
 const title = latestItem.getChildText('title');
 const guid = latestItem.getChildText('guid') || latestItem.getChildText('link'); // 重複判定用ID
 // 音声ファイルのURL(enclosureタグ)を取得
 const enclosure = latestItem.getChild('enclosure');
 if (!enclosure) return;
 const mp3Url = enclosure.getAttribute('url').getValue();
 // すでにダウンロード済みかチェック
 if (properties.getProperty(guid)) {
 Logger.log(`[${feed.name}] 最新エピソードは保存済みです: ${title}`);
 return; // 保存済みなら何もせず終了
 }
 Logger.log(`新規エピソードを発見。ダウンロード開始 [${feed.name}]: ${title}`);
 Logger.log(`MP3 URL [${mp3Url}`);
 // 3. MP3ファイルをダウンロードしてGoogleドライブに保存
 const folder = DriveApp.getFolderById(feed.folderId);
 const mp3Response = UrlFetchApp.fetch(mp3Url);
 const blob = mp3Response.getBlob().setName(`${title}.mp3`);
 folder.createFile(blob);
 // 4. 保存済みとして記録(Key-Valueストア)
 properties.setProperty(guid, "downloaded");
 } catch (e) {
 Logger.log(`エラー [${feed.name}]: ${e.toString()}`);
 }
 });
}