Do main function.
()
| 11 | __version__ = xstudio.__version__ |
| 12 | |
| 13 | def inject_main(): |
| 14 | """Do main function.""" |
| 15 | retval = 0 |
| 16 | parser = argparse.ArgumentParser( |
| 17 | description=__doc__ + " Injects media into xStudio.", |
| 18 | formatter_class=argparse.ArgumentDefaultsHelpFormatter |
| 19 | ) |
| 20 | |
| 21 | parser.add_argument( |
| 22 | "-s", "--session", action="store", |
| 23 | type=str, |
| 24 | help="Host name.", |
| 25 | default=None |
| 26 | ) |
| 27 | |
| 28 | parser.add_argument( |
| 29 | "-H", "--host", action="store", |
| 30 | type=str, |
| 31 | help="Host name.", |
| 32 | default=None |
| 33 | ) |
| 34 | |
| 35 | parser.add_argument( |
| 36 | "-p", "--port", action="store", |
| 37 | type=int, |
| 38 | help="Port.", |
| 39 | default=14441 |
| 40 | ) |
| 41 | |
| 42 | parser.add_argument( |
| 43 | "media", type=str, nargs="*", default=[], |
| 44 | help="Media paths to add." |
| 45 | ) |
| 46 | |
| 47 | args = parser.parse_args() |
| 48 | |
| 49 | if args.session: |
| 50 | m = RemoteSessionManager(remote_session_path()) |
| 51 | s = m.find(args.session) |
| 52 | conn = Connection() |
| 53 | conn.connect_remote(s.host(), s.port.port()) |
| 54 | |
| 55 | elif args.host: |
| 56 | conn = Connection() |
| 57 | conn.connect_remote(args.host, args.port) |
| 58 | else: |
| 59 | conn = Connection() |
| 60 | conn.connect_remote("localhost", args.port) |
| 61 | |
| 62 | pl = conn.api.app.session.create_playlist("Injected Media")[1] |
| 63 | |
| 64 | if len(args.media): |
| 65 | for path in args.media: |
| 66 | try: |
| 67 | path = os.path.abspath(path) |
| 68 | print("Added "+str(len(pl.add_media_list(path, True)))+" Media items.") |
| 69 | except ValueError as err: |
| 70 | print(str(err)) |
nothing calls this directly
no test coverage detected