def play_file( api: BaiduPCSApi, remotepath: str, player: Player = DEFAULT_PLAYER, player_params: List[str] = [], m3u8: bool = False, quiet: bool = False, out_cmd: bool = False, ): if not _with_media_ext(remotepath): return print(f"[italic blue]Play[/italic blue]: {remotepath} {'(m3u8)' if m3u8 else ''}") if m3u8: m3u8_cn = api.m3u8_stream(remotepath) with open(DEFAULT_TEMP_M3U8, "w") as fd: fd.write(m3u8_cn) url = DEFAULT_TEMP_M3U8 else: url = api.download_link(remotepath) player.play( url, api.cookies, m3u8=m3u8, quiet=quiet, player_params=player_params, out_cmd=out_cmd, )
def download_file( api: BaiduPCSApi, remotepath: str, localdir: str, downloader: Downloader = DEFAULT_DOWNLOADER, downloadparams: DownloadParams = DEFAULT_DOWNLOADPARAMS, out_cmd: bool = False, ): localpath = Path(localdir) / os.path.basename(remotepath) # Make sure parent directory existed if not localpath.parent.exists(): localpath.parent.mkdir(parents=True) if not out_cmd and localpath.exists(): print(f"[yellow]{localpath}[/yellow] is ready existed.") return dlink = api.download_link(remotepath) if downloader != Downloader.me: print(f"[italic blue]Download[/italic blue]: {remotepath} to {localpath}") downloader.download( dlink, str(localpath), api.cookies, downloadparams=downloadparams, out_cmd=out_cmd, )
def _get_download_link_and_rapid_upload_info( api: BaiduPCSApi, pcs_file: PcsFile, show_dl_link: bool = False, show_hash_link: bool = False, check_md5: bool = True, ) -> Tuple[Optional[str], Optional[PcsRapidUploadInfo]]: dl_link = None if show_dl_link: dl_link = api.download_link(pcs_file.path) rpinfo = None if show_hash_link: rpinfo = api.rapid_upload_info(pcs_file.path, check=check_md5) return dl_link, rpinfo
def play_file( api: BaiduPCSApi, remotepath: str, player: Player = DEFAULT_PLAYER, player_params: List[str] = [], m3u8: bool = False, quiet: bool = False, ignore_ext: bool = False, out_cmd: bool = False, local_server: str = "", ): if not ignore_ext and not _with_media_ext(remotepath): return print( f"[italic blue]Play[/italic blue]: {remotepath} {'(m3u8)' if m3u8 else ''}" ) # For typing url: Optional[str] = None if m3u8: m3u8_cn = api.m3u8_stream(remotepath) with open(DEFAULT_TEMP_M3U8, "w") as fd: fd.write(m3u8_cn) url = DEFAULT_TEMP_M3U8 use_local_server = bool(local_server) if use_local_server: url = f"{local_server}{quote(remotepath)}" print("url:", url) else: url = api.download_link(remotepath) if not url: display_blocked_remotepath(remotepath) return player.play( url, api.cookies, m3u8=m3u8, quiet=quiet, player_params=player_params, out_cmd=out_cmd, use_local_server=use_local_server, )