+if cmdl_opts.use_netrc and cmdl_opts.password is not None:
+ sys.exit('Error: using netrc conflicts with giving command line password.')
+
+if cmdl_opts.use_title and cmdl_opts.use_literal:
+ sys.exit('Error: cannot use title and literal title at the same time.')
+
+if cmdl_opts.quiet and cmdl_opts.get_url:
+ sys.exit('Error: cannot be quiet and print final URL at the same time.')
+
+# Incorrect option formatting
+if cmdl_opts.username is None and cmdl_opts.password is not None:
+ sys.exit('Error: password give but username is missing.')
+
+if cmdl_opts.get_url is None and cmdl_opts.get_title is not None:
+ sys.exit('Error: getting title requires getting URL.')
+
+# Get account information if any
+account_username = None
+account_password = None
+
+if cmdl_opts.use_netrc:
+ try:
+ info = netrc.netrc().authenticators('youtube')
+ if info is None:
+ sys.exit('Error: no authenticators for machine youtube.')
+ netrc_username = info[0]
+ netrc_password = info[2]
+ except IOError:
+ sys.exit('Error: unable to read .netrc file.')
+ except netrc.NetrcParseError:
+ sys.exit('Error: unable to parse .netrc file.')
+
+if cmdl_opts.password is not None:
+ account_username = cmdl_opts.username
+ account_password = cmdl_opts.password
+else:
+ if cmdl_opts.username is not None and cmdl_opts.use_netrc:
+ if cmdl_opts.username != netrc_username:
+ sys.exit('Error: conflicting username from .netrc and command line options.')
+ account_username = cmdl_opts.username
+ account_password = netrc_password
+ elif cmdl_opts.username is not None:
+ account_username = cmdl_opts.username
+ account_password = getpass.getpass('Type YouTube password and press return: ')
+ elif cmdl_opts.use_netrc:
+ if len(netrc_username) == 0:
+ sys.exit('Error: empty username in .netrc file.')
+ account_username = netrc_username
+ account_password = netrc_password