問題描述
Nhận thời lượng video trên youtube từ URL với bash (Get youtube video duration from URL with bash)
How can I get a youtube video duration from it’s URL with bash? Preferably using curl, and without having to mess with authentications and API keys.
If possible, I’d like to know the details (i.e. I think the results are given in json, so maybe a way to get only the duration from that), but getting the duration is the main problem.
參考解法
方法 1:
Well, if you don't want to use the API and would like to use curl, here's a super ugly answer to match :)
Marks‑MacBook‑Air:~ mstanislav$ curl ‑s http://www.youtube.com/watch?v=dQw4w9WgXcQ |grep '<meta itemprop="duration"'
<meta itemprop="duration" content="PT3M33S">
The PT3M33S means 3 minutes and 33 seconds, which is the duration. Just process the data from there (via shell script or otherwise you're using curl with). Be kind voters, just answering the question as requested ;)
For the sake of everything happy, here's using curl with the API, which, does not require a developer key unless you are uploading or writing data.
curl ‑s 'http://gdata.youtube.com/feeds/api/videos/dQw4w9WgXcQ?v=2&alt=jsonc'
(by user137369、Mark Stanislav)