def test_parse_file_info(): data = "FILE\n"\ "2151394|13485|204354|7172|0|0|1064875798|3448d5bd5c28f352006f24582a091c58|"\ "28d457964c6c348b5d10bf035d33aea6|72b21799ed147d5874ddc792fe545ea9a84dba74|23d62d71||very high|"\ "www|AAC|128|H264/AVC|5888|1920x1080|mkv|japanese|english|1415|1535760000|"\ "Boku no Hero Academia (2018) - 21 - What`s the Big Idea? - [HorribleSubs](23d62d71).mkv|"\ "25|25|2018|TV Series||Boku no Hero Academia (2018)|僕のヒーローアカデミア (2018)|My Hero Academia Season 3|"\ "僕のヒーローアカデミア (2018)'My Hero Academia Season 3'My Hero Academia Saison 3'나의 히어로 아카데미아 3|"\ "heroaca3|Boku no Hero Academia Season 3|21|What`s the Big Idea?|Nani o Shitenda yo|何をしてんだよ|HorribleSubs|HorribleSubs" conn = flexmock.flexmock() conn.should_receive("send_request").once().with_args( "FILE size=42&ed2k=ABC1234&fmask=79FAFFE900&amask=F2FCF0C0" ).and_return({ "code": 220, "data": data }) out = flexmock.flexmock() out.should_receive("success").once() f = {"size": 42, "ed2k": "ABC1234"} oper = operations.GetFileInfoOperation(conn, out) oper.Process(f) assert f["info"]["crc32"] == "23d62d71" assert f["info"]["year"] == "2018" assert f["info"]["a_kanji"] == "僕のヒーローアカデミア (2018)" assert f["info"]["a_english"] == "My Hero Academia Season 3" assert f["info"]["ep_no"] == "21" assert f["info"]["ep_english"] == "What's the Big Idea?" assert f["info"]["ep_kanji"] == "何をしてんだよ" assert f["info"]["resolution"] == "1920x1080" assert f["info"]["g_name"] == "HorribleSubs"
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())
def test_parse_file_info_err(): conn = flexmock.flexmock() conn.should_receive("send_request").once().with_args("FILE size=42&ed2k=ABC1234&fmask=79FAFFE900&amask=F2FCF0C0").and_raise(Exception) out = flexmock.flexmock() out.should_receive("error").once() oper = operations.GetFileInfoOperation(conn, out) f = {"size": 42, "ed2k": "ABC1234"} oper.Process(f)
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()