{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0",
   "metadata": {},
   "outputs": [],
   "source": [
    "from suno_utils.utils.text import read_jsonl, write_jsonl\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {},
   "outputs": [],
   "source": [
    "artists_df = pd.read_csv(\"/home/sara/rateyourmusic/artists.csv\")\n",
    "albums_df = pd.read_csv(\"/home/sara/rateyourmusic/albums.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2",
   "metadata": {},
   "outputs": [],
   "source": [
    "albums_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3",
   "metadata": {},
   "outputs": [],
   "source": [
    "mashup_artsts = artists_df[artists_df[\"Genres\"].str.lower().str.contains(\"mashup\", na=False)]\n",
    "print(len(mashup_artsts))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4",
   "metadata": {},
   "outputs": [],
   "source": [
    "mashup_albums = albums_df[albums_df[\"Genres\"].str.lower().str.contains(\"mashup\", na=False)]\n",
    "print(len(mashup_albums))\n",
    "mashup_albums.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5",
   "metadata": {},
   "outputs": [],
   "source": [
    "final_rows = []\n",
    "\n",
    "def clean_string(s):\n",
    "    \"\"\"Remove all quotes from the string\"\"\"\n",
    "    s = s.strip()\n",
    "    s = s.replace('\"', '').replace(\"'\", '')\n",
    "    return s\n",
    "\n",
    "for idx, row in mashup_albums.iterrows():\n",
    "    # Clean up album name\n",
    "    album_name = clean_string(str(row['Album Name']))\n",
    "    artist_name = clean_string(str(row['Artist']))\n",
    "    genre = ', '.join(clean_string(str(row['Genres'])).split(','))\n",
    "    youtube_id = row['YouTube Id']\n",
    "    \n",
    "    # Split and clean up tracks\n",
    "    if pd.notna(row['Tracks']):\n",
    "        tracks = [clean_string(track) for track in str(row['Tracks']).split(',')]\n",
    "    else:\n",
    "        tracks = []\n",
    "\n",
    "    for t in tracks:\n",
    "        meta_row = dict(\n",
    "            title=t,\n",
    "            artist=artist_name,\n",
    "            genre=genre,\n",
    "            album=album_name\n",
    "        )\n",
    "        final_rows.append(meta_row)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import re\n",
    "\n",
    "# Fix genre formatting - add comma before \"Mashup\" if missing\n",
    "for row in final_rows:\n",
    "    genre = row['genre']\n",
    "    # Add comma before Mashup/mashup if it's not already there\n",
    "    genre = re.sub(r'([a-zA-Z])(Mashup)', r'\\1, \\2', genre, flags=re.IGNORECASE).lower()\n",
    "    row['genre'] = genre\n",
    "\n",
    "for r in final_rows[:10]:\n",
    "    print(r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "suno_clean",
   "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.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
