Ejemplo n.º 1
0
def track_rip(track_id):
    meta = client.get_meta(type="track", id=int(track_id))
    track = meta['list'][0]['track_detail']['result']['track']
    logger_bugs.info("Artist: {} | Track: {}".format(track['artist_nm'],
                                                     track['track_title']))
    track_quality = utils.determine_quality(track=track)
    album_path = os.path.join(config.prefs['downloads_directory'])
    pre_path = os.path.join(album_path,
                            "{}. .BugsPy".format(track['track_no']))
    post_path = os.path.join(
        album_path,
        utils.sanitize("{}. {}.{}".format(track['track_no'],
                                          track['track_title'],
                                          track_quality)))
    if utils.exist_check(post_path):
        logger_bugs.info("{} already exists.".format(post_path))
    else:
        download_track(pre_path=pre_path,
                       track_id=track['track_id'],
                       track_title=track['track_title'],
                       track_number=track['track_no'])
        os.rename(pre_path, post_path)
        # Fetch the album meta of the track, this is required for proper tagging.
        meta = client.get_meta(type="album", id=int(track['album_id']))
        # Download album artwork
        cover_path = os.path.join(album_path, config.prefs['cover_name'])
        try:
            download_cover(meta['list'][0]['album_info']['result']['img_urls'],
                           cover_path)
        # If we're unable to request from the url we'll set the cover_path to False
        except requests.exceptions.HTTPError:
            cover_path = False
        try:
            tag(album=meta,
                track=track,
                file_path=post_path,
                cover_path=cover_path)
        # TODO: Come back to this exception and implement a better solution on f_file.save() within tag()
        except error:
            logger_bugs.warning(
                "_writeblock error, falling back to a smaller cover artwork.")
            config.prefs['cover_size'] = "500"
            cover_path = os.path.join(album_path, "fallback_cover.jpg")
            download_cover(meta['list'][0]['album_info']['result']['img_urls'],
                           cover_path)
            tag(album=meta,
                track=track,
                file_path=post_path,
                cover_path=cover_path)
Ejemplo n.º 2
0
def album_rip(album_id):
	"""
	:param id: String (Album ID)
	"""
	meta = client.get_meta(type="album", id=int(album_id))
	# Check for multiple artists.
	if meta['list'][0]['album_info']['result']['multi_artist_yn'] == "Y":
		# Label V.A. if amount of artists > 2
		if meta['list'][0]['album_info']['result']['artist_disp_nm'].count(",") > 2:
			meta['list'][0]['album_info']['result']['artist_disp_nm'] = "Various Artists"
	album_directory_name = "{} - {} [{}]".format(meta['list'][0]['album_info']['result']['artist_disp_nm'],
	                                        meta['list'][0]['album_info']['result']['title'].strip(),
	                                        utils.get_date(meta['list'][0]['album_info']['result']['release_ymd']))
	# Check for availability.
	if meta['list'][0]['album_info']['result']['is_album_str_noright']:
		logger_bugs.warning('No streaming rights for {}.'.format(album_directory_name))
	else:
		logger_bugs.info("Album: {}.".format(album_directory_name))
		if config.prefs['artist_folders']:
			album_path = utils.sanitize(os.path.join(config.prefs['downloads_directory'],
			                          meta['list'][0]['album_info']['result']['artist_disp_nm'], album_directory_name))
		else:
			album_path = utils.sanitize(os.path.join(config.prefs['downloads_directory'], album_directory_name))
		utils.make_dir(album_path)
		cover_path = os.path.join(album_path, config.prefs['cover_name'])
		try:
			download_cover(meta['list'][0]['album_info']['result']['img_urls'], cover_path)
		# If we're unable to request from the url we'll set the cover_path to False
		except requests.exceptions.HTTPError:
			cover_path = False
		for track in meta['list'][0]['album_info']['result']['tracks']:
			# Check for availability.
			if not track['track_str_rights']:
				logger_bugs.warning('No streaming rights for #{} - {}.'.format(track['track_no'], track['track_title']))
			else:
				track_quality = utils.determine_quality(track=track)
				pre_path = os.path.join(album_path, "{}. .BugsPy".format(track['track_no']))
				post_path = utils.sanitize(os.path.join(album_path, "{}. {}.{}".format(track['track_no'], track['track_title'],
				                                                        track_quality)))
				if utils.exist_check(post_path):
					logger_bugs.info("{} already exists.".format(post_path))
				else:
					download_track(pre_path=pre_path, track_id=track['track_id'], track_title=track['track_title'],
					               track_number=track['track_no'])
					os.rename(pre_path, post_path)
					try:
						tag(album=meta, track=track, file_path=post_path, cover_path=cover_path)
					# TODO: Come back to this exception and implement a better solution on f_file.save() within tag()
					except error:
						logger_bugs.warning("_writeblock error, falling back to a smaller cover artwork.")
						config.prefs['cover_size'] = "500"
						cover_path = os.path.join(album_path, "fallback_cover.jpg")
						download_cover(meta['list'][0]['album_info']['result']['img_urls'], cover_path)
						tag(album=meta, track=track, file_path=post_path, cover_path=cover_path)
Ejemplo n.º 3
0
def artist_rip(artist_id):
	meta = client.get_meta(type="artist", id=int(artist_id))
	logger_bugs.info("Artist: {} | Album Count: {}".format(meta['list'][0]['artist_info']['result']['artist_nm'], len(meta['list'][1]['artist_album']['list'])))
	for album in meta['list'][1]['artist_album']['list']:
		index = meta['list'][1]['artist_album']['list'].index(album)+1
		logger_bugs.info("Downloading Album #{} of #{}.".format(index, len(meta['list'][1]['artist_album']['list'])))
		contribution_status = utils.contribution_check(artist_id, album['artist_id'])
		if contribution_status:
			if config.prefs['include_contributions']:
				album_rip(album['album_id'])
			else:
				logger_bugs.info("{} has been marked as a contribution and skipped.".format(album['title'].strip()))
		else:
			album_rip(album['album_id'])
Ejemplo n.º 4
0
def main():
    """
	Main function which will control the flow of our script when called.
	"""
    total = len(args.u)
    for n, url in enumerate(args.u, 1):
        logger_genie.info("Album {} of {}".format(n, total))
        album_id = utils.check_url(url)
        if not album_id:
            return
        meta = client.get_meta(album_id)
        album_fol = "{} - {}".format(
            parse.unquote(meta['DATA0']['DATA'][0]['ARTIST_NAME']),
            parse.unquote(meta['DATA0']['DATA'][0]['ALBUM_NAME']))
        if prefs['artist_folders']:
            album_fol_abs = os.path.join(
                os.path.dirname(__file__), prefs['download_directory'],
                parse.unquote(
                    utils.sanitize(meta['DATA0']['DATA'][0]['ARTIST_NAME'])),
                utils.sanitize(album_fol))
        else:
            album_fol_abs = os.path.join(os.path.dirname(__file__),
                                         prefs['download_directory'],
                                         utils.sanitize(album_fol))
        logger_genie.info("Album found: " + album_fol)
        utils.make_dir(album_fol_abs)
        cover_url = parse.unquote(
            meta['DATA0']['DATA'][0]['ALBUM_IMG_PATH_600'])
        download_cover(cover_url, album_fol_abs)
        f_meta = {
            "track_total": len(meta['DATA1']['DATA']),
            "album_artist":
            parse.unquote(meta['DATA0']['DATA'][0]['ARTIST_NAME']),
            "release_date": meta['DATA0']['DATA'][0]['ALBUM_RELEASE_DT'],
            "planning":
            parse.unquote(meta['DATA0']['DATA'][0]['ALBUM_PLANNER'])
        }
        f_meta['disc_total'] = meta['DATA1']['DATA'][f_meta['track_total'] -
                                                     1]['ALBUM_CD_NO']
        for track in meta['DATA1']['DATA']:
            try:
                s_meta = client.get_stream_meta(track['SONG_ID'], args.f)
            except HTTPError:
                logger_genie.warning("Could not get stream info for {}".format(
                    track['SONG_ID']))
                continue
            except exceptions.StreamMetadataError:
                continue
            cur = track['ROWNUM']
            track_title = parse.unquote(track['SONG_NAME'])
            f_meta['track_artist'] = parse.unquote(track['ARTIST_NAME'])
            ext = utils.get_ext(s_meta['FILE_EXT'])
            post_abs = os.path.join(
                album_fol_abs, "{}. {}.{}".format(cur.zfill(2),
                                                  utils.sanitize(track_title),
                                                  ext))
            if utils.exist_check(post_abs):
                continue
            if not utils.allowed_check(s_meta['STREAMING_LICENSE_YN']):
                continue
            pre_abs = os.path.join(album_fol_abs, cur + ".genie-dl")
            specs = utils.parse_specs(s_meta['FILE_EXT'], s_meta['FILE_BIT'])
            download_track(s_meta['STREAMING_MP3_URL'], track_title, pre_abs,
                           cur, f_meta['track_total'], specs)
            try:
                fix_tags(pre_abs, ext, f_meta)
                logger_genie.debug("Tags updated: {}".format(f_meta))
            except Exception as e:
                raise e
            try:
                os.rename(pre_abs, post_abs)
                logger_genie.debug("{} has been renamed".format(post_abs))
            except OSError:
                raise exceptions.TrackRenameError(
                    "Could not rename {}".format(pre_abs))