Streaming audio (YouTube)

前端 未结 2 1128
盖世英雄少女心
盖世英雄少女心 2021-01-13 16:55

I\'m writing a CLI for a music-media-platform. One of the features is going to be that you can directly play YouTube videos from the CLI. I don\'t really have an idea of how

相关标签:
2条回答
  • 2021-01-13 17:29

    It appears that KeepVid is simply a JavaScript bookmarklet that links you to a KeepVid download page where you can then download the YouTube video in any one of a variety of formats. So, unless you want to figure out how to stream the file that it links you to, it's not easily doable. You'd have to scrape the page returned and figure out which URL you wanted to download, and then you'd have to stream from that URL (and some of the formats may or may not be streamable anyway).

    And as an aside, even though they don't have a terms of service specified, I'd imagine that since they appear to be mostly advertisement-supported that abusing their functionality by going around their advertisement-supported webpage would be ethically questionable.

    0 讨论(0)
  • 2021-01-13 17:41

    You need two things to be able to download a YouTube video, the video id, which is represented by the v= section of the URL, and a hidden field t= which is present in the page source. I have no idea what this t value is, but it's what you need :)

    You can then download the video using a URL in the format;

    http://www.youtube.com/get_video?video_id=*******&t=*******
    

    Where the stars represent the values obtained.

    I'm guessing you can ask for the video id from user input, as it's straightforward to obtain. Your program would then download the HTML source for that video, parse the source for the t value, then download the video using the newly constructed URL.

    For example, if you open this link in your browser, it should download the video, or you can use a downloading program such as Wget;

    http://www.youtube.com/get_video?video_id=3HrSN7176XI&t=vjVQa1PpcFNM4c8MbEhsnGaNvYKoYERIJ-hK7ErLpUI=

    0 讨论(0)
提交回复
热议问题