{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import json\n",
    "\n",
    "from suno_utils.utils.text import read_jsonl, write_jsonl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# this is a temp cell\n",
    "# load the jsonl and export text of reliable artist ids\n",
    "filepath = \"/home/christian/code/christian/metadata/v4/metas_v0_labeled_dupes.jsonl\"\n",
    "metas = read_jsonl(filepath)\n",
    "print(len(metas))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "metas[2000000]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from tqdm import tqdm\n",
    "\n",
    "valid_artist_ids = []\n",
    "for meta in tqdm(metas):\n",
    "    if not meta[\"is_artist_duplicate\"]:\n",
    "        valid_artist_ids.append(meta[\"id\"])\n",
    "\n",
    "print(len(valid_artist_ids))\n",
    "\n",
    "# save this list to a text file\n",
    "with open(\"/home/christian/code/christian/metadata/v4/reliable_artist_ids.txt\", \"w\") as f:\n",
    "    for id in valid_artist_ids:\n",
    "        f.write(f\"{id}\\n\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# load the list of covers\n",
    "reliable_covers_filepath = \"/home/christian/code/christian/metadata/v4/reliable_cover_ids.txt\"\n",
    "with open(reliable_covers_filepath, \"r\") as f:\n",
    "    reliable_cover_ids = f.readlines()\n",
    "\n",
    "reliable_cover_ids = set([id.strip() for id in reliable_cover_ids])\n",
    "\n",
    "print(f\"{len(reliable_cover_ids):,} reliable cover ids\")\n",
    "\n",
    "# load the list of artist ids\n",
    "artist_ids_filepath = \"/home/christian/code/christian/metadata/v4/reliable_artist_ids.txt\"\n",
    "with open(artist_ids_filepath, \"r\") as f:\n",
    "    artist_ids = f.readlines()\n",
    "\n",
    "artist_ids = set([id.strip() for id in artist_ids])\n",
    "print(f\"{len(artist_ids):,} reliable artist ids\")\n",
    "\n",
    "valid_audio_ids_filepath = \"/home/christian/code/christian/metadata/v45_splits/ids_keep_sets_v11.json\"\n",
    "with open(valid_audio_ids_filepath, \"r\") as f:\n",
    "    valid_audio_ids = json.load(f)\n",
    "# collapase the keys into one list\n",
    "valid_audio_ids = set([id for ids in valid_audio_ids.values() for id in ids])\n",
    "\n",
    "print(f\"{len(valid_audio_ids):,} valid audio ids\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# this will merge three json files of ids into one json file\n",
    "# we will have a set of ids for \n",
    "# create a new dict\n",
    "valid_dict = {\n",
    "    \"audio_ids\": list(valid_audio_ids),\n",
    "    \"artist_ids\": list(artist_ids),\n",
    "    \"cover_ids\": list(reliable_cover_ids)\n",
    "}\n",
    "\n",
    "# save the new dict to a json file\n",
    "with open(\"/home/christian/code/christian/metadata/v45_splits/ids_keep_sets_ext_v11.json\", \"w\") as f:\n",
    "    json.dump(valid_dict, f)\n",
    "\n",
    "# /app/suno/data/auk_v0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "suno_env",
   "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.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
