首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >youtube-dl提取的视频描述不包含换行符,并被截断

youtube-dl提取的视频描述不包含换行符,并被截断
EN

Stack Overflow用户
提问于 2020-07-09 15:33:01
回答 1查看 248关注 0票数 0

我有一个脚本,下载作为json文件的视频信息播放列表。

昨天我得到了带有\n换行符的视频描述,但今天这些换行符现在只是一个空格,提取的描述被截断了。我记得我的代码没有变化,youtube-dl也没有更新。

youtube改变了什么吗?还是我在什么地方弄错了?

Python 3.8.1,youtube-dl 2020.6.16.1

这是当前提取没有换行符的视频描述的代码。

代码语言:javascript
复制
import youtube_dl
import json

ydl_opts = {
    'ignoreerrors': True,
}

urls = ['http://youtu.be/wFWihZTktUw', 'http://youtu.be/QvuQH4_05LI']

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    print('Extracting playlist info...')
    playlist_info = []
    for idx, url in enumerate(urls):
        video_info = ydl.extract_info(url, download=False)
        if not video_info:
            continue
        
        properties = ['title', 'id', 'description']
        for k in list(video_info.keys()):
            if k not in properties:
                del video_info[k]

        playlist_info.append(video_info)

    with open(f'playlist_info.json', 'w') as fp:
        json.dump(playlist_info, fp)

换行的结果示例(昨天的结果):

代码语言:javascript
复制
[
    {
        "id": "wTJI_WuZSwE",
        "title": "The impossible chessboard puzzle",
        "description": "An information puzzle with an interesting twist\nSolution on Stand-up Maths: https://youtu.be/as7Gkm7Y7h4\nHome page: https://www.3blue1brown.com\nBrought to you by you: https://3b1b.co/chess-thanks\n\n------------------\n0:00 Introduction\n3:58 Visualizing the two-square case\n5:46 Visualizing the three-square case\n12:19 Proof that it's impossible\n16:22 Explicit painting of the hypercube\n------------------\n\nThese animations are largely made using manim, a scrappy open-source python library:  https://github.com/3b1b/manim\n\nIf you want to check it out, I feel compelled to warn you that it's not the most well-documented tool, and it has many other quirks you might expect in a library someone wrote with only their own use in mind.\n\nMusic by Vincent Rubinetti.\nDownload the music on Bandcamp:\nhttps://vincerubinetti.bandcamp.com/album/the-music-of-3blue1brown\n\nStream the music on Spotify:\nhttps://open.spotify.com/album/1dVyjwS8FBqXhRunaG5W5u\n\nIf you want to contribute translated subtitles or to help review those that have already been made by others and need approval, you can click the gear icon in the video and go to subtitles/cc, then \"add subtitles/cc\".  I really appreciate those who do this, as it helps make the lessons accessible to more people.\n\n------------------\n\n3blue1brown is a channel about animating math, in all senses of the word animate.  And you know the drill with YouTube, if you want to stay posted on new videos, subscribe: http://3b1b.co/subscribe\n\nVarious social media stuffs:\nWebsite: https://www.3blue1brown.com\nTwitter: https://twitter.com/3blue1brown\nReddit: https://www.reddit.com/r/3blue1brown\nInstagram: https://www.instagram.com/3blue1brown_animations/\nPatreon: https://patreon.com/3blue1brown\nFacebook: https://www.facebook.com/3blue1brown"
    },
    {
        "id": "QvuQH4_05LI",
        "title": "Tips to be a better problem solver [Last lecture] | Lockdown math ep. 10",
        "description": "Tips on problem-solving, with examples from geometry, trig, and probability.\nPast episodes with integrated quizzes: https://itempool.com/c/3b1b\nFull playlist: https://www.youtube.com/playlist?list=PLZHQObOWTQDP5CVelJJ1bNDouqrAhVPev\nHome page: https://www.3blue1brown.com\nBrought to you by you: https://3b1b.co/ldm-thanks\nHuge huge thanks to Ben Eater: https://www.youtube.com/user/eaterbc\nAnd Cam Christensen, creator of ItemPool: https://itempool.com/\n\nNotes by Ngân Vũ:\nhttps://twitter.com/ThuyNganVu/status/1265480770832855040\n\nMistakes:\n50:35, there should be a dx in the integral\n54:40, if you notice the mistake here and are inclined to complain, keep watching\n\n\n------------------\nVideo timeline (thanks to user \"noonesperfect\")\n0:34  9-Problem Solving Principles/Tip\n1:15  Question 1 (Probability)\n2:08  Who is Ben Eater?\n4:25  Inscribed angle theorem, θL=2*θs\n5:58  Tip-1\n7:48  Tip-2\n8:16  Question 2\n9:34  Answer 2\n10:29 Tip-3\n15:17 Tip-4\n22:48 Question 3\n25:56 Answer 3 (Marked incorrectly, Answer: Option D)\n26:31 Answer 1\n27:28 Explanation for Q1, Floor function\n30:38 Tip-5\n32:53 Tip-6\n33:36 Question 4\n34:43 Answer 4\n36:37 Question 5\n38:10 Answer 5\n41:48 Probability graph in Desmos\n44:08 Revisiting an alternating series sum for ln(2)\n47:29 Tip-7\n51:08 Tip-8\n55:23 Audience questions through tweets\n57:28 Tip-9\n58:29 Python programming for various probability question\n1:04:31 Arts created using Desmos graph tool with mathematical expressions\n1:05:54 Thank you, appreciation to the team and all.\n------------------\nThe live question setup with stats on-screen is powered by Itempool.\nhttps://itempool.com/\n\nCurious about other animations?\nhttps://www.3blue1brown.com/faq#manim\n\nMusic by Vincent Rubinetti.\nDownload the music on Bandcamp:\nhttps://vincerubinetti.bandcamp.com/album/the-music-of-3blue1brown\n\nStream the music on Spotify:\nhttps://open.spotify.com/album/1dVyjwS8FBqXhRunaG5W5u\n\nIf you want to contribute translated subtitles or to help review those that have already been made by others and need approval, you can click the gear icon in the video and go to subtitles/cc, then \"add subtitles/cc\".  I really appreciate those who do this, as it helps make the lessons accessible to more people.\n\n------------------\n\n3blue1brown is a channel about animating math, in all senses of the word animate.  And you know the drill with YouTube, if you want to stay posted on new videos, subscribe: http://3b1b.co/subscribe\n\nVarious social media stuffs:\nWebsite: https://www.3blue1brown.com\nTwitter: https://twitter.com/3blue1brown\nReddit: https://www.reddit.com/r/3blue1brown\nInstagram: https://www.instagram.com/3blue1brown_animations/\nPatreon: https://patreon.com/3blue1brown\nFacebook: https://www.facebook.com/3blue1brown"
    }

没有换行符和截断描述的示例结果(今天的结果):

代码语言:javascript
复制
[
    {
        "id": "wTJI_WuZSwE",
        "title": "The impossible chessboard puzzle",
        "description": "An information puzzle with an interesting twist Solution on Stand-up Maths: https://youtu.be/as7Gkm7Y7h4 Home page: https://www.3blue1brown.com Brought to yo..."
    },
    {
        "id": "QvuQH4_05LI",
        "title": "Tips to be a better problem solver [Last lecture] | Lockdown math ep. 10",
        "description": "Tips on problem-solving, with examples from geometry, trig, and probability. Past episodes with integrated quizzes: https://itempool.com/c/3b1b Full playlist..."
    }
]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-09 15:47:11

这是一个似乎从今天开始的issue with youtube-dl。这很可能与Youtube方面的变化有关。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62809641

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档