Skip to content

Feature Request/TODO: 当出现 Sign in to confirm you’re not a bot. 时向 ydl_opts 中添加从 Firefox 中获取 cookies 的参数 #5

Description

@Ayx03

由于读取 cookies 需要一些时间应该考虑在需要时再添加这一参数重新运行,我目前使用的代码:

def download(youtube_url, folder_name):
    ydl_opts = {
        # outtmpl 格式化下载后的文件名,避免默认文件名太长无法保存
        "outtmpl": "./videos/"
        + str(folder_name)
        + "/%(id)s.mp4",
        'cookiesfrombrowser': ('firefox',)  # 从 Firefox 获取 cookies,不知为和没有逗号会报错
    }

    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        ydl.download([youtube_url])


def get_info(url):
    ydl_opts = {
        #'proxy': 'http://127.0.0.1:10809',
        'cookiesfrombrowser': ('firefox',)  # 从 Firefox 获取 cookies,不知为和没有逗号会报错
    }
    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        info = ydl.extract_info(url, download=False)
        return info

其他 Chromium-based 浏览器(Brave、Chrome、Edge)的 cookies 似乎无法直接被 yt-dlp 获取,或在浏览器正在运行时无法获取。

PS C:\Users\Null\u2b> yt-dlp https://www.youtube.com/watch?v=gq2OcwMpcYg --cookies-from-browser brave
Extracting cookies from brave
ERROR: Could not copy Chrome cookie database. See  https://github.com/yt-dlp/yt-dlp/issues/7271  for more info
ERROR: Could not copy Chrome cookie database. See  https://github.com/yt-dlp/yt-dlp/issues/7271  for more info
PS C:\Users\Null\u2b> yt-dlp https://www.youtube.com/watch?v=gq2OcwMpcYg --cookies-from-browser chrome
Extracting cookies from chrome
ERROR: Could not copy Chrome cookie database. See  https://github.com/yt-dlp/yt-dlp/issues/7271  for more info
ERROR: Could not copy Chrome cookie database. See  https://github.com/yt-dlp/yt-dlp/issues/7271  for more info
PS C:\Users\Null\u2b> yt-dlp https://www.youtube.com/watch?v=gq2OcwMpcYg --cookies-from-browser edge    
Extracting cookies from edge 
[Cookies] Loading cookie      0/  1817ERROR: Failed to decrypt with DPAPI. See  https://github.com/yt-dlp/yt-dlp/issues/10927  for more info 
ERROR: Failed to decrypt with DPAPI. See  https://github.com/yt-dlp/yt-dlp/issues/10927  for more info

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions