'Attempt to log in to YouTube.
True is returned if successful or skipped.
False is returned if login failed.
If _LOGIN_REQUIRED is set and no authentication was provided, an error is raised.'

def _login(self):

    (username, password) = self._get_login_info()
    if (username is None):
        if self._LOGIN_REQUIRED:
            raise ExtractorError((u'No    login    info    available,    needed    for    using    %s.' % self.IE_NAME), expected=True)
        return True
    login_page = self._download_webpage(self._LOGIN_URL, None, note=u'Downloading    login    page', errnote=u'unable    to    fetch    login    page', fatal=False)
    if (login_page is False):
        return
    login_form = self._hidden_inputs(login_page)
    def req(url, f_req, note, errnote):
        data = login_form.copy()
        data.update({u'pstMsg': 1, u'checkConnection': u'youtube', u'checkedDomains': u'youtube', u'hl': u'en', u'deviceinfo': u'[null,null,null,[],null,"US",null,null,[],"GlifWebSignIn",null,[null,null,[]]]', u'f.req': json.dumps(f_req), u'flowName': u'GlifWebSignIn', u'flowEntry': u'ServiceLogin'})
        return self._download_json(url, None, note=note, errnote=errnote, transform_source=(lambda s: re.sub(u'^[^[]*', u'', s)), fatal=False, data=urlencode_postdata(data), headers={u'Content-Type': u'application/x-www-form-urlencoded;charset=utf-8', u'Google-Accounts-XSRF': 1})
    def warn(message):
        self._downloader.report_warning(message)
    lookup_req = [username, None, [], None, u'US', None, None, 2, False, True, [None, None, [2, 1, None, 1, u'https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252F%26action_handle_signin%3Dtrue%26hl%3Den%26app%3Ddesktop%26feature%3Dsign_in_button&hl=en&service=youtube&uilel=3&requestPath=%2FServiceLogin&Page=PasswordSeparationSignIn', None, [], 4], 1, [None, None, []], None, None, None, True], username]
    lookup_results = req(self._LOOKUP_URL, lookup_req, u'Looking    up    account    info', u'Unable    to    look    up    account    info')
    if (lookup_results is False):
        return False
    user_hash = try_get(lookup_results, (lambda x: x[0][2]), compat_str)
    if (not user_hash):
        warn(u'Unable    to    extract    user    hash')
        return False
    challenge_req = [user_hash, None, 1, None, [1, None, None, None, [password, None, True]], [None, None, [2, 1, None, 1, u'https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252F%26action_handle_signin%3Dtrue%26hl%3Den%26app%3Ddesktop%26feature%3Dsign_in_button&hl=en&service=youtube&uilel=3&requestPath=%2FServiceLogin&Page=PasswordSeparationSignIn', None, [], 4], 1, [None, None, []], None, None, None, True]]
    challenge_results = req(self._CHALLENGE_URL, challenge_req, u'Logging    in', u'Unable    to    log    in')
    if (challenge_results is False):
        return
    login_res = try_get(challenge_results, (lambda x: x[0][5]), list)
    if login_res:
        login_msg = try_get(login_res, (lambda x: x[5]), compat_str)
        warn(((u'Unable    to    login:    %s' % u'Invalid    password') if (login_msg == u'INCORRECT_ANSWER_ENTERED') else login_msg))
        return False
    res = try_get(challenge_results, (lambda x: x[0][(-1)]), list)
    if (not res):
        warn(u'Unable    to    extract    result    entry')
        return False
    tfa = try_get(res, (lambda x: x[0][0]), list)
    if tfa:
        tfa_str = try_get(tfa, (lambda x: x[2]), compat_str)
        if (tfa_str == u'TWO_STEP_VERIFICATION'):
            status = try_get(tfa, (lambda x: x[5]), compat_str)
            if (status == u'QUOTA_EXCEEDED'):
                warn(u'Exceeded    the    limit    of    TFA    codes,    try    later')
                return False
            tl = try_get(challenge_results, (lambda x: x[1][2]), compat_str)
            if (not tl):
                warn(u'Unable    to    extract    TL')
                return False
            tfa_code = self._get_tfa_info(u'2-step    verification    code')
            if (not tfa_code):
                warn(u'Two-factor    authentication    required.    Provide    it    either    interactively    or    with    --twofactor    <code>(Note    that    only    TOTP    (Google    Authenticator    App)    codes    work    at    this    time.)')
                return False
            tfa_code = remove_start(tfa_code, u'G-')
            tfa_req = [user_hash, None, 2, None, [9, None, None, None, None, None, None, None, [None, tfa_code, True, 2]]]
            tfa_results = req(self._TFA_URL.format(tl), tfa_req, u'Submitting    TFA    code', u'Unable    to    submit    TFA    code')
            if (tfa_results is False):
                return False
            tfa_res = try_get(tfa_results, (lambda x: x[0][5]), list)
            if tfa_res:
                tfa_msg = try_get(tfa_res, (lambda x: x[5]), compat_str)
                warn(((u'Unable    to    finish    TFA:    %s' % u'Invalid    TFA    code') if (tfa_msg == u'INCORRECT_ANSWER_ENTERED') else tfa_msg))
                return False
            check_cookie_url = try_get(tfa_results, (lambda x: x[0][(-1)][2]), compat_str)
    else:
        check_cookie_url = try_get(res, (lambda x: x[2]), compat_str)
    if (not check_cookie_url):
        warn(u'Unable    to    extract    CheckCookie    URL')
        return False
    check_cookie_results = self._download_webpage(check_cookie_url, None, u'Checking    cookie', fatal=False)
    if (check_cookie_results is False):
        return False
    if (u'https://myaccount.google.com/' not in check_cookie_results):
        warn(u'Unable    to    log    in')
        return False
    return True
