{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c9ea3ca5",
   "metadata": {},
   "outputs": [],
   "source": [
    "from suno_utils.utils.podcasts import load_podcast_db"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ab89d116",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = load_podcast_db(\"/mnt/data-ssd-1/data/podcasts/meta/bk_podcastindex_feeds.db\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "282d7c52",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "id                                                                      2\n",
       "url                              https://anchor.fm/s/19ccb320/podcast/rss\n",
       "title                                                 Rahdo Talks Through\n",
       "last_update                                           2022-03-23 11:06:15\n",
       "link                                            https://patreon.com/rahdo\n",
       "last_http_status                                                      200\n",
       "dead                                                                    0\n",
       "content_type                           application/rss+xml; charset=utf-8\n",
       "itunes_id                                                      1000016089\n",
       "original_url                     https://anchor.fm/s/19ccb320/podcast/rss\n",
       "itunes_author                                                 Richard Ham\n",
       "itunes_owner_name                                             Richard Ham\n",
       "explicit                                                                0\n",
       "image_url               https://d3t3ozftmdmh3i.cloudfront.net/staging/...\n",
       "itunes_type                                                      episodic\n",
       "generator                                                 Anchor Podcasts\n",
       "newest_item_pubdate                                   2022-03-23 02:31:26\n",
       "language                                                               en\n",
       "oldest_item_pubdate                                   2015-05-31 03:00:00\n",
       "episode_count                                                         217\n",
       "popularity_score                                                        1\n",
       "priority                                                                2\n",
       "created_on                                            2020-08-06 22:21:27\n",
       "update_frequency                                                        1\n",
       "chash                                    f9fce8424a9918be9182c2d67fc51c16\n",
       "host                                                            anchor.fm\n",
       "newest_enclosure_url    https://anchor.fm/s/19ccb320/podcast/play/4946...\n",
       "podcast_guid                         655b4e1a-4deb-56a2-9256-cad10f099410\n",
       "Name: 1, dtype: object"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "39b19d0e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "id                                                                      1\n",
       "url                               https://markalanwilliams.libsyn.com/rss\n",
       "title                                  Christianity Questions and Answers\n",
       "last_update                                           2021-11-11 04:08:49\n",
       "link                           http://markalanwilliams.libsyn.com/webpage\n",
       "last_http_status                                                      200\n",
       "dead                                                                    0\n",
       "content_type                           application/rss+xml; charset=utf-8\n",
       "itunes_id                                                      1435175190\n",
       "original_url                      https://markalanwilliams.libsyn.com/rss\n",
       "itunes_author                                      Dr. Mark Alan Williams\n",
       "itunes_owner_name                                           Mark Williams\n",
       "explicit                                                                0\n",
       "image_url               https://ssl-static.libsyn.com/p/assets/e/7/5/d...\n",
       "itunes_type                                                      episodic\n",
       "generator                                            Libsyn WebEngine 2.0\n",
       "newest_item_pubdate                                   2021-01-09 21:13:35\n",
       "language                                                               en\n",
       "oldest_item_pubdate                                   2015-05-28 18:25:32\n",
       "episode_count                                                          90\n",
       "popularity_score                                                        0\n",
       "priority                                                               -1\n",
       "created_on                                            2020-08-06 22:21:27\n",
       "update_frequency                                                        8\n",
       "chash                                    52ad7fcfa9cf5e7e2b5abf9c1ee6da85\n",
       "host                                                           libsyn.com\n",
       "newest_enclosure_url    https://traffic.libsyn.com/secure/markalanwill...\n",
       "podcast_guid                         78e9f51b-0ac3-5711-a921-1f2c7b5dbb35\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "25f2d08a",
   "metadata": {},
   "outputs": [],
   "source": [
    "PARSED_FEEDS_DIR = \"/mnt/data-ssd-1/data/podcasts/bulk_rss_feeds/parsed_feeds/\"\n",
    "filepaths = "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7b672813",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import json\n",
    "import multiprocessing\n",
    "\n",
    "\n",
    "def foo(filepath):\n",
    "    with open(filepath) as f:\n",
    "        feed_info = json.load(f)\n",
    "    podcast_id = filepath.split(\"/\")[-1].split(\".\")[0]\n",
    "    if (str(feed_info.get(\"language\")).lower() == \"en-in\") or (\"hinglish\" in str(feed_info).lower()):\n",
    "        return podcast_id, feed_info\n",
    "    return None\n",
    "\n",
    "\n",
    "FEED_DIR = \"/mnt/data-ssd-1/data/podcasts/bulk_rss_feeds/parsed_feeds/\"\n",
    "filepaths = [os.path.join(FEED_DIR, filename) for filename in os.listdir(FEED_DIR)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "981f7e8a",
   "metadata": {},
   "outputs": [],
   "source": [
    "p = multiprocessing.Pool(20)\n",
    "out = p.map(foo, filepaths, chunksize=100)\n",
    "out = [e for e in out if e is not None]\n",
    "p.close()\n",
    "p.join()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2c6eda9d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5685203a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4121bc9b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2b8a43d0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
