{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import random\n",
    "from tqdm import tqdm\n",
    "from suno_utils.utils.text import read_jsonl, write_jsonl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "datasets = [(\"youtube_music\", None),  (\"genius_hq\", None),  (\"imslp\", 1000), (\"jamendo\", 1000), (\"pond5_music\", 2000), (\"ytm_tagged\", 2000)]\n",
    "new_dataset_metas = []\n",
    "for dataset, max_duration_hr in datasets:\n",
    "    print(\"Processing dataset: {}\".format(dataset))\n",
    "    dataset_metas = read_jsonl(\"/home/christian/code/christian/metadata/{}_metas.jsonl\".format(dataset))\n",
    "    metas_indices = list(range(len(dataset_metas)))\n",
    "    # shuffle\n",
    "    random.shuffle(metas_indices)\n",
    "\n",
    "    total_duration_hr = 0\n",
    "    pbar = tqdm(metas_indices)\n",
    "    for idx in pbar:\n",
    "        meta = dataset_metas[idx]\n",
    "        duration_s = meta.get(\"duration_s\", None)\n",
    "        if duration_s is not None:\n",
    "            total_duration_hr += duration_s / 3600\n",
    "\n",
    "        new_meta = meta\n",
    "        new_meta[\"dataset\"] = dataset\n",
    "        new_dataset_metas.append(new_meta)\n",
    "        \n",
    "        pbar.set_description(f\"Total duration: {total_duration_hr:0.0f} hr\")\n",
    "        \n",
    "        if max_duration_hr is not None and total_duration_hr > max_duration_hr:\n",
    "            break\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "write_jsonl(\"/home/christian/code/christian/metadata/diffison_mix/metas.jsonl\", new_dataset_metas)"
   ]
  }
 ],
 "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
}
