使用you-get下载优酷播单视频

in 其他 | 25 comments | 阅读量: 1,444

you-get是python制作的一个命令行工具,但是目前不支持优酷的播单视频下载功能,自己写了一个小脚本来下载.

依赖库安装

代码如下(下载任何播单只需要更换`playlist_id`)
import requests as rq
import re
import json
from bs4 import BeautifulSoup
from you_get import common as you_get

# parameters
playlist_id = 49399706  # 播单页面的id, 可以在url中查看
page = 1  # 无需更改


headers = {
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36',
    'Accept': 'ext/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
    'Referer': 'http://v.youku.com/v_show/id_XMjY4NDI3NjE2OA==.html?spm=a2h1n.8251843.playList.5~5~A&f=49399706&o=0'
}

urls = set()
failed_urls = set()


while True:
    print("===== downloading the {} page =====".format(page))
    json_data = rq.get("http://list.youku.com/albumlist/items?id={}&page={}&size=20&ascending=1&callback=tuijsonp5".format(playlist_id, page)).text
    json_data = re.search("\((.*)\)", json_data).group(1)

    video_data = json.loads(json_data)['html']
    if not video_data:
        print("===== all the pages have scraped! =====")
        break

    soup = BeautifulSoup(video_data, 'html5lib')

    video_tags = soup.find_all(href=re.compile("v.youku.com"))

    for each in video_tags:
        video_url = "http:" + each.get('href')
        urls.add(video_url)

    page += 1

print("thr num of all the video is :{}".format(len(urls)))
# begin download
for each in urls:
    try:
        you_get.any_download(each, output_dir="../../Videos/tensorflow/", merge=True)
    except Exception as e:
        print(e)
        failed_urls.add(each)
        print("download {} failed".format(each))

for each in failed_urls:
    print(each)
Responses
  1. low interest loan best online payday loans bank personal loan [url=https://cashadvanceonline.us.org/#]fast payday loans[/url]

    Reply
  2. instant approval personal loans fast payday loans personal installment loan [url=https://onlineloan.us.org/#]same day payday loans[/url]

    Reply
  3. of payday loan payday loans no credit check payday loans 1 hour [url=https://cashloansonline.us.org/#]payday loans[/url]

    Reply
  4. online loans fast payday loans payday loans no faxing no credit checks [url=https://onlinepaydayloan.us.org/#]payday loans direct lender[/url]

    Reply
  5. buy research paper [url=http://writingpaperqze.org/#]research paper service[/url]
    thesis dissertation [url=http://writethesisdcv.org/#]thesis writing[/url]
    thesis writing help [url=http://writinghelprvs.org/#]essay help[/url]
    create business plan [url=http://writebusinessplanatb.org/#]small business plans[/url]
    dissertation papers [url=http://essaypapersus.org/#]buy research paper[/url]

    Reply
  6. american cash loans online payday loans no credit check auto loans for bad credit [url=https://paydayloans-online.us.org/#]best payday loans[/url]

    Reply
  7. easy loans no credit check online payday loans no credit check car title & payday loan [url=https://cashadvanceonline.us.org/#]fast payday loans[/url]

    Reply
  8. 30 day payday loans same day payday loans fast cash personal loans [url=https://onlinepaydayloan.us.org/#]online payday loans no credit check[/url]

    Reply
  9. online cash loans effects side viagra fast payday loan online [url=https://cashloansonline.us.org/#]viagra pfizer online[/url]

    Reply
  10. cash advance loan payday loans online same day small loans [url=https://onlineloan.us.org/#]best online payday loans[/url]

    Reply
  11. buy cialis las vegas
    reddit cialis online http://canadian-pharmasy.com

    Reply
  12. viagra generique acheter viagra en ligne cialis ou viagra [url=http://vieillemaman.com/#]viagra achat[/url]

    Reply
  13. viagra stories viagra generic cheap viagra canada [url=https://www.purseinstock.com/#]viagra prices[/url]

    Reply
  14. buy herbal viagra viagra dosing cheap viagra pills [url=http://canadiannowv.com/#]alcohol and viagra[/url]

    Reply
  15. buy female viagra lowest price viagra buy viagra [url=http://usa77www.com/#]real viagra[/url]

    Reply
  16. viagra pill п»їviagra what does viagra do [url=http://usa77www.com/#]cheap viagra[/url]

    Reply
  17. wo kann man viagra kaufen viagra online kaufen ohne rezept viagra kaufen deutschland [url=http://kostenlosdeutschporno.net/#]wo kann man viagra kaufen[/url]

    Reply
  18. prix viagra viagra homme viagra sans ordonnance [url=http://vieillemaman.com/#]viagra pour homme[/url]

    Reply
  19. viagra online order cheap viagra india viagra sildenafil citrate [url=http://canadiannowv.com/#]lowest cost viagra[/url]

    Reply
  20. natГјrliches viagra viagra kaufen deutschland viagra online [url=http://kostenlosdeutschporno.net/#]was ist viagra[/url]

    Reply
  21. viagra sales purchase viagra online viagra online purchase [url=https://www.purseinstock.com/#]canada viagra[/url]

    Reply
  22. online cheap viagra http://webcreationbcn.com/ brand generic viagra

    Reply
  23. viagra brand buy http://wrestlemaniaresultslive.com/ female viagra pill

    Reply
  24. online viagra prescription best place to buy generic viagra online canada viagra generic [url=http://fviagrajjj.com/#]order viagra online[/url]

    Reply
  25. admin

    你好,我想问下,request请求的那个网址是怎么发现的,我在chrome下F12没看到这个网址啊。

    Reply