def get_album(url): data = extract_ldjson_blob(url, clean=True) if data.get('inAlbum'): return BandcampAlbum({ "title": data['inAlbum'].get('name'), "url": data['inAlbum'].get('id', url).split("#")[0], 'type': data['inAlbum'].get("type"), })
def get_comments(url): data = extract_ldjson_blob(url, clean=True) comments = [] for d in data.get("comment", []): comment = { "text": d["text"], 'image': d["author"].get("image"), "author": d["author"]["name"] } comments.append(comment) return comments
def get_artist(url): data = extract_ldjson_blob(url, clean=True) d = data.get("byArtist") if d: return BandcampArtist({ "title": d.get('name'), "url": d.get('id', url).split("#")[0], 'genre': d.get('genre'), "artist_type": d.get('type') }, scrap=False) return None
def get_releases(url): data = extract_ldjson_blob(url, clean=True) releases = [] for d in data.get("albumRelease", []): release = { "description": d.get("description"), 'image': d.get('image'), "title": d.get('name'), "url": d.get('id', url).split("#")[0], 'format': d.get('musicReleaseFormat'), } releases.append(release) return releases
def get_track_data(url): data = extract_ldjson_blob(url, clean=True) track = { 'dateModified': data.get('dateModified'), 'datePublished': data.get('datePublished'), "url": data.get('id') or url, "title": data.get("name"), "type": data.get("type"), 'image': data.get('image'), 'keywords': data.get('keywords', "").split(", ") } for k, v in get_props(data).items(): track[k] = v return track
def get_album_data(url): data = extract_ldjson_blob(url, clean=True) props = get_props(data) return { 'dateModified': data.get('dateModified'), 'datePublished': data.get('datePublished'), 'description': data.get('description'), "url": data.get('id') or url, "title": data.get("name"), "type": data.get("type"), "n_tracks": data.get('numTracks'), 'image': data.get('image'), 'featured_track_num': props.get('featured_track_num'), 'keywords': data.get('keywords', "").split(", ") }
def get_tracks(url): data = extract_ldjson_blob(url, clean=True) if not data.get("track"): return [] data = data['track'] tracks = [] for d in data.get('itemListElement', []): d = d['item'] track = { "title": d.get('name'), "url": d.get('id') or url, 'type': d.get('type'), } for k, v in get_props(d).items(): track[k] = v tracks.append(BandcampTrack(track, scrap=False)) return tracks