Streaming audio (YouTube)

前端 未结 2 1127
盖世英雄少女心
盖世英雄少女心 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: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=

提交回复
热议问题