예제 #1
0
def download_songs(mm, songs, template=None):
    if not songs:
        logger.log('NORMAL', "No songs to download")
    else:
        logger.log('NORMAL', "Downloading songs from Google Music")

        if not template:
            template = Path.cwd()

        songnum = 0
        total = len(songs)
        pad = len(str(total))

        for song in songs:
            songnum += 1

            try:
                audio, _ = mm.download(song)
            except Exception as e:  # TODO: More specific exception.
                logger.log('ACTION_FAILURE', "({:>{}}/{}) Failed -- {} | {}",
                           songnum, pad, total, song, e)
            else:
                tags = audio_metadata.loads(audio).tags
                filepath = gm_utils.template_to_filepath(
                    template, tags).with_suffix('.mp3')
                if filepath.is_file():
                    filepath.unlink()

                filepath.parent.mkdir(parents=True, exist_ok=True)
                filepath.touch()
                filepath.write_bytes(audio)

                logger.log('ACTION_SUCCESS',
                           "({:>{}}/{}) Downloaded -- {} ({song['id']})",
                           songnum, pad, total, filepath, song['id'])
예제 #2
0
def download_songs(mm, songs, template=None):
	logger.success(f"Downloading {len(songs)} songs from Google Music")

	if not template:
		template = Path.cwd()

	songnum = 0
	total = len(songs)
	pad = len(str(total))

	for song in songs:
		songnum += 1

		try:
			audio, _ = mm.download(song)
		except Exception as e:  # TODO: More specific exception.
			logger.log(
				'FAILURE',
				f"({songnum:>{pad}}/{total}) Failed -- {song} | {e}"
			)
		else:
			tags = audio_metadata.loads(audio).tags
			filepath = gm_utils.template_to_filepath(template, tags).with_suffix('.mp3')

			if filepath.is_file():
				filepath.unlink()

			filepath.parent.mkdir(parents=True, exist_ok=True)
			filepath.touch()
			filepath.write_bytes(audio)

			logger.success(
				f"({songnum:>{pad}}/{total}) Downloaded -- {filepath} ({song['id']})"
			)
예제 #3
0
def template_to_base_path(template, google_songs):
    """Get base output path for a list of songs for download."""

    path = Path(template)

    if (path == Path.cwd() or path == Path('%suggested%')):
        base_path = Path.cwd()
    else:
        song_paths = [
            gm_utils.template_to_filepath(template, song)
            for song in google_songs
        ]
        if song_paths:
            base_path = Path(os.path.commonpath(song_paths))
        else:
            base_path = Path.cwd()

    return base_path.resolve()