Done some more work
[battle-of-the-bands.git] / discogs.ipynb
diff --git a/discogs.ipynb b/discogs.ipynb
new file mode 100644 (file)
index 0000000..9f107b8
--- /dev/null
@@ -0,0 +1,615 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "import pandas as pd\n",
+    "import numpy as np\n",
+    "import matplotlib\n",
+    "import matplotlib.pyplot as plt\n",
+    "%matplotlib inline  \n",
+    "import urllib.request\n",
+    "import urllib.parse\n",
+    "import urllib.error\n",
+    "import json\n",
+    "import base64\n",
+    "import configparser\n",
+    "from bs4 import BeautifulSoup\n",
+    "import re\n",
+    "import pymongo\n",
+    "from datetime import datetime\n",
+    "import time\n",
+    "import collections\n",
+    "import editdistance"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "# Open a connection to the Mongo server\n",
+    "client = pymongo.MongoClient('mongodb://localhost:27017/')"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "# Create a database and a collections within it.\n",
+    "songs_db = client.songs\n",
+    "albums = songs_db.albums\n",
+    "tracks = songs_db.tracks\n",
+    "genius_tracks = songs_db.gtracks"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "['app_name', 'consumer_key', 'consumer_secret', 'token']"
+      ]
+     },
+     "execution_count": 5,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "config = configparser.ConfigParser()\n",
+    "config.read('secrets.ini')\n",
+    "[k for k in config['discogs']]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "def get_audio_features(track_ids, auth_type, auth_token):\n",
+    "    url = 'https://api.spotify.com/v1/audio-features?ids={ids}'.format(ids=','.join(track_ids))\n",
+    "    headers = {'Authorization': auth_type + ' ' + auth_token}\n",
+    "    request = urllib.request.Request(url, headers=headers, method='GET')\n",
+    "    \n",
+    "    for _ in range(10):\n",
+    "        try:\n",
+    "            with urllib.request.urlopen(request) as f:\n",
+    "                response = json.loads(f.read().decode('utf-8'))\n",
+    "                for track in response['audio_features']:\n",
+    "                    tracks.update_one({'_id': track['id']}, {'$set': track})\n",
+    "                break\n",
+    "        except urllib.error.HTTPError as e:\n",
+    "            print(\"Rate limited. Pausing for\", e.info()['Retry-After'])\n",
+    "            time.sleep(int(e.info()['Retry-After']) + 0.5)\n",
+    "            continue     "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "def get_artists(artist_name):\n",
+    "    query = urllib.parse.urlencode({'q': artist_name, 'type': 'artist'})\n",
+    "    request = 'https://api.spotify.com/v1/search?{}'.format(query)\n",
+    "    with urllib.request.urlopen(request) as f:\n",
+    "        response = json.loads(f.read().decode('utf-8'))\n",
+    "        artists = []\n",
+    "        for artist in response['artists']['items']:\n",
+    "            if artist['name'].lower() == artist_name.lower():\n",
+    "                this_artist = {'name': artist['name'], 'id': artist['id']}\n",
+    "                if artist['images']:\n",
+    "                    this_artist['image'] = artist['images'][0]['url']\n",
+    "                artists += [this_artist]\n",
+    "    return artists"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": [
+    "/database/search?q={query}&{?type,title,release_title,credit,artist,anv,label,genre,style,country,year,format,catno,barcode,track,submitter,contributor}"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 45,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [],
+   "source": [
+    "def get_artist(artist_name):\n",
+    "    query = urllib.parse.urlencode({'q': artist_name, 'type': 'artist'})\n",
+    "    # query = urllib.parse.urlencode({'q': artist_name})\n",
+    "    url = 'https://api.discogs.com/database/search?{}'.format(query)\n",
+    "    headers = {'Authorization': 'Discogs token=' + config['discogs']['token']}\n",
+    "    artists = []\n",
+    "    while url:\n",
+    "        request = urllib.request.Request(url, headers=headers, method='GET')\n",
+    "        with urllib.request.urlopen(request) as f:\n",
+    "            response = json.loads(f.read().decode('utf-8'))\n",
+    "            artists += response['results']\n",
+    "            if 'next' in response['pagination']['urls']:\n",
+    "                url = response['pagination']['urls']['next']\n",
+    "            else:\n",
+    "                url = None\n",
+    "    return artists"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 44,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "{'next': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=2', 'last': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=5'}\n",
+      "{'first': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=1', 'next': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=3', 'last': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=5', 'prev': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=1'}\n",
+      "{'first': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=1', 'next': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=4', 'last': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=5', 'prev': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=2'}\n",
+      "{'first': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=1', 'next': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=5', 'last': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=5', 'prev': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=3'}\n",
+      "{'first': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=1', 'prev': 'https://api.discogs.com/database/search?q=Nirvana&per_page=50&type=artist&page=4'}\n"
+     ]
+    },
+    {
+     "data": {
+      "text/plain": [
+       "201"
+      ]
+     },
+     "execution_count": 44,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "nivs = get_artist('Nirvana')\n",
+    "len(nivs)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 47,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "[{'id': 125246,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/125246',\n",
+       "  'thumb': 'https://api-img.discogs.com/6AS7RIgqIBFEuGusd3tG_z2J2rs=/150x150/smart/filters:strip_icc():format(jpeg):mode_rgb():quality(40)/discogs-images/A-125246-1105986304.jpg.jpg',\n",
+       "  'title': 'Nirvana',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/125246-Nirvana'},\n",
+       " {'id': 307513,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/307513',\n",
+       "  'thumb': 'https://api-img.discogs.com/5skyOqEGgSOnt9lhPHhjP4uCACE=/150x150/smart/filters:strip_icc():format(jpeg):mode_rgb():quality(40)/discogs-images/A-307513-1270236942.jpeg.jpg',\n",
+       "  'title': 'Nirvana (2)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/307513-Nirvana-2'},\n",
+       " {'id': 1087206,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/1087206',\n",
+       "  'thumb': 'https://api-img.discogs.com/Wgp-oaSc03_RK9skZYyCp3YrQOU=/150x150/smart/filters:strip_icc():format(jpeg):mode_rgb():quality(40)/discogs-images/A-1087206-1266869411.jpeg.jpg',\n",
+       "  'title': 'Nirvana 2002',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/1087206-Nirvana-2002'},\n",
+       " {'id': 1082359,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/1082359',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana (6)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/1082359-Nirvana-6'},\n",
+       " {'id': 2744248,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/2744248',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana (10)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/2744248-Nirvana-10'},\n",
+       " {'id': 1176738,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/1176738',\n",
+       "  'thumb': 'https://api-img.discogs.com/NV8RiufOYHnOPR1oA6tGpIy3mog=/150x150/smart/filters:strip_icc():format(jpeg):mode_rgb():quality(40)/discogs-images/A-1176738-1317705549.jpeg.jpg',\n",
+       "  'title': 'Nirvana (7)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/1176738-Nirvana-7'},\n",
+       " {'id': 457609,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/457609',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana (4)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/457609-Nirvana-4'},\n",
+       " {'id': 1389061,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/1389061',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana (8)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/1389061-Nirvana-8'},\n",
+       " {'id': 816495,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/816495',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana (5)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/816495-Nirvana-5'},\n",
+       " {'id': 965460,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/965460',\n",
+       "  'thumb': 'https://api-img.discogs.com/tnmDXyMMViUQYCPPRkrINumoAP0=/150x150/smart/filters:strip_icc():format(jpeg):mode_rgb():quality(40)/discogs-images/A-965460-1370853336-6662.jpeg.jpg',\n",
+       "  'title': 'The Nirvana Devils',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/965460-The-Nirvana-Devils'},\n",
+       " {'id': 319676,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/319676',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana (3)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/319676-Nirvana-3'},\n",
+       " {'id': 2414323,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/2414323',\n",
+       "  'thumb': '',\n",
+       "  'title': 'El Nirvana',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/2414323-El-Nirvana'},\n",
+       " {'id': 934885,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/934885',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana Bros.',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/934885-Nirvana-Bros'},\n",
+       " {'id': 2103552,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/2103552',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana (9)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/2103552-Nirvana-9'},\n",
+       " {'id': 45870,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/45870',\n",
+       "  'thumb': '',\n",
+       "  'title': 'The Nirvana Sitar & String Group',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/45870-The-Nirvana-Sitar-String-Group'},\n",
+       " {'id': 4634135,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/4634135',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana (13)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/4634135-Nirvana-13'},\n",
+       " {'id': 520870,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/520870',\n",
+       "  'thumb': '',\n",
+       "  'title': 'The Attainment Of Nirvana',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/520870-The-Attainment-Of-Nirvana'},\n",
+       " {'id': 5145389,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/5145389',\n",
+       "  'thumb': 'https://api-img.discogs.com/YSxmWcLnQ716R0Om_psIRruIyZ4=/150x150/smart/filters:strip_icc():format(jpeg):mode_rgb():quality(40)/discogs-images/A-5145389-1468099375-2943.jpeg.jpg',\n",
+       "  'title': 'Nirvana (14)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/5145389-Nirvana-14'},\n",
+       " {'id': 3465490,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/3465490',\n",
+       "  'thumb': 'https://api-img.discogs.com/-oS5YYSnPEdE5qT4sh1_jyY2h_s=/150x150/smart/filters:strip_icc():format(jpeg):mode_rgb():quality(40)/discogs-images/A-3465490-1379316060-1118.jpeg.jpg',\n",
+       "  'title': 'Approaching Nirvana',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/3465490-Approaching-Nirvana'},\n",
+       " {'id': 5047262,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/5047262',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana Kelly',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/5047262-Nirvana-Kelly'},\n",
+       " {'id': 1907189,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/1907189',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Paulette \"Nirvana\" Buckley',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/1907189-Paulette-Nirvana-Buckley'},\n",
+       " {'id': 1286267,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/1286267',\n",
+       "  'thumb': '',\n",
+       "  'title': 'The Nirvana',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/1286267-The-Nirvana'},\n",
+       " {'id': 2888206,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/2888206',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nada Nirvana',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/2888206-Nada-Nirvana'},\n",
+       " {'id': 1459803,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/1459803',\n",
+       "  'thumb': 'https://api-img.discogs.com/HW8koSJDiyjCmFZHsTSBpbIiD2A=/150x150/smart/filters:strip_icc():format(jpeg):mode_rgb():quality(40)/discogs-images/A-1459803-1420753729-4099.jpeg.jpg',\n",
+       "  'title': 'Nirvana Savoury',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/1459803-Nirvana-Savoury'},\n",
+       " {'id': 4809078,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/4809078',\n",
+       "  'thumb': '',\n",
+       "  'title': 'The Nirvana Ensemble',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/4809078-The-Nirvana-Ensemble'},\n",
+       " {'id': 501548,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/501548',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana 1 Way',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/501548-Nirvana-1-Way'},\n",
+       " {'id': 2100392,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/2100392',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Last Casino In Nirvana',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/2100392-Last-Casino-In-Nirvana'},\n",
+       " {'id': 3995371,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/3995371',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana (12)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/3995371-Nirvana-12'},\n",
+       " {'id': 2728399,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/2728399',\n",
+       "  'thumb': '',\n",
+       "  'title': 'The Nirvana (2)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/2728399-The-Nirvana-2'},\n",
+       " {'id': 3105291,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/3105291',\n",
+       "  'thumb': 'https://api-img.discogs.com/uGA8CJEGkje1yNUt7kwEIDF1TBQ=/150x150/smart/filters:strip_icc():format(jpeg):mode_rgb():quality(40)/discogs-images/A-3105291-1358422778-8324.jpeg.jpg',\n",
+       "  'title': 'Nirvana (11)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/3105291-Nirvana-11'},\n",
+       " {'id': 2852124,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/2852124',\n",
+       "  'thumb': '',\n",
+       "  'title': 'The Nirvana Banana',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/2852124-The-Nirvana-Banana'},\n",
+       " {'id': 3114787,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/3114787',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana Pan Jali',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/3114787-Nirvana-Pan-Jali'},\n",
+       " {'id': 3574712,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/3574712',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Ricky Nirvana',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/3574712-Ricky-Nirvana'},\n",
+       " {'id': 1285360,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/1285360',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana Banana',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/1285360-Nirvana-Banana'},\n",
+       " {'id': 2966881,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/2966881',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Weed Nirvana',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/2966881-Weed-Nirvana'},\n",
+       " {'id': 4562747,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/4562747',\n",
+       "  'thumb': '',\n",
+       "  'title': \"Grass  (The Real '60s UK Nirvana)\",\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/4562747-Grass-The-Real-60s-UK-Nirvana'},\n",
+       " {'id': 3758745,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/3758745',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nihil Nirvana',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/3758745-Nihil-Nirvana'},\n",
+       " {'id': 4143675,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/4143675',\n",
+       "  'thumb': 'https://api-img.discogs.com/3rc6erC0JTTNXR05sF9T7eF60Qc=/150x150/smart/filters:strip_icc():format(jpeg):mode_rgb():quality(40)/discogs-images/A-4143675-1486326311-8056.jpeg.jpg',\n",
+       "  'title': 'Nirvanass',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/4143675-Nirvanass'},\n",
+       " {'id': 5375335,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/5375335',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana Heire',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/5375335-Nirvana-Heire'},\n",
+       " {'id': 3221382,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/3221382',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana Groove',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/3221382-Nirvana-Groove'},\n",
+       " {'id': 3875208,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/3875208',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana Lucie',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/3875208-Nirvana-Lucie'},\n",
+       " {'id': 2337392,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/2337392',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana Curve',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/2337392-Nirvana-Curve'},\n",
+       " {'id': 3801487,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/3801487',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana Gherbaz Duraković',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/3801487-Nirvana-Gherbaz-Duraković'},\n",
+       " {'id': 3189817,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/3189817',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Takis Nirvanas And The 4 Chambers',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/3189817-Takis-Nirvanas-And-The-4-Chambers'},\n",
+       " {'id': 5305718,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/5305718',\n",
+       "  'thumb': '',\n",
+       "  'title': 'Nirvana Teen Spirit',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/5305718-Nirvana-Teen-Spirit'},\n",
+       " {'id': 5515837,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/5515837',\n",
+       "  'thumb': 'https://api-img.discogs.com/images/warning.png',\n",
+       "  'title': 'Bon Jovi, Nirvana, Michael Jackson, INXS, ZZTOP, Extreme, Boston, Garth Brooks, Midnight Oil, Huey Lewis & The News',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/5515837-Bon-Jovi-Nirvana-Michael-Jackson-INXS-ZZTOP-Extreme-Boston-Garth-Brooks-Midnight-Oil-Huey-Lewis-The-News'}]"
+      ]
+     },
+     "execution_count": 47,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "[n for n in nivs if 'Nirvana' in n['title']]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 48,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "647"
+      ]
+     },
+     "execution_count": 48,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "tbs = get_artist('The Beatles')\n",
+    "len(tbs)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 56,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "3"
+      ]
+     },
+     "execution_count": 56,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "atbs = [a for a in tbs if re.match('^The Beatles(\\s\\(\\d+\\))?$', a['title'])]\n",
+    "len(atbs)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 57,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "[{'id': 82730,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/82730',\n",
+       "  'thumb': 'https://api-img.discogs.com/v1NIz7CyzwLHJsnSGIjg6sCL5FI=/150x150/smart/filters:strip_icc():format(jpeg):mode_rgb():quality(40)/discogs-images/A-82730-1449581547-9306.jpeg.jpg',\n",
+       "  'title': 'The Beatles',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/82730-The-Beatles'},\n",
+       " {'id': 2517607,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/2517607',\n",
+       "  'thumb': '',\n",
+       "  'title': 'The Beatles (2)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/2517607-The-Beatles-2'},\n",
+       " {'id': 4290435,\n",
+       "  'resource_url': 'https://api.discogs.com/artists/4290435',\n",
+       "  'thumb': '',\n",
+       "  'title': 'The Beatles (3)',\n",
+       "  'type': 'artist',\n",
+       "  'uri': '/artist/4290435-The-Beatles-3'}]"
+      ]
+     },
+     "execution_count": 57,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "atbs"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Python 3",
+   "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.5.2+"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}