{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/christian/code/christian/metadata/v4/discogs_subset_metas_v0.jsonl\n",
      "2916657\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 2916657/2916657 [00:06<00:00, 436343.52it/s] "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of metas with tags: 1972698\n",
      "Number of metas with lyrics: 2199518\n",
      "Average number of tags per meta: 7.99675469838769\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "# v4 metas\n",
    "# we will audit the tags in the metas\n",
    "from tqdm import tqdm\n",
    "from suno_utils.utils.text import read_jsonl\n",
    "\n",
    "\n",
    "version = \"v0\"\n",
    "\n",
    "meta_filepaths = [\n",
    "    #f\"/home/christian/code/christian/metadata/v4/imslp_metas_{version}.jsonl\",\n",
    "    #f\"/home/christian/code/christian/metadata/v4/genius_metas_{version}.jsonl\",\n",
    "    f\"/home/christian/code/christian/metadata/v4/discogs_subset_metas_{version}.jsonl\",\n",
    "    #f\"/home/christian/code/christian/metadata/v4/youtube_music_metas_{version}.jsonl\",\n",
    "]\n",
    "\n",
    "complete_tag_list = []\n",
    "\n",
    "for meta_filepath in meta_filepaths:\n",
    "    print(meta_filepath)\n",
    "    metas = read_jsonl(meta_filepath)\n",
    "    print(len(metas))\n",
    "\n",
    "    tag_count = 0\n",
    "    tags_count = 0\n",
    "    lyric_count = 0\n",
    "    # count how many metas have any tags\n",
    "    for meta in tqdm(metas):\n",
    "        tags_text = meta.get(\"tags_text\", [])\n",
    "        if len(tags_text) < 1:\n",
    "            tags_text = meta.get(\"tags\", [])\n",
    "        if len(tags_text) > 0:\n",
    "            tag_count += 1\n",
    "            tags_count += len(tags_text)\n",
    "\n",
    "        complete_tag_list.append(tags_text)\n",
    "\n",
    "        lyrics = meta.get(\"text\", [])\n",
    "        if len(lyrics) > 0:\n",
    "            lyric_count += 1\n",
    "\n",
    "    print(f\"Number of metas with tags: {tag_count}\")\n",
    "    print(f\"Number of metas with lyrics: {lyric_count}\")\n",
    "    if tag_count > 0:\n",
    "        print(f\"Average number of tags per meta: {tags_count / tag_count}\")\n",
    "    else:\n",
    "        print(\"No metas with tags\")\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "metas = read_jsonl(f\"/home/christian/code/christian/metadata/v4/discogs_subset_metas_{version}.jsonl\")\n",
    "print(len(metas))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# save complete_tag_list\n",
    "with open(\"/home/christian/code/christian/metadata/v45_complete_tag_list.json\", \"w\") as fp:\n",
    "    json.dump(complete_tag_list, fp)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "tag_filepath = \"/home/christian/code/christian/metadata/v45_tags_counter.json\"\n",
    "\n",
    "with open(tag_filepath, \"r\") as fp:\n",
    "    tags = json.load(fp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4972238\n"
     ]
    }
   ],
   "source": [
    "print(len(tags))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# short tags\n",
    "short_tags = [tag for tag in tags.keys() if len(tag) < 16]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Random tags:\n",
      "restful spa: 1\n",
      "almglocken: 1\n",
      "rough: 12145\n"
     ]
    }
   ],
   "source": [
    "# sample three random tags\n",
    "import random\n",
    "\n",
    "sample_tags = random.sample(list(short_tags), 3)\n",
    "print(\"Random tags:\")\n",
    "for tag in sample_tags:\n",
    "    print(f\"{tag}: {tags[tag]}\")\n"
   ]
  },
  {
   "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
}
