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


Python Progress.prepare_track方法代码示例

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


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

示例1: Ripper

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

#.........这里部分代码省略.........
            path_tokens = [truncate(token, 255) for token in path_tokens]
            return os.pathsep.join(path_tokens)

        def truncate_file_name(file_name):
            tokens = file_name.rsplit(os.extsep, 1)
            if len(tokens) > 1:
                tokens[0] = truncate(tokens[0], 255 - len(tokens[1]) - 1)
            else:
                tokens[0] = truncate(tokens[0], 255)
            return os.extsep.join(tokens)

        # ensure each component in path is no more than 255 chars long
        tokens = audio_file.rsplit(os.pathsep, 1)
        if len(tokens) > 1:
            audio_file = os.path.join(
                truncate_dir_path(tokens[0]), truncate_file_name(tokens[1]))
        else:
            audio_file = truncate_file_name(tokens[0])

        # prepend base_dir
        audio_file = to_ascii(args, os.path.join(_base_dir, audio_file))

        # create directory if it doesn't exist
        audio_path = os.path.dirname(audio_file)
        if not os.path.exists(audio_path):
            os.makedirs(audio_path)

        return audio_file

    def prepare_rip(self, idx, track):
        args = self.args

        # reset progress
        self.progress.prepare_track(track)

        if self.progress.total_tracks > 1:
            print(Fore.GREEN + "[ " + str(idx + 1) + " / " + str(
                self.progress.total_tracks) + " ] Ripping " +
                  track.link.uri + Fore.RESET)
        else:
            print(Fore.GREEN + "Ripping " + track.link.uri + Fore.RESET)
        print(Fore.CYAN + self.audio_file + Fore.RESET)

        file_size = calc_file_size(self.args, track)
        print("Track Download Size: " + format_size(file_size))

        if args.output_type == "wav":
            self.wav_file = wave.open(self.audio_file, "wb")
            self.wav_file.setparams((2, 2, 44100, 0, 'NONE', 'not compressed'))
        elif args.output_type == "pcm":
            self.pcm_file = open(self.audio_file, 'wb')
        elif args.output_type == "flac":
            self.rip_proc = Popen(
                ["flac", "-f", str("-" + args.comp), "--silent", "--endian",
                 "little", "--channels", "2", "--bps", "16", "--sample-rate",
                 "44100", "--sign", "signed", "-o", self.audio_file, "-"],
                stdin=PIPE)
        elif args.output_type == "alac.m4a":
            self.rip_proc = Popen(
                ["avconv", "-nostats", "-loglevel", "0", "-f", "s16le", "-ar",
                 "44100", "-ac", "2", "-channel_layout", "stereo", "-i", "-",
                 "-acodec", "alac", self.audio_file],
                stdin=PIPE)
        elif args.output_type == "ogg":
            if args.cbr:
                self.rip_proc = Popen(
开发者ID:bsdman,项目名称:spotify-ripper,代码行数:70,代码来源:ripper.py

示例2: Ripper

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

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

        # replace filename
        if args.replace is not None:
            audio_file = self.replace_filename(audio_file, args.replace)

        # remove not allowed characters in filename (windows)
        if args.windows_safe:
            audio_file = re.sub('[:"*?<>|]', '', audio_file)

        # prepend base_dir
        audio_file = to_ascii(os.path.join(base_dir(), audio_file))

        if args.normalized_ascii:
            audio_file = to_normalized_ascii(audio_file)

        # create directory if it doesn't exist
        audio_path = os.path.dirname(audio_file)
        if not path_exists(audio_path):
            os.makedirs(enc_str(audio_path))

        self.track_path_cache[track.link.uri] = audio_file
        return audio_file

    def replace_filename(self, filename, pattern_list):
        for pattern in pattern_list:
            repl = pattern.split('/')
            filename = re.sub(repl[0], repl[1], filename)
        return filename

    def prepare_rip(self, idx, track):
        args = self.args

        # reset progress
        self.progress.prepare_track(track)

        if self.progress.total_tracks > 1:
            print(Fore.GREEN + "[ " + str(self.progress.track_idx) + " / " +
                  str(self.progress.total_tracks +
                      self.progress.skipped_tracks) + " ] Ripping " +
                  track.link.uri + Fore.WHITE +
                  "\t(ESC to skip)" + Fore.RESET)
        else:
            print(Fore.GREEN + "Ripping " + track.link.uri + Fore.RESET)
        print(Fore.CYAN + self.audio_file + Fore.RESET)

        file_size = calc_file_size(track)
        print("Track Download Size: " + format_size(file_size))

        if args.output_type == "wav" or args.plus_wav:
            audio_file = change_file_extension(self.audio_file, "wav") if \
                args.output_type != "wav" else self.audio_file
            wav_file = audio_file if sys.version_info >= (3, 0) \
                else enc_str(audio_file)
            self.wav_file = wave.open(wav_file, "wb")
            self.wav_file.setparams((2, 2, 44100, 0, 'NONE', 'not compressed'))

        if args.output_type == "pcm" or args.plus_pcm:
            audio_file = change_file_extension(self.audio_file, "pcm") if \
                args.output_type != "pcm" else self.audio_file
            self.pcm_file = open(enc_str(audio_file), 'wb')

        audio_file_enc = enc_str(self.audio_file)

        if args.output_type == "flac":
            self.rip_proc = Popen(
                ["flac", "-f", ("-" + str(args.comp)), "--silent", "--endian",
开发者ID:rcjavier,项目名称:spotify-ripper,代码行数:70,代码来源:ripper.py

示例3: Ripper

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

#.........这里部分代码省略.........
        artist = to_ascii(args, escape_filename_part(track.artists[0].name))
        album = to_ascii(args, escape_filename_part(track.album.name))
        track_name = to_ascii(args, escape_filename_part(track.name))
        extension = "." + args.output_type

        # in case the file name is too long
        def truncate(_str, max_size):
            return (_str[:max_size].strip() if len(_str) > max_size else _str)

        if args.flat:
            file_name = truncate(artist + " - " + track_name, 251) + extension
            audio_file = to_ascii(args, os.path.join(base_dir, file_name))
        elif args.flat_with_index:
            filled_idx = str(idx).zfill(self.idx_digits)
            file_name = truncate(filled_idx + " - " + artist + " - " + track_name, 251) + extension
            audio_file = to_ascii(args, os.path.join(base_dir, file_name))
        else:
            artist_t = truncate(artist, 255)
            album_t = truncate(album, 255)
            file_name = truncate(artist + " - " + track_name, 251) + extension
            audio_file = to_ascii(args, os.path.join(base_dir, artist_t, album_t, file_name))

        # create directory if it doesn't exist
        mp3_path = os.path.dirname(audio_file)
        if not os.path.exists(mp3_path):
            os.makedirs(mp3_path)

        return audio_file

    def prepare_rip(self, idx, track):
        args = self.args

        # reset progress
        self.progress.prepare_track(track)

        if self.progress.total_tracks > 1:
            print(Fore.GREEN + "[ " + str(idx + 1) + " / " + str(self.progress.total_tracks) + " ] Ripping " + track.link.uri + Fore.RESET)
        else:
            print(Fore.GREEN + "Ripping " + track.link.uri + Fore.RESET)
        print(Fore.CYAN + self.audio_file + Fore.RESET)

        file_size = calc_file_size(self.args, track)
        print("Track Download Size: " + format_size(file_size))

        if args.output_type == "flac":
            self.rip_proc = Popen(["flac", "-f", "--best", "--silent", "--endian", "little", "--channels", "2", "--bps", "16", "--sample-rate", "44100", "--sign", "signed", "-o", self.audio_file, "-"], stdin=PIPE)
        elif args.output_type == "ogg":
            if args.cbr:
                self.rip_proc = Popen(["oggenc", "--quiet", "--raw", "-b", args.bitrate, "-o", self.audio_file, "-"], stdin=PIPE)
            else:
                self.rip_proc = Popen(["oggenc", "--quiet", "--raw", "-q", args.vbr, "-o", self.audio_file, "-"], stdin=PIPE)
        elif args.output_type == "opus":
            if args.cbr:
                self.rip_proc = Popen(["opusenc", "--quiet", "--cvbr", "--bitrate", str(int(args.bitrate) / 2), "--raw", "--raw-rate", "44100", "-", self.audio_file], stdin=PIPE)
            else:
                self.rip_proc = Popen(["opusenc", "--quiet", "--vbr", "--bitrate", args.vbr, "--raw", "--raw-rate", "44100", "-", self.audio_file], stdin=PIPE)
        elif args.output_type == "aac":
            if self.dev_null is None: self.dev_null = open(os.devnull, 'wb')
            if args.cbr:
                self.rip_proc = Popen(["faac", "-P", "-X", "-b", args.bitrate, "-o", self.audio_file, "-"], stdin=PIPE, stdout=self.dev_null, stderr=self.dev_null)
            else:
                self.rip_proc = Popen(["faac", "-P", "-X", "-q", args.vbr, "-o", self.audio_file, "-"], stdin=PIPE, stdout=self.dev_null, stderr=self.dev_null)
        elif args.output_type == "m4a":
            if args.cbr:
                self.rip_proc = Popen(["fdkaac", "-S", "-R", "-w", "200000", "-b", args.bitrate, "-o", self.audio_file, "-"], stdin=PIPE)
            else:
开发者ID:yaksa-me,项目名称:spotify-ripper,代码行数:70,代码来源:ripper.py

示例4: Ripper

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

#.........这里部分代码省略.........
            path_tokens = dir_path.split(os.pathsep)
            path_tokens = [truncate(token, 255) for token in path_tokens]
            return os.pathsep.join(path_tokens)

        def truncate_file_name(file_name):
            tokens = file_name.rsplit(os.extsep, 1)
            if len(tokens) > 1:
                tokens[0] = truncate(tokens[0], 255 - len(tokens[1]) - 1)
            else:
                tokens[0] = truncate(tokens[0], 255)
            return os.extsep.join(tokens)

        # ensure each component in path is no more than 255 chars long
        tokens = audio_file.rsplit(os.pathsep, 1)
        if len(tokens) > 1:
            audio_file = os.path.join(truncate_dir_path(tokens[0]), truncate_file_name(tokens[1]))
        else:
            audio_file = truncate_file_name(tokens[0])

        # prepend base_dir
        audio_file = to_ascii(args, os.path.join(_base_dir, audio_file))

        # create directory if it doesn't exist
        audio_path = os.path.dirname(audio_file)
        if not os.path.exists(audio_path):
            os.makedirs(audio_path)

        return audio_file

    def prepare_rip(self, idx, track):
        args = self.args

        # reset progress
        self.progress.prepare_track(track)

        if self.progress.total_tracks > 1:
            print(
                Fore.GREEN
                + "[ "
                + str(idx + 1)
                + " / "
                + str(self.progress.total_tracks)
                + " ] Ripping "
                + track.link.uri
                + Fore.RESET
            )
        else:
            print(Fore.GREEN + "Ripping " + track.link.uri + Fore.RESET)
        print(Fore.CYAN + self.audio_file + Fore.RESET)

        file_size = calc_file_size(self.args, track)
        print("Track Download Size: " + format_size(file_size))

        if args.output_type == "wav":
            self.wav_file = wave.open(self.audio_file, "wb")
            self.wav_file.setparams((2, 2, 44100, 0, "NONE", "not compressed"))
        elif args.output_type == "pcm":
            self.pcm_file = open(self.audio_file, "wb")
        elif args.output_type == "flac":
            self.rip_proc = Popen(
                [
                    "flac",
                    "-f",
                    str("-" + args.comp),
                    "--silent",
                    "--endian",
开发者ID:bkintanar,项目名称:spotify-ripper,代码行数:70,代码来源:ripper.py


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