Описание видео, извлеченное с youtube-dl, не содержит символов новой строки и усечено - PullRequest
0 голосов
/ 09 июля 2020

У меня есть сценарий, который загружает список воспроизведения с информацией о видео в виде файла json.

Вчера я получил описание видео с \n символами новой строки, но сегодня эти новые строки теперь являются просто пробелом и извлеченными описание усечено. Я не помню никаких изменений в моем коде и обновлений до youtube-dl.

Youtube что-то изменил? Или я где-то ошибся?

Python 3.8.1, youtube-dl 2020.6.16.1

Вот код, который в настоящее время извлекает описание видео без символов новой строки.

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)

Пример результата с символом новой строки (вчерашний результат):

[
    {
        "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"
    }
*

Пример результата без перевода строки и усеченного описания (сегодняшний результат):

[
    {
        "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..."
    }
]

1 Ответ

1 голос
/ 09 июля 2020

Это проблема с youtube-dl , которая, похоже, началась сегодня. Скорее всего, это связано с изменениями на стороне Youtube.

...