Exemple #1
0
def main():
    cli = dict((key.lstrip("-<").rstrip(">"), value)
               for key, value in docopt(__doc__).items())

    print_ = safe_print if not cli['quiet'] else lambda *args, **kwargs: None

    if not cli['input']:
        cli['input'] = [os.getcwd()]

    mmw = MusicManagerWrapper(log=cli['log'])
    mmw.login(oauth_file=cli['cred'], uploader_id=cli['uploader-id'])

    excludes = "|".join(
        pattern.decode('utf8')
        for pattern in cli['exclude']) if cli['exclude'] else None

    upload_songs, exclude_songs = mmw.get_local_songs(
        cli['input'],
        exclude_patterns=excludes,
        filters=cli['filter'],
        filter_all=cli['all'])

    upload_songs.sort()
    exclude_songs.sort()

    if cli['dry-run']:
        print_("Found {0} songs to upload".format(len(upload_songs)))

        if upload_songs:
            safe_print("\nSongs to upload:\n")

            for song in upload_songs:
                safe_print(song)
        else:
            safe_print("\nNo songs to upload")

        if exclude_songs:
            safe_print("\nSongs to exclude:\n")

            for song in exclude_songs:
                safe_print(song)
        else:
            safe_print("\nNo songs to exclude")
    else:
        if upload_songs:
            print_("Uploading {0} songs to Google Music\n".format(
                len(upload_songs)))

            mmw.upload(upload_songs, enable_matching=cli['match'])
        else:
            safe_print("\nNo songs to upload")

    mmw.logout()
    print("\nAll done!")
def main():
	cli = dict((key.lstrip("-<").rstrip(">"), value) for key, value in docopt(__doc__).items())

	print_ = safe_print if not cli['quiet'] else lambda *args, **kwargs: None

	if not cli['input']:
		cli['input'] = [os.getcwd()]

	mmw = MusicManagerWrapper(log=cli['log'])
	mmw.login(oauth_file=cli['cred'], uploader_id=cli['uploader-id'])

	excludes = "|".join(pattern.decode('utf8') for pattern in cli['exclude']) if cli['exclude'] else None

	upload_songs, exclude_songs = mmw.get_local_songs(cli['input'], exclude_patterns=excludes, filters=cli['filter'], filter_all=cli['all'])

	upload_songs.sort()
	exclude_songs.sort()

	if cli['dry-run']:
		print_("Found {0} songs to upload".format(len(upload_songs)))

		if upload_songs:
			safe_print("\nSongs to upload:\n")

			for song in upload_songs:
				safe_print(song)
		else:
			safe_print("\nNo songs to upload")

		if exclude_songs:
			safe_print("\nSongs to exclude:\n")

			for song in exclude_songs:
				safe_print(song)
		else:
			safe_print("\nNo songs to exclude")
	else:
		if upload_songs:
			print_("Uploading {0} songs to Google Music\n".format(len(upload_songs)))

			mmw.upload(upload_songs, enable_matching=cli['match'])
		else:
			safe_print("\nNo songs to upload")

	mmw.logout()
	print("\nAll done!")
def main():
    cli = dict((key.lstrip("-<").rstrip(">"), value)
               for key, value in docopt(__doc__).items())

    print_ = safe_print if not cli['quiet'] else lambda *args, **kwargs: None

    if not cli['input']:
        cli['input'] = [os.getcwd()]

    if not cli['output']:
        cli['output'] = os.getcwd()

    # Pre-compile regex for exclude option.
    excludes = "|".join(
        pattern.decode('utf8')
        for pattern in cli['exclude']) if cli['exclude'] else None

    mmw = MusicManagerWrapper(log=cli['log'], quiet=cli['quiet'])
    mmw.login(oauth_file=cli['cred'], uploader_id=cli['uploader-id'])

    if cli['down']:
        google_songs = mmw.get_google_songs(filters=cli['filter'],
                                            filter_all=cli['all'])

        cli['input'] = template_to_base_path(google_songs, cli['output'])

        local_songs, exclude_songs = mmw.get_local_songs(
            cli['input'], exclude_patterns=excludes)

        print_("Scanning for missing songs...")
        download_songs = compare_song_collections(google_songs, local_songs)

        download_songs.sort(key=lambda song: (song['artist'], song['album'],
                                              song['track_number']))

        if cli['dry-run']:
            print_("Found {0} songs to download".format(len(download_songs)))

            if download_songs:
                safe_print("\nSongs to download:\n")

                for song in download_songs:
                    safe_print("{0} by {1}".format(song['title'],
                                                   song['artist']))
            else:
                safe_print("\nNo songs to download")
        else:
            if download_songs:
                print_("Downloading {0} songs from Google Music\n".format(
                    len(download_songs)))
                mmw.download(download_songs, cli['output'])
            else:
                safe_print("\nNo songs to download")
    else:
        google_songs = mmw.get_google_songs()
        local_songs, exclude_songs = mmw.get_local_songs(
            cli['input'],
            exclude_patterns=excludes,
            filters=cli['filter'],
            filter_all=cli['all'])

        print_("Scanning for missing songs...")

        upload_songs = compare_song_collections(local_songs, google_songs)

        # Sort lists for sensible output.
        upload_songs.sort()
        exclude_songs.sort()

        if cli['dry-run']:
            print_("Found {0} songs to upload".format(len(upload_songs)))

            if upload_songs:
                safe_print("\nSongs to upload:\n")

                for song in upload_songs:
                    safe_print(song)
            else:
                safe_print("\nNo songs to upload")

            if exclude_songs:
                safe_print("\nSongs to exclude:\n")

                for song in exclude_songs:
                    safe_print(song)
            else:
                safe_print("\nNo songs to exclude")
        else:
            if upload_songs:
                print_("Uploading {0} songs to Google Music\n".format(
                    len(upload_songs)))

                mmw.upload(upload_songs, enable_matching=cli['match'])
            else:
                safe_print("\nNo songs to upload")

    mmw.logout()
    print_("\nAll done!")
def main():
	cli = dict((key.lstrip("-<").rstrip(">"), value) for key, value in docopt(__doc__).items())

	print_ = safe_print if not cli['quiet'] else lambda *args, **kwargs: None

	if not cli['input']:
		cli['input'] = [os.getcwd()]

	if not cli['output']:
		cli['output'] = os.getcwd()

	# Pre-compile regex for exclude option.
	excludes = "|".join(pattern.decode('utf8') for pattern in cli['exclude']) if cli['exclude'] else None

	mmw = MusicManagerWrapper(log=cli['log'], quiet=cli['quiet'])
	mmw.login(oauth_file=cli['cred'], uploader_id=cli['uploader-id'])

	if cli['down']:
		google_songs = mmw.get_google_songs(filters=cli['filter'], filter_all=cli['all'])

		cli['input'] = template_to_base_path(google_songs, cli['output'])

		local_songs, exclude_songs = mmw.get_local_songs(cli['input'], exclude_patterns=excludes)

		print_("Scanning for missing songs...")
		download_songs = compare_song_collections(google_songs, local_songs)

		download_songs.sort(key=lambda song: (song['artist'], song['album'], song['track_number']))

		if cli['dry-run']:
			print_("Found {0} songs to download".format(len(download_songs)))

			if download_songs:
				safe_print("\nSongs to download:\n")

				for song in download_songs:
					safe_print("{0} by {1}".format(song['title'], song['artist']))
			else:
				safe_print("\nNo songs to download")
		else:
			if download_songs:
				print_("Downloading {0} songs from Google Music\n".format(len(download_songs)))
				mmw.download(download_songs, cli['output'])
			else:
				safe_print("\nNo songs to download")
	else:
		google_songs = mmw.get_google_songs()
		local_songs, exclude_songs = mmw.get_local_songs(cli['input'], exclude_patterns=excludes, filters=cli['filter'], filter_all=cli['all'])

		print_("Scanning for missing songs...")

		upload_songs = compare_song_collections(local_songs, google_songs)

		# Sort lists for sensible output.
		upload_songs.sort()
		exclude_songs.sort()

		if cli['dry-run']:
			print_("Found {0} songs to upload".format(len(upload_songs)))

			if upload_songs:
				safe_print("\nSongs to upload:\n")

				for song in upload_songs:
					safe_print(song)
			else:
				safe_print("\nNo songs to upload")

			if exclude_songs:
				safe_print("\nSongs to exclude:\n")

				for song in exclude_songs:
					safe_print(song)
			else:
				safe_print("\nNo songs to exclude")
		else:
			if upload_songs:
				print_("Uploading {0} songs to Google Music\n".format(len(upload_songs)))

				mmw.upload(upload_songs, enable_matching=cli['match'])
			else:
				safe_print("\nNo songs to upload")

	mmw.logout()
	print_("\nAll done!")