Example #1
0
def afp_shell(args):
    my_args = copy.copy(args)
    running = True
    parser = LibyoArgumentParser(prog="AFP Shell",may_exit=False,autoprint_usage=False,error_handle=sys.stdout)
    parser.add_argument("id",help="VideoID / URL / literals '+exit', '+pass', '+print'", metavar="OPERATION")
    parser.add_argument("-s","--switches",dest="switches",help="Set enabled switches (u,x,f,n,v,s)",choices=switchchoice(["u","x","f","n","v","s"]),metavar="SW")
    parser.add_argument("-a","--avc",dest="avc",help="Set Profile",choices=cichoice(profiles.profiles.keys()),metavar="PROFILE")
    parser.add_argument("-q","--quality",dest="quality",help="Set Quality Level",choices=qchoice.new(1080,720,480,360,240))
    parser.add_argument("-c","--cmd",dest="command",help="set command")
    if HAS_READLINE:
        readline.parse_and_bind("\eA: previous-history")
        readline.parse_and_bind("\eB: next-history")
    else:
        print("WARNING: No Readline extension found. Readline functionality will NOT be available. If you're on Windows you might want to consider PyReadline.")
    sw = my_args.switches = ("u" if args.extract_url else "")+("x" if args.xspf else "")+("f" if args.force else"")+("n" if not args.quiet else "")+("v" if args.verbose else "")+("s" if args.sub else "")
    while running:
        line = input("{0}> ".format(args.prog))
        try:
            parser.parse_args(shlex.split(line), my_args)
        except SystemExit:
            print("""Use "+pass --help" to show available options""")
            continue
        if sw != my_args.switches:
            my_args.extract_url = "u" in my_args.switches
            my_args.xspf = "x" in my_args.switches
            my_args.force = "f" in my_args.switches
            my_args.quiet = "n" not in my_args.switches
            my_args.verbose = "v" in my_args.switches
            my_args.sub = "s" in my_args.switches
            sw = my_args.switches
        if my_args.id =="+pass":
            continue
        elif my_args.id == "+print":
            print("Switches: [{0}]\nProfile: {1}p {2}\nCommand: {3}".format(my_args.switches,my_args.quality,my_args.avc,my_args.command))
            continue
        elif my_args.id == "+exit":
            running = False
            break
        else:
            try:
                process(my_args)
            except YouTubeException:
                print(sys.exc_info()[1])
    #end while
    return 0
Example #2
0
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)
Example #3
0
def main(ARGC,ARGV):
    welcome()
    parser = ArgumentParser(prog=ARGV[0],formatter_class=RawTextHelpFormatter,
                            description="Playback YouTube Videos without flashplayer")
    parser.add_argument("id", metavar="VideoID", type=str, help="The YouTube Video ID")
    parser.add_argument("-u","--url", dest="extract_url", action="store_true", default=False, help="VideoID is a URL; Extract the ID from it.")
    parser.add_argument("-q","--quality", metavar="Q", dest="quality", action="store", choices=qchoice.new(1080,720,480,360,240), default="480", help="Quality (Will automatically lower Quality if not avaiable!) [Default: %(default)sp]")
    parser.add_argument("-a","--avc", metavar="PRF", dest="avc", action="store", choices=cichoice(profiles.profiles.keys()), default=firstkey(profiles.profiles), help="What Profile to use [Default: %(default)s]\nUse '%(prog)s -i profiles' to show avaliable choices")
    parser.add_argument("-f","--force",dest="force",action="store_true",default=False,help="Force Quality Level (don't jump down)")
    parser.add_argument("-y","--fmt",dest="fmt",metavar="FMT",action="store",type=int,choices=profiles.descriptions.keys(),help="Specify FMT Level. (For Advanced Users)\nUse '%(prog)s -i fmt' to show known Values")
    parser.add_argument("-c","--cmd", metavar="CMD", dest="command", default="vlc %u vlc://quit --sub-file=%s", action="store", help="Media PLayer Command. use \x25\x25u for url"); #use %% to get around the usage of % formatting in argparse
    parser.add_argument("-n","--not-quiet",dest="quiet",action="store_false",default=True,help="Show Media Player Output")
    parser.add_argument("-x","--xspf",dest="xspf",action="store_true",default=False,help="Don't Play the URL directly, but create a XSPF Playlist and play that. (With Title Information etc.)")
    parser.add_argument("-s","--sub",dest="sub",action="store_true",default=False,help="Enable Subtitles (use %%s in the cmd for subtitlefile)")
    parser.add_argument("-i","--internal",dest="int",action="store_true",default=False,help="Treat VideoID as AFP internal command\nUse '%(prog)s -i help' for more Informations.")
    parser.add_argument("-v","--verbose",dest="verbose",action="store_true",default=False,help="Output more Details")
    #parser.add_argument("-s","--shell",dest="shell",action="store_true",default=False,help="Run internal Shell")
    args    = parser.parse_args(ARGV[1:])
    args.id = args.id.lstrip("\\")
    args.prog = parser.prog

    if args.int:
        return internal_cmd(args)
    #elif args.shell:
    #    return afp_shell(args)
    else:
        return process(args)