当前位置: 首页>>代码示例>>Python>>正文


Python Progress.calc_total方法代码示例

本文整理汇总了Python中spotify_ripper.progress.Progress.calc_total方法的典型用法代码示例。如果您正苦于以下问题:Python Progress.calc_total方法的具体用法?Python Progress.calc_total怎么用?Python Progress.calc_total使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在spotify_ripper.progress.Progress的用法示例。


在下文中一共展示了Progress.calc_total方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Ripper

# 需要导入模块: from spotify_ripper.progress import Progress [as 别名]
# 或者: from spotify_ripper.progress.Progress import calc_total [as 别名]

#.........这里部分代码省略.........
                Fore.RED + "Encountered issue while logging into "
                           "Spotify, aborting..." + Fore.RESET)
            self.stop_event_loop()
            self.finished.set()
            return

        # check if we were passed a file name or search
        if len(args.uri) == 1 and os.path.exists(args.uri[0]):
            uris = [line.strip() for line in open(args.uri[0])]
        elif len(args.uri) == 1 and not args.uri[0].startswith("spotify:"):
            uris = [list(self.search_query(args.uri[0]))]
        else:
            uris = args.uri

        def get_tracks_from_uri(uri):
            if isinstance(uri, list):
                return uri
            else:
                if (args.exclude_appears_on and
                        uri.startswith("spotify:artist:")):
                    album_uris = self.load_artist_albums(uri)
                    return itertools.chain(
                        *[self.load_link(album_uri) for
                          album_uri in album_uris])
                else:
                    return self.load_link(uri)

        # calculate total size and time
        all_tracks = []
        for uri in uris:
            tracks = get_tracks_from_uri(uri)
            all_tracks += list(tracks)

        self.progress.calc_total(all_tracks)

        if self.progress.total_size > 0:
            print(
                "Total Download Size: " +
                format_size(self.progress.total_size))

        # create track iterator
        for uri in uris:
            if self.abort.is_set():
                break

            tracks = list(get_tracks_from_uri(uri))

            if args.flat_with_index and self.current_playlist:
                self.idx_digits = len(str(len(self.current_playlist.tracks)))

            if args.playlist_sync and self.current_playlist:
                self.sync = Sync(args, self)
                self.sync.sync_playlist(self.current_playlist)

            # ripping loop
            for idx, track in enumerate(tracks):
                try:
                    if self.abort.is_set():
                        break

                    print('Loading track...')
                    track.load()
                    if track.availability != 1:
                        print(
                            Fore.RED + 'Track is not available, '
                                       'skipping...' + Fore.RESET)
开发者ID:bsdman,项目名称:spotify-ripper,代码行数:70,代码来源:ripper.py

示例2: Ripper

# 需要导入模块: from spotify_ripper.progress import Progress [as 别名]
# 或者: from spotify_ripper.progress.Progress import calc_total [as 别名]

#.........这里部分代码省略.........
                         args.artist_album_market is not None)):
                    album_uris = self.web.get_albums_with_filter(uri)
                    return itertools.chain(
                        *[self.load_link(album_uri) for
                          album_uri in album_uris])
                elif uri.startswith("spotify:charts:"):
                    charts = self.web.get_charts(uri)
                    if charts is not None:
                        self.current_chart = charts
                        chart_uris = charts["tracks"]
                        return itertools.chain(
                            *[self.load_link(chart_uri) for
                              chart_uri in chart_uris])
                    else:
                        return iter([])
                else:
                    return self.load_link(uri)

        # calculate total size and time
        all_tracks = []
        for uri in uris:
            tracks = list(get_tracks_from_uri(uri))

            # TODO: remove dependency on current_album, ...
            for idx, track in enumerate(tracks):

                # ignore local tracks
                if track.is_local:
                    continue

                audio_file = self.format_track_path(idx, track)
                all_tracks.append((track, audio_file))

        self.progress.calc_total(all_tracks)

        if self.progress.total_size > 0:
            print(
                "Total Download Size: " +
                format_size(self.progress.total_size))

        # create track iterator
        for uri in uris:
            if self.abort.is_set():
                break

            tracks = list(get_tracks_from_uri(uri))

            if args.playlist_sync and self.current_playlist:
                self.sync = Sync(args, self)
                self.sync.sync_playlist(self.current_playlist)

            # ripping loop
            for idx, track in enumerate(tracks):
                try:
                    self.check_stop_time()
                    self.skip.clear()

                    if self.abort.is_set():
                        break

                    print('Loading track...')
                    track.load()
                    if track.availability != 1 or track.is_local:
                        print(
                            Fore.RED + 'Track is not available, '
                                       'skipping...' + Fore.RESET)
开发者ID:rcjavier,项目名称:spotify-ripper,代码行数:70,代码来源:ripper.py

示例3: Ripper

# 需要导入模块: from spotify_ripper.progress import Progress [as 别名]
# 或者: from spotify_ripper.progress.Progress import calc_total [as 别名]

#.........这里部分代码省略.........

        # login
        print("Logging in...")
        if args.last:
            self.login_as_last()
        elif args.user != None and args.password == None:
            password = getpass.getpass()
            self.login(args.user[0], password)
        else:
            self.login(args.user[0], args.password[0])

        if not self.login_success:
            print(Fore.RED + "Encountered issue while logging into Spotify, aborting..." + Fore.RESET)
            self.finished = True
            return

        # create track iterator
        for uri in args.uri:
            if os.path.exists(uri):
                tracks = itertools.chain(*[self.load_link(line.strip()) for line in open(uri)])
            elif uri.startswith("spotify:"):
                if args.exclude_appears_on and uri.startswith("spotify:artist:"):
                    album_uris = self.load_artist_albums(uri)
                    tracks = itertools.chain(*[self.load_link(album_uri) for album_uri in album_uris])
                else:
                    tracks = self.load_link(uri)
            else:
                tracks = self.search_query(uri)

            if args.flat_with_index and self.current_playlist:
                self.idx_digits = len(str(len(self.current_playlist.tracks)))

            tracks = list(tracks)
            self.progress.calc_total(tracks)

            if self.progress.total_size > 0:
                print("Total Download Size: " + format_size(self.progress.total_size))

            # ripping loop
            for idx, track in enumerate(tracks):
                try:
                    print('Loading track...')
                    track.load()
                    if track.availability != 1:
                        print(Fore.RED + 'Track is not available, skipping...' + Fore.RESET)
                        continue

                    self.audio_file = self.track_path(idx, track)

                    if not args.overwrite and os.path.exists(self.audio_file):
                        print(Fore.YELLOW + "Skipping " + track.link.uri + Fore.RESET)
                        print(Fore.CYAN + self.audio_file + Fore.RESET)
                        self.queue_remove_from_playlist(idx)
                        continue

                    self.session.player.load(track)
                    self.prepare_rip(idx, track)
                    self.session.player.play()

                    self.end_of_track.wait()
                    self.end_of_track.clear()

                    self.finish_rip(track)

                    # update id3v2 with metadata and embed front cover image
                    set_metadata_tags(args, self.audio_file, track)
开发者ID:yaksa-me,项目名称:spotify-ripper,代码行数:70,代码来源:ripper.py

示例4: Ripper

# 需要导入模块: from spotify_ripper.progress import Progress [as 别名]
# 或者: from spotify_ripper.progress.Progress import calc_total [as 别名]

#.........这里部分代码省略.........
        else:
            self.login(args.user[0], args.password[0])

        if not self.login_success:
            print(Fore.RED + "Encountered issue while logging into " "Spotify, aborting..." + Fore.RESET)
            self.finished = True
            return

        # check if we were passed a file name
        if len(args.uri) == 1 and os.path.exists(args.uri[0]):
            uris = [line.strip() for line in open(args.uri[0])]
        else:
            uris = args.uri

        # create track iterator
        for uri in uris:
            if uri.startswith("spotify:"):
                if args.exclude_appears_on and uri.startswith("spotify:artist:"):
                    album_uris = self.load_artist_albums(uri)
                    tracks = itertools.chain(*[self.load_link(album_uri) for album_uri in album_uris])
                else:
                    tracks = self.load_link(uri)
            else:
                tracks = self.search_query(uri)

            if args.flat_with_index and self.current_playlist:
                self.idx_digits = len(str(len(self.current_playlist.tracks)))

            if args.playlist_sync and self.current_playlist:
                self.sync = Sync(args, self)
                self.sync.sync_playlist(self.current_playlist)

            tracks = list(tracks)
            self.progress.calc_total(tracks)

            if self.progress.total_size > 0:
                print("Total Download Size: " + format_size(self.progress.total_size))

            # ripping loop
            for idx, track in enumerate(tracks):
                try:
                    print("Loading track...")
                    track.load()
                    if track.availability != 1:
                        print(Fore.RED + "Track is not available, " "skipping..." + Fore.RESET)
                        self.log_failure(track)
                        continue

                    self.audio_file = self.format_track_path(idx, track)

                    if not args.overwrite and os.path.exists(self.audio_file):
                        print(Fore.YELLOW + "Skipping " + track.link.uri + Fore.RESET)
                        print(Fore.CYAN + self.audio_file + Fore.RESET)
                        self.queue_remove_from_playlist(idx)
                        continue

                    self.session.player.load(track)
                    self.prepare_rip(idx, track)
                    self.session.player.play()

                    self.end_of_track.wait()
                    self.end_of_track.clear()

                    self.finish_rip(track)

                    # update id3v2 with metadata and embed front cover image
开发者ID:bkintanar,项目名称:spotify-ripper,代码行数:70,代码来源:ripper.py


注:本文中的spotify_ripper.progress.Progress.calc_total方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。