Example #1
0
def test_rename_works_with_subtitles():
    filename = "test/abcd.mkv"
    target = ""
    target_expanded = ""
    f = {"path": filename, "info": {}}
    for tag in ("tag_1", "tag_2", "tag_3", "tag_4"):
        target += f"%{tag}%"
        target_expanded += tag
        f["info"][tag] = tag
    f["info"]["aired"] = datetime.datetime(2018, 2, 9)
    target_expanded = target_expanded.replace("aired", "2018-02-09")
    out = flexmock.flexmock(error=lambda x: print(x), warning=lambda x: None)
    out.should_receive("success")
    os_mock = flexmock.flexmock(os)
    glob_mock = flexmock.flexmock(glob)
    os_mock.should_receive("rename").with_args(
        "test/abcd.mkv", target_expanded + ".mkv").once()
    os_mock.should_receive("rename").with_args(
        "test/abcd.srt", target_expanded + ".srt").once()
    os_mock.should_receive("link").with_args(
        "test/abcd.mkv", "test\\" + target_expanded + ".mkv").once()
    os_mock.should_receive("link").with_args(
        "test/abcd.srt", "test\\" + target_expanded + ".srt").once()
    os_mock.should_receive("makedirs").at_least().once()
    lst = [filename, "test/abcd.srt"]
    glob_mock.should_receive("glob").and_return(lst)
    oper = operations.RenameOperation(out, target, "%Y-%m-%d", False, False,
                                      False, False)
    oper2 = operations.RenameOperation(out, target, "%Y-%m-%d", False, True,
                                       False, True)
    oper.Process(f)
    assert f[
        "path"] != filename  # Should be changed for next elements in pipeline
    f["path"] = filename
    oper2.Process(f)
Example #2
0
def api(ctx, username, password, apikey, add, unwatched, rename, files,
        keep_structure, date_format, delete_empty, link, softlink, persistent,
        abort, state):
    if (not add and not rename):
        ctx.obj["output"].info("Nothing to do.")
        return
    try:
        conn = get_connector(apikey, username, password, persistent)
    except Exception as e:
        raise e
        ctx.obj["output"].error(e)
        exit(1)
    pipeline = []
    pipeline.append(operations.HashOperation(ctx.obj["output"]))
    if add:
        pipeline.append(
            operations.MylistAddOperation(conn, ctx.obj["output"], state,
                                          unwatched))
    if rename:
        pipeline.append(
            operations.GetFileInfoOperation(conn, ctx.obj["output"]))
        pipeline.append(
            operations.RenameOperation(ctx.obj["output"], rename, date_format,
                                       delete_empty, keep_structure, softlink,
                                       link, abort))
    to_process = get_files_to_process(files, ctx)
    for file in to_process:
        file_obj = {}
        file_obj["path"] = file
        ctx.obj["output"].info("Processing file \"" + file + "\"")
        for operation in pipeline:
            res = operation.Process(file_obj)
            if not res:  # Critical error, cannot proceed with pipeline
                break
    conn.close(persistent, get_persistent_file_path())
Example #3
0
def api(ctx, username, password, apikey, add, rename, files, keep_structure,
        date_format, delete_empty, link, softlink):
    if (not add and not rename):
        ctx.obj["output"].info("Nothing to do.")
        return
    try:
        if apikey:
            conn = anidbconnector.AnidbConnector.create_secure(
                username, password, apikey)
        else:
            conn = anidbconnector.AnidbConnector.create_plain(
                username, password)
    except Exception as e:
        ctx.obj["output"].error(e)
        exit(1)
    pipeline = []
    pipeline.append(operations.HashOperation(ctx.obj["output"]))
    if add:
        pipeline.append(operations.MylistAddOperation(conn, ctx.obj["output"]))
    if rename:
        pipeline.append(
            operations.GetFileInfoOperation(conn, ctx.obj["output"]))
        pipeline.append(
            operations.RenameOperation(ctx.obj["output"], rename, date_format,
                                       delete_empty, keep_structure, softlink,
                                       link))
    to_process = get_files_to_process(files, ctx)
    for file in to_process:
        file_obj = {}
        file_obj["path"] = file
        ctx.obj["output"].info("Processing file \"" + file + "\"")
        for operation in pipeline:
            res = operation.Process(file_obj)
            if not res:  # Critical error, cannot proceed with pipeline
                break
    conn.close()