def _job_quality(job): from libyo.youtube.resolve.profiles import profiles profile=job.getnosect("profile",list(profiles.keys())[0]).lower() if profile not in profiles: print("[ERROR] The Profile \"{0}\" is unknown".format(profile)) return False if job.getnosect("resolution",job.getnosect("quality",None)): try: resolution = int(job.getnosect("resolution",job.getnosect("quality")).lower().rstrip("p")) except ValueError: print("[ERROR] Resolution has to be in this format: \"%i\" or \"%ip\" ('360' or '360p')") return False raw_map = profiles[profile][0] if resolution not in raw_map: print("[ WARN] The Exact Resolution given ({1}) is not avaiable in this Profile: \"{0}\"".format(profile,resolution)) l= [ v for k,v in raw_map.items() if k <= resolution ] return l else: return list(profiles[profile][0].values())
def main(argv): """ The main entrypoint. This only manages commandline arguments and db intialization It will dispatch control to [subcommand]_command(args) """ # print welcome message and check versions welcome() #--------------------------------------------- # parse the commandline arguments #--------------------------------------------- choice_profile = choice.cichoice(profiles.keys()) choice_quality = choice.qchoice.new(1080, 720, 480, 360, 240) parser = argparse.ArgumentParser(prog=argv[0]) parser.add_argument("-db", dest="database", help="The Database to use", default=database) parser.add_argument("-V", dest="command_", action="store_const", const="version", help="Display version and quit") subparsers = parser.add_subparsers(dest="command", help="Use '%(prog)s (command) -h' to get further help. By Default, the 'run' command is run.", title="command", default="run") # config subcommand config_parser = subparsers.add_parser("config", description="Modify application options") config_parser.add_argument("mode", choices=("get", "set", "list"), help="What you want to do; available options are %(choices)s") config_parser.add_argument("key", help="The Key to modify/show (set, get)", nargs="?") config_parser.add_argument("value", help="The Value to set (set)", nargs="?") # job management job_parser = subparsers.add_parser("job", description="Manage youfeed jobs") job_subparsers = job_parser.add_subparsers(dest="mode", help="Job modification modes") job_add = job_subparsers.add_parser("add", description="Add new job") job_add.add_argument("name", help="An unique Identifier for this job") job_add.add_argument("type", help="The job type. choices: %(choices)s", choices=("playlist", "favorites")) job_add.add_argument("resource", help="The job resource. [playlist -> playlist ID]") job_add.add_argument("-target", help="The name of the resulting playlist") job_add.add_argument("-profile", help="The job codec profile", choices=choice_profile) job_add.add_argument("-quality", help="The job maximum quality", choices=choice_quality) job_add.add_argument("-export", help="Export the playlist file") job_add.add_argument("-disable", action="store_true", help="Disable the new job") job_add.add_argument("-noidcheck", action="store_true", help="Disable Playlist ID check") job_rm = job_subparsers.add_parser("rm", description="Remove a job") job_rm.add_argument("name", help="The job identifier") job_dis = job_subparsers.add_parser("disable", description="Enable/Disable Job") job_dis.add_argument("name", help="The job identifier") job_dis.add_argument("disabled", help="disabled flag value. choices: %(choices)s", choices=("yes", "no")) job_mod = job_subparsers.add_parser("change", description="Modify a job") job_mod.add_argument("name", help="The job identifier") job_mod.add_argument("-name", dest="newname", help="Change the identifier") job_mod.add_argument("-type", help="Change the job type", choices=("playlist",)) job_mod.add_argument("-resource", help="Change the job resource") job_mod.add_argument("-target", help="Change the playlist name") job_mod.add_argument("-profile", help="Change the codec profile", choices=choice_profile) job_mod.add_argument("-quality", help="Change the maximum quality", choices=choice_quality) job_mod.add_argument("-export", help="Change the export location") job_mod.add_argument("-noidcheck", action="store_true", help="Disable Playlist ID check") job_list = job_subparsers.add_parser("list", description="List jobs") job_list.add_argument("-showall", help="Don't hide system jobs", action="store_true") job_show = job_subparsers.add_parser("show", description="Display a job") job_show.add_argument("name", help="The job identifier") # run subcommand run_parser = subparsers.add_parser("run", description="run job(s). if no jobs are given, run all enabled jobs") run_parser.add_argument("names", help="The job identifier(s)", nargs="*") run_parser.add_argument("-p", help="Only recreate the playlist file(s)", action="store_true") run_parser.add_argument("-d", help="Only check for new videos, don't download anything", action="store_true") run_parser.add_argument("-forceall", help="run disabled jobs, too", action="store_true") # db subcommand db_parser = subparsers.add_parser("db", description="Manage the YouFeed Database") db_parsers = db_parser.add_subparsers(dest="mode") db_import2 = db_parsers.add_parser("v2import", description="Import v2 videos") db_import2.add_argument("pldir", help="youfeed v2 pl/ directory") db_import2.add_argument("-move", help="move contained videos to new schema", action="store_true") #db_import2.add_argument # export subcommand export_parser = subparsers.add_parser("export", description="export videos") export_parser.add_argument("playlist_id", help="what to export") export_parser.add_argument("-profile", choices=choice_profile, help="profile") export_parser.add_argument("-quality", choices=choice_quality, help="quality") export_parser.add_argument("-startat", type=int, help="first element index", default=1) export_parsers = export_parser.add_subparsers(dest="mode", help="where to export to") export_folder = export_parsers.add_parser("folder", description="copy videos to folder") export_folder.add_argument("location", help="the folder location") export_folder.add_argument("filename_template", help="how to name the video files: %n=index %t=title %e=extension %i=videoId %p=playlistTitle %x=playlistId %u=uploader", default="%n._%t.%e", nargs="?") # do the parsing args = parser.parse_args(argv[1:]) #--------------------------------------------- # database initialization #--------------------------------------------- if not os.path.exists(args.database): db = yfdb.DB.open(args.database) db.setOptionValue("playlists_folder", playlists_folder) db.setOptionValue("videos_folder", videos_folder) else: db = yfdb.DB.open(args.database) # pass db around with args args.db = db args.root = os.path.dirname(os.path.abspath(args.database)) #--------------------------------------------- # Dispatcher #--------------------------------------------- if args.command_: if args.command_ == "version": print("YouFeed version: %s" % version) print("libyo version: %s" % libyo.version) print("DB version: %i" % yfdb.DB_VERSION) return 0 elif args.command == "config": return config_command(args) elif args.command == "job": return job_command(args) elif args.command == "run": return run_command(args) elif args.command == "db": return db_command(args) elif args.command == "export": return export_command(args)