示例#1
0
def download(item: dict, extr: bool = False, server=Server.WB1, limit=None):
    file_name = item["name"]
    repl_list = [
        (" ", r"\ "),  # TODO: use escaped for all?
        ("'", "*"),
        ("[", "*"),
        ("]", "*"),
        ("(", "*"),
        (")", "*")
    ]
    for char, repl in repl_list:
        file_name = file_name.replace(char, repl)
    print(f'downloading: {cstr(file_name, "orange")}')
    conf = config.ConfigurationManager()
    dl_dir = conf.get("path_download")
    limit_str = f"-l {limit} " if limit is not None else ""
    command = f'scp {limit_str}-r {server.value}:"~/files/{file_name}" "{dl_dir}"'
    local_command(command, hide_output=False)
    # only run extract if dest was default dl dir
    if extr:
        path_for_extract_cmd = Path(dl_dir) / file_name
        if not path_for_extract_cmd.exists():
            return
        pfcs(f"running extract command on: g[{path_for_extract_cmd}]")
        extract.extract_item(path_for_extract_cmd)
示例#2
0
 def get_subtitle_file(self, link_name, save_as="downloaded_sub.zip"):
     self.driver.find_element_by_partial_link_text(link_name).click()
     WebDriverWait(self.driver, 3).until(
         ec.presence_of_element_located((By.ID, "downloadButton")))
     button_element = self.driver.find_element_by_id("downloadButton")
     url = button_element.get_attribute('href')
     # TODO: urllib to download file instead of relying on curl?
     run.local_command(f"curl {url} --output {save_as}", print_info=False)
     self.driver.back()
示例#3
0
def mount(ds_share):
    if platform.system() != 'Linux':
        pcstr("not on a linux-system, quitting", "red")
        sys.exit(1)
    mount_dest = get_mount_dest()
    ds_shares = get_ds_shares()
    cred_file = CONFIG.get('smb_credentials_reg')
    if ds_share == "all" or ds_share.upper() in ds_shares:
        for share in ds_shares:
            if share == ds_share.upper() or ds_share == "all":
                if ismounted(share):
                    print(
                        f"{cstr(share, 'lgreen')} is mounted at {get_mount_path(share)}"
                    )
                    continue
                opt = f"credentials={cred_file},iocharset=utf8,vers=3.0,rw,file_mode=0777,dir_mode=0777"
                src = f"//{NAS_IP}/{share}"
                local_dest = f"{mount_dest}{share.lower()}"
                print(f"mounting {share} to {local_dest}")
                success = local_command(
                    f"sudo mount -t cifs {src} {local_dest} -o {opt}",
                    print_info=False)
                if not success:
                    print(f"mounting of {cstr(src, 'red')} failed!")
    else:
        _print_error_invalid_share(ds_share)
示例#4
0
def main():
    args = get_args()
    srt_filenames = []
    if args.search_subscene is not None:
        if args.verbose:
            print("searching subscene")
        subscene = SubScene(args.search_subscene, verbose=args.verbose)
        for lang in [Language.English, Language.Swedish]:
            if args.lang is not None:
                if args.lang == "en" and lang != Language.English:
                    continue
                if args.lang == "sv" and lang != Language.Swedish:
                    continue
            sub = subscene.result.get_best(lang)
            if sub:
                srt_path = sub.download_and_unzip()
                if srt_path:
                    handle_srt(srt_path)
            else:
                print(f"could not find any subs for language: {lang}")
        return 0
    if "*" in args.file:
        items = list(Path().glob(args.file))
        if items:
            pfcs(f"found i[{len(items)}] item matching i[{args.file}]")
        for num, item in enumerate(items, 1):
            if len(items) > 1:
                pfcs(f"processing item i[{num}] of {len(items)}")
            if item.suffix.endswith("srt"):
                handle_srt(item.name, auto_move=args.auto_move)
            else:
                pfcs(f"skipping item w[{item.name}], not srt")
            print_line()
        print("done!")
        sys.exit(0)
    file_path = Path(args.file)
    if not file_path.exists():
        print("passed file does not exists")
        exit()
    if file_path.suffix.endswith('zip'):
        srt_filenames = find_srt_filenames_in_zip(file_path)
        if not srt_filenames:
            print("could not find srt in zip file!")
            exit()
        for srt_filename in srt_filenames:
            command = f"unzip -oj {file_path} {srt_filename}"
            if run.local_command(command, print_info=False):
                print(f"extracted {cstr(srt_filename, 154)}!")
    elif file_path.suffix.endswith('srt'):
        srt_filenames = [file_path.name]
    else:
        print("no subtitle file to process..")
        exit()
    [handle_srt(srt, auto_move=args.auto_move) for srt in srt_filenames]
示例#5
0
 def download_with_svtplaydl(self):
     command = f'svtplay-dl -S --force-subtitle -o "{self.get_dest_path()}" {self.url}'
     dual_srt_filename = self.get_dest_path().name + ".srt"
     dual_srt_extension_path = Path(self.dest_path) / dual_srt_filename
     if dual_srt_extension_path.exists():  # svtplay-dl might add ext.
         pass
     elif not run.local_command(command, hide_output=True,
                                print_info=False):
         self.download_succeeded = False
     if dual_srt_extension_path.exists():  # svtplay-dl adds srt extension?
         dual_srt_extension_path.rename(self.get_dest_path())
示例#6
0
def wb_scp_torrents(server=Server.WB1):
    "send torrent files to wb watch dir"
    torrent_file_list = []
    conf = config.ConfigurationManager()
    dl_paths = [
        Path.home() / "mnt" / "downloads",
        Path(conf.get("path_download"))
    ]
    for dl_path in dl_paths:
        if not dl_path.exists():
            continue
        torrent_file_list += dl_path.glob("**/*.torrent")
    for torrent_file in torrent_file_list:
        command = f'scp "{str(torrent_file)}" {server.value}:~/watch'
        pfcs(f"sending torrent: g[{torrent_file.name}]")
        if local_command(command, hide_output=True):
            try:
                torrent_file.unlink()  # remove file
                pfcs(f"removed local torrent: o[{torrent_file.name}]")
            except:
                pfcs(f"failed to remove local torrent: e[{torrent_file.name}]")
示例#7
0
 def subp(self, command):
     command = command.replace("{}", self.filename)
     local_command(command, hide_output=False, print_info=True)
示例#8
0
 def download_with_curl(self):
     command = f"curl {self.url} > {self.get_dest_path()}"
     self.log_fs(f"running: lg[{command}]")
     if not run.local_command(command, hide_output=True, print_info=False):
         self.download_succeeded = False