libsecret stuff moved to extractor/common.py, reworked
This commit is contained in:
parent
5b295effdd
commit
1579fd3889
@ -11,10 +11,6 @@ import os
|
|||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import gi
|
|
||||||
gi.require_version('Secret', '1')
|
|
||||||
from gi.repository import Secret
|
|
||||||
from .compat import compat_urllib_parse
|
|
||||||
|
|
||||||
from .options import (
|
from .options import (
|
||||||
parseOpts,
|
parseOpts,
|
||||||
@ -50,8 +46,6 @@ from .YoutubeDL import YoutubeDL
|
|||||||
|
|
||||||
|
|
||||||
def _real_main(argv=None):
|
def _real_main(argv=None):
|
||||||
LIBSECRET_SCHEMA = Secret.Schema.new("io.github.rg3.youtube-dl.Store", Secret.SchemaFlags.DONT_MATCH_NAME, {"user-name": Secret.SchemaAttributeType.STRING, "domain-name": Secret.SchemaAttributeType.STRING})
|
|
||||||
|
|
||||||
# Compatibility fixes for Windows
|
# Compatibility fixes for Windows
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
# https://github.com/rg3/youtube-dl/issues/820
|
# https://github.com/rg3/youtube-dl/issues/820
|
||||||
@ -133,6 +127,10 @@ def _real_main(argv=None):
|
|||||||
# Conflicting, missing and erroneous options
|
# Conflicting, missing and erroneous options
|
||||||
if opts.usenetrc and (opts.username is not None or opts.password is not None):
|
if opts.usenetrc and (opts.username is not None or opts.password is not None):
|
||||||
parser.error('using .netrc conflicts with giving username/password')
|
parser.error('using .netrc conflicts with giving username/password')
|
||||||
|
if opts.usekeyring and (opts.username is not None or opts.password is not None):
|
||||||
|
parser.error('using keyring conflicts with giving username/password')
|
||||||
|
if opts.usekeyring and opts.usenetrc:
|
||||||
|
parser.error('using keyring conflicts with using .netrc')
|
||||||
if opts.password is not None and opts.username is None:
|
if opts.password is not None and opts.username is None:
|
||||||
parser.error('account username missing\n')
|
parser.error('account username missing\n')
|
||||||
if opts.ap_password is not None and opts.ap_username is None:
|
if opts.ap_password is not None and opts.ap_username is None:
|
||||||
@ -147,16 +145,7 @@ def _real_main(argv=None):
|
|||||||
parser.error('auto number start must be positive or 0')
|
parser.error('auto number start must be positive or 0')
|
||||||
if opts.usetitle and opts.useid:
|
if opts.usetitle and opts.useid:
|
||||||
parser.error('using title conflicts with using video ID')
|
parser.error('using title conflicts with using video ID')
|
||||||
if opts.username is not None and opts.password is None and opts.keyring is True:
|
if opts.username is not None and opts.password is None:
|
||||||
# extract domain names, check if all videos are from the same domain.
|
|
||||||
all_domains = set(map(lambda url: compat_urllib_parse.urlparse(url).netloc, all_urls))
|
|
||||||
if len(all_domains) > 1:
|
|
||||||
parser.error('You passed URLs from more than one domain - supplying credentials from command line is not supported in this case.')
|
|
||||||
domain_name = all_domains.pop()
|
|
||||||
password = Secret.password_lookup_sync(LIBSECRET_SCHEMA, {"user-name": opts.username, "domain-name": domain_name}, None)
|
|
||||||
if password is None:
|
|
||||||
parser.error('Password not found in keyring/wallet')
|
|
||||||
if opts.username is not None and opts.password is None and opts.keyring is False:
|
|
||||||
opts.password = compat_getpass('Type account password and press [Return]: ')
|
opts.password = compat_getpass('Type account password and press [Return]: ')
|
||||||
if opts.ap_username is not None and opts.ap_password is None:
|
if opts.ap_username is not None and opts.ap_password is None:
|
||||||
opts.ap_password = compat_getpass('Type TV provider account password and press [Return]: ')
|
opts.ap_password = compat_getpass('Type TV provider account password and press [Return]: ')
|
||||||
@ -324,6 +313,7 @@ def _real_main(argv=None):
|
|||||||
|
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'usenetrc': opts.usenetrc,
|
'usenetrc': opts.usenetrc,
|
||||||
|
'usekeyring': opts.usekeyring,
|
||||||
'username': opts.username,
|
'username': opts.username,
|
||||||
'password': opts.password,
|
'password': opts.password,
|
||||||
'twofactor': opts.twofactor,
|
'twofactor': opts.twofactor,
|
||||||
|
@ -827,6 +827,24 @@ class InfoExtractor(object):
|
|||||||
self._downloader.report_warning(
|
self._downloader.report_warning(
|
||||||
'parsing .netrc: %s' % error_to_compat_str(err))
|
'parsing .netrc: %s' % error_to_compat_str(err))
|
||||||
|
|
||||||
|
if self._downloader.params.get('usekeyring', False):
|
||||||
|
try:
|
||||||
|
import gi
|
||||||
|
gi.require_version('Secret', '1')
|
||||||
|
from gi.repository import Secret
|
||||||
|
LIBSECRET_SCHEMA = Secret.Schema.new("io.github.rg3.youtube-dl.Store",Secret.SchemaFlags.DONT_MATCH_NAME,{"extractor": Secret.SchemaAttributeType.STRING,"app": Secret.SchemaAttributeType.STRING})
|
||||||
|
secret = Secret.password_lookup_sync(LIBSECRET_SCHEMA, {"extractor": "json", "app": "youtube-dl"}, None)
|
||||||
|
if secret is None:
|
||||||
|
raise netrc.NetrcParseError('Can\'t find credentials in keyring for "' + netrc_machine + '"')
|
||||||
|
print(str(secret))
|
||||||
|
secret_dict = json.loads(secret)
|
||||||
|
print('JSON Parsed: ' + str(secret_json))
|
||||||
|
print('JSON User: ' + secret_json['u'])
|
||||||
|
print('JSON Password: ' + secret_json['p'])
|
||||||
|
except (IOError, netrc.NetrcParseError) as err:
|
||||||
|
self._downloader.report_warning(
|
||||||
|
'Libsecret: %s' % error_to_compat_str(err))
|
||||||
|
|
||||||
return username, password
|
return username, password
|
||||||
|
|
||||||
def _get_login_info(self, username_option='username', password_option='password', netrc_machine=None):
|
def _get_login_info(self, username_option='username', password_option='password', netrc_machine=None):
|
||||||
@ -843,7 +861,7 @@ class InfoExtractor(object):
|
|||||||
|
|
||||||
downloader_params = self._downloader.params
|
downloader_params = self._downloader.params
|
||||||
|
|
||||||
# Attempt to use provided username and password or .netrc data
|
# Attempt to use provided username and password or .netrc data or libsecret data
|
||||||
if downloader_params.get(username_option) is not None:
|
if downloader_params.get(username_option) is not None:
|
||||||
username = downloader_params[username_option]
|
username = downloader_params[username_option]
|
||||||
password = downloader_params[password_option]
|
password = downloader_params[password_option]
|
||||||
|
@ -368,7 +368,7 @@ def parseOpts(overrideArguments=None):
|
|||||||
help='Video password (vimeo, smotri, youku)')
|
help='Video password (vimeo, smotri, youku)')
|
||||||
authentication.add_option(
|
authentication.add_option(
|
||||||
'--keyring',
|
'--keyring',
|
||||||
action='store_true', dest='keyring', default=False,
|
action='store_true', dest='usekeyring', default=False,
|
||||||
help='Retrieve password from keyring. Experimental.')
|
help='Retrieve password from keyring. Experimental.')
|
||||||
|
|
||||||
adobe_pass = optparse.OptionGroup(parser, 'Adobe Pass Options')
|
adobe_pass = optparse.OptionGroup(parser, 'Adobe Pass Options')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user