芒果TV視頻的地址解析下載

以芒果TV播放頁(yè)地址http://www.mgtv.com/v/10/167938/c/2942052.html?為例回溺,說(shuō)說(shuō)如何解析得到真實(shí)視頻地址。

提取視頻ID(即vid)

芒果TV的視頻ID可以從播放頁(yè)地址中得到抡谐。上述播放頁(yè)地址中铁追,2942052就是視頻ID.

請(qǐng)求接口

以視頻ID為參數(shù)請(qǐng)求接口 http://v.api.mgtv.com/player/video?retry=1&video_id=2942052 返回的JSON數(shù)據(jù)如下:

{
  "status": 200,
  "msg": "",
  "data": {
    "user": {
      "id": "",
      "uuid": "",
      "isvip": "0",
      "purview": "200",
      "ip": "1.95.84.161"
    },
    "info": {
      "video_id": "3467275",
      "root_id": "10",
      "root_name": "新聞",
      "collection_id": "298221",
      "collection_name": "午間新聞2016",
      "clip_type": "2",
      "title": "長(zhǎng)沙著力解決房產(chǎn)證遺留問(wèn)題",
      "sub_title": "長(zhǎng)沙著力解決房產(chǎn)證遺留問(wèn)題",
      "series": "",
      "url": "http://www.hunantv.com/v/10/298221/c/3467275.html",
      "thumb": "http://2img.mgtv.com/preview/sp_images/2016/xinwen/129747/2942052/20160106130629996.jpg_220x123.jpg",
      "desc": "長(zhǎng)沙著力解決房產(chǎn)證遺留問(wèn)題",
      "icon": "",
      "ispayment": "0",
      "isdrm": "0",
      "isiplimit": "0",
      "duration": "37",
      "trialtime": "300",
      "scale": "16:9",
      "istry": "0",
      "price_vip": "2.5",
      "price_novip": "5",
      "price": "0"
    },
    "stream": [
      {
        "url": "/vod.do?fmt=2&pno=1000&fid=AD299930AAB40177B5F10D4AF1471071&now=1478094895&gsid=a599287b6be0403988d92fae7a7f930a&file=%2Fmp4%2F2016%2Fxinwen%2Fwjxw_46493%2FAD299930AAB40177B5F10D4AF1471071_20160106_1_1_388_mp4%2F27647495F355811D49F4A26327EC35DC.m3u8",
        "name": "標(biāo)清"
      },
      {
        "url": "/vod.do?fmt=2&pno=1000&fid=CBA97B6D9BA73EB84283817B1FE38FE8&now=1478094895&gsid=7f3a643f38dc469d81fd8bc942c6aa89&file=%2Fmp4%2F2016%2Fxinwen%2Fwjxw_46493%2FCBA97B6D9BA73EB84283817B1FE38FE8_20160106_1_1_719_mp4%2FB2B29E3A4D135CB9B86B85841D12139C.m3u8",
        "name": "高清"
      },
      {
        "url": "/vod.do?fmt=2&pno=1000&fid=593B5886239791678A15C4A872A60B08&now=1478094895&gsid=79b4eb17ce3b441084b4828230fdfdd7&file=%2Fmp4%2F2016%2Fxinwen%2Fwjxw_46493%2F593B5886239791678A15C4A872A60B08_20160106_1_1_1100_mp4%2FE2017FFD796C00BB185FBC30B6D7360B.m3u8",
        "name": "超清"
      }
    ],
    "stream_domain": [
      "http://disp.titan.mgtv.com",
      "http://disp1.titan.mgtv.com",
      "http://disp2.titan.mgtv.com"
    ],
    "share": {
      "weibo": "http://service.weibo.com/share/share.php?appkey=152400019&url=http%3A%2F%2Fwww.hunantv.com%2Fv%2F10%2F298221%2Fc%2F3467275.html%3Ffrom%3Dwb&title=%E9%95%BF%E6%B2%99%E7%9D%80%E5%8A%9B%E8%A7%A3%E5%86%B3%E6%88%BF%E4%BA%A7%E8%AF%81%E9%81%97%E7%95%99%E9%97%AE%E9%A2%98&content=utf-8&pic=http://2img.mgtv.com/preview/sp_images/2016/xinwen/129747/2942052/20160106130629996.jpg_220x123.jpg",
      "weixin": "http://www.hunantv.com/share/weixin/?url=http://www.hunantv.com/v/10/298221/c/3467275.html&title=%E9%95%BF%E6%B2%99%E7%9D%80%E5%8A%9B%E8%A7%A3%E5%86%B3%E6%88%BF%E4%BA%A7%E8%AF%81%E9%81%97%E7%95%99%E9%97%AE%E9%A2%98",
      "qq": "http://connect.qq.com/widget/shareqq/index.html?title=%E9%95%BF%E6%B2%99%E7%9D%80%E5%8A%9B%E8%A7%A3%E5%86%B3%E6%88%BF%E4%BA%A7%E8%AF%81%E9%81%97%E7%95%99%E9%97%AE%E9%A2%98&desc=%E5%9C%A8%E8%8A%92%E6%9E%9CTV%E4%B8%8A%E7%9C%8B%E8%A7%81%E8%BF%99%E6%9D%A1%E8%A7%86%E9%A2%91%E8%BF%98%E4%B8%8D%E9%94%99%E5%93%A6%EF%BC%9A%E9%95%BF%E6%B2%99%E7%9D%80%E5%8A%9B%E8%A7%A3%E5%86%B3%E6%88%BF%E4%BA%A7%E8%AF%81%E9%81%97%E7%95%99%E9%97%AE%E9%A2%98&site=%E8%8A%92%E6%9E%9CTV&url=http://www.hunantv.com/v/10/298221/c/3467275.html&tpa=dW5pb25faWQ9MTAzMjUyXzEwMDAwMV8wMV8wMQ",
      "qzone": "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=http://www.hunantv.com/v/10/298221/c/3467275.html&title=%E9%95%BF%E6%B2%99%E7%9D%80%E5%8A%9B%E8%A7%A3%E5%86%B3%E6%88%BF%E4%BA%A7%E8%AF%81%E9%81%97%E7%95%99%E9%97%AE%E9%A2%98"
    },
    "skipad": [
      "http://i1.hunantv.com/ui/2015/images/skipad.jpg",
      "http://order.mgtv.com/pay/pc/index.html"
    ],
    "tips": {
      "title": "會(huì)員跳廣告(買(mǎi)12送3)",
      "url": "http://order.mgtv.com/pay/pc/index.html",
      "img": ""
    },
    "frame": {
      "second": [],
      "images": []
    },
    "points": {
      "start": [],
      "end": [],
      "content": []
    },
    "next": {
      "title": "長(zhǎng)沙2016春運(yùn)“兩證”核發(fā)",
      "img": "http://0img.mgtv.com/preview/sp_images/2016/xinwen/129747/2942051/20160106125233250.jpg_220x123.jpg",
      "url": "/v/10/298221/c/3467257.html",
      "duration": "23"
    }
  }
}

我們可以看到姻成,stream列表里面共有3個(gè)清晰度也祠,stream_domain列表里面共有3個(gè)域名昙楚。假如選擇超清清晰度對(duì)應(yīng)的url,然后在url前面加上3個(gè)域名中的任一個(gè)诈嘿,構(gòu)成一個(gè)地址 http://disp.titan.mgtv.com/vod.do?fmt=2&pno=1000&fid=593B5886239791678A15C4A872A60B08&now=1478094895&gsid=79b4eb17ce3b441084b4828230fdfdd7&file=%2Fmp4%2F2016%2Fxinwen%2Fwjxw_46493%2F593B5886239791678A15C4A872A60B08_20160106_1_1_1100_mp4%2FE2017FFD796C00BB185FBC30B6D7360B.m3u8

請(qǐng)求這個(gè)地址得到的也是一個(gè)JSON格式數(shù)據(jù):

{
  "ver": "2015-02-25 v1.0.1",
  "isothercdn": "1",
  "info": "http://pcvideoaliyun.titan.mgtv.com/mp4/2016/xinwen/wjxw_46493/593B5886239791678A15C4A872A60B08_20160106_1_1_1100_mp4/E2017FFD796C00BB185FBC30B6D7360B.m3u8?uuid=66e980da9e284bbe8222cae71fcc650a&t=581a6306&pno=1000&sign=ccedb70160e9136870fbd72864f11bb2&win=3600&srgid=25021&urgid=81&srgids=25021&nid=25021&payload=usertoken%3dhit%3d0%5eruip%3d23024801&rdur=21600&arange=0&limitrate=0&fid=593B5886239791678A15C4A872A60B08&ver=0x03",
  "status": "ok",
  "loc": "81-1.95.84.161",
  "t": "1478095494",
  "idc": "aliyun_cdn"
}

其中堪旧,info是一個(gè)m3u8地址,請(qǐng)求m3u8地址 http://pcvideoaliyun.titan.mgtv.com/mp4/2016/xinwen/wjxw_46493/593B5886239791678A15C4A872A60B08_20160106_1_1_1100_mp4/E2017FFD796C00BB185FBC30B6D7360B.m3u8?uuid=66e980da9e284bbe8222cae71fcc650a&t=581a6306&pno=1000&sign=ccedb70160e9136870fbd72864f11bb2&win=3600&srgid=25021&urgid=81&srgids=25021&nid=25021&payload=usertoken%3dhit%3d0%5eruip%3d23024801&rdur=21600&arange=0&limitrate=0&fid=593B5886239791678A15C4A872A60B08&ver=0x03 奖亚,得到如下m3u8內(nèi)容:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:11
#EXT-X-MEDIA-SEQUENCE:0
#EXT-MGTV-VIDEO-WIDTH:1280
#EXT-MGTV-VIDEO-HEIGHT:720
#EXT-MGTV-File-SIZE:699360
#EXTINF:5.080000,
5976B00263913818AE86F0122D7B766F_0_5080_1101_v02_mp4.ts?uuid=66e980da9e284bbe8222cae71fcc650a&t=581a6306&pno=1000&sign=ccedb70160e9136870fbd72864f11bb2&win=3600&srgid=25021&urgid=81&srgids=25021&nid=25021&payload=usertoken%3dhit%3d0%5eruip%3d23024801&rdur=21600&arange=0&limitrate=0&fid=593B5886239791678A15C4A872A60B08&ver=0x03
#EXT-MGTV-File-SIZE:512488
#EXTINF:5.000000,
01FC81B6CE4051E6CA9D990A72FF9B61_5080_10080_819_v02_mp4.ts?uuid=66e980da9e284bbe8222cae71fcc650a&t=581a6306&pno=1000&sign=ccedb70160e9136870fbd72864f11bb2&win=3600&srgid=25021&urgid=81&srgids=25021&nid=25021&payload=usertoken%3dhit%3d0%5eruip%3d23024801&rdur=21600&arange=0&limitrate=0&fid=593B5886239791678A15C4A872A60B08&ver=0x03
#EXT-MGTV-File-SIZE:1392140
#EXTINF:10.000000,
E1A9A55392CA363DD79F9F34C5AB1D45_10080_20080_1113_v02_mp4.ts?uuid=66e980da9e284bbe8222cae71fcc650a&t=581a6306&pno=1000&sign=ccedb70160e9136870fbd72864f11bb2&win=3600&srgid=25021&urgid=81&srgids=25021&nid=25021&payload=usertoken%3dhit%3d0%5eruip%3d23024801&rdur=21600&arange=0&limitrate=0&fid=593B5886239791678A15C4A872A60B08&ver=0x03
#EXT-MGTV-File-SIZE:2260136
#EXTINF:10.000000,
645A04A7B53530E5FA5CB5FCCF772A35_20080_30080_1808_v02_mp4.ts?uuid=66e980da9e284bbe8222cae71fcc650a&t=581a6306&pno=1000&sign=ccedb70160e9136870fbd72864f11bb2&win=3600&srgid=25021&urgid=81&srgids=25021&nid=25021&payload=usertoken%3dhit%3d0%5eruip%3d23024801&rdur=21600&arange=0&limitrate=0&fid=593B5886239791678A15C4A872A60B08&ver=0x03
#EXT-MGTV-File-SIZE:926652
#EXTINF:7.080000,
B7D675030CAB254C04330380F8A8A2AF_30080_37160_1047_v02_mp4.ts?uuid=66e980da9e284bbe8222cae71fcc650a&t=581a6306&pno=1000&sign=ccedb70160e9136870fbd72864f11bb2&win=3600&srgid=25021&urgid=81&srgids=25021&nid=25021&payload=usertoken%3dhit%3d0%5eruip%3d23024801&rdur=21600&arange=0&limitrate=0&fid=593B5886239791678A15C4A872A60B08&ver=0x03
#EXT-X-ENDLIST

那些不以#號(hào)開(kāi)頭的行就是視頻分段地址的一部分淳梦。只不過(guò),完整的視頻分段地址需要構(gòu)造出來(lái)昔字。如何構(gòu)造呢爆袍?我們用瀏覽器開(kāi)發(fā)者工具觀(guān)察到最終的視頻地址是這樣的:

http://pcvideoaliyun.titan.mgtv.com/mp4/2016/xinwen/wjxw_46493/CBA97B6D9BA73EB84283817B1FE38FE8_20160106_1_1_719_mp4/B4FBE7EEE4C4E58313038787AFA1CBF7_30080_37160_773_v02_mp4.ts?uuid=b6e729c483cb4ebfa2ca6cccc08bacff&t=581a661e&pno=1000&sign=b454c0a00e9240c96c877662329699cb&win=3600&srgid=25021&urgid=81&srgids=25021&nid=25021&payload=usertoken%3dhit%3d0%5eruip%3d23024801&rdur=21600&arange=0&limitrate=0&fid=CBA97B6D9BA73EB84283817B1FE38FE8&ver=0x03&r=309659237103548&tt=3167&yfmode=3

而m3u8地址是這樣的:

http://pcvideoaliyun.titan.mgtv.com/mp4/2016/xinwen/wjxw_46493/593B5886239791678A15C4A872A60B08_20160106_1_1_1100_mp4/E2017FFD796C00BB185FBC30B6D7360B.m3u8?uuid=66e980da9e284bbe8222cae71fcc650a&t=581a6306&pno=1000&sign=ccedb70160e9136870fbd72864f11bb2&win=3600&srgid=25021&urgid=81&srgids=25021&nid=25021&payload=usertoken=hit=0%5Eruip=23024801&rdur=21600&arange=0&limitrate=0&fid=593B5886239791678A15C4A872A60B08&ver=0x03

這兩個(gè)地址的前面一部分是一樣的,有木有李滴?這下該知道如何構(gòu)造完整的視頻分段地址了吧螃宙。

Python代碼示例

import requests
import json
import re
import os
import urlparse
import random

vid = re.search(r'/(\d+).html', 'http://www.mgtv.com/v/10/167938/c/2942052.html').group(1)
r = requests.get('http://v.api.mgtv.com/player/video?retry=1&video_id=%s' % vid)
data = json.loads(r.content)
streams = data['data']['stream']
stream_domains = data['data']['stream_domain']
for stream in streams:
    print stream['name']
    stream_domain = random.choice(stream_domains)
    url = urlparse.urljoin(stream_domain, stream['url'])
    r = requests.get(url)
    data = json.loads(r.content)
    m3u8_url = data['info']
    parse_result = urlparse.urlparse(m3u8_url)
    r = requests.get(m3u8_url)
    segments = re.findall(r'^[^#][^\r][^\n]*', r.content, re.MULTILINE)
    for s in segments:
        print '%s://%s%s/%s' % (parse_result.scheme, parse_result.netloc, os.path.dirname(parse_result.path), s)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市所坯,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌挂捅,老刑警劉巖芹助,帶你破解...
    沈念sama閱讀 206,214評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異闲先,居然都是意外死亡状土,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,307評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門(mén)伺糠,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)蒙谓,“玉大人,你說(shuō)我怎么就攤上這事训桶±弁裕” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 152,543評(píng)論 0 341
  • 文/不壞的土叔 我叫張陵舵揭,是天一觀(guān)的道長(zhǎng)谤专。 經(jīng)常有香客問(wèn)我,道長(zhǎng)午绳,這世上最難降的妖魔是什么置侍? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 55,221評(píng)論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上蜡坊,老公的妹妹穿的比我還像新娘杠输。我一直安慰自己,他們只是感情好秕衙,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,224評(píng)論 5 371
  • 文/花漫 我一把揭開(kāi)白布蠢甲。 她就那樣靜靜地躺著,像睡著了一般灾梦。 火紅的嫁衣襯著肌膚如雪峡钓。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 49,007評(píng)論 1 284
  • 那天若河,我揣著相機(jī)與錄音能岩,去河邊找鬼。 笑死萧福,一個(gè)胖子當(dāng)著我的面吹牛拉鹃,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播鲫忍,決...
    沈念sama閱讀 38,313評(píng)論 3 399
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼膏燕,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了悟民?” 一聲冷哼從身側(cè)響起坝辫,我...
    開(kāi)封第一講書(shū)人閱讀 36,956評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎射亏,沒(méi)想到半個(gè)月后近忙,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,441評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡智润,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,925評(píng)論 2 323
  • 正文 我和宋清朗相戀三年及舍,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片窟绷。...
    茶點(diǎn)故事閱讀 38,018評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡锯玛,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出兼蜈,到底是詐尸還是另有隱情攘残,我是刑警寧澤,帶...
    沈念sama閱讀 33,685評(píng)論 4 322
  • 正文 年R本政府宣布饭尝,位于F島的核電站肯腕,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏钥平。R本人自食惡果不足惜实撒,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,234評(píng)論 3 307
  • 文/蒙蒙 一姊途、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧知态,春花似錦捷兰、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,240評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至其做,卻和暖如春顶考,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背妖泄。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,464評(píng)論 1 261
  • 我被黑心中介騙來(lái)泰國(guó)打工驹沿, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人蹈胡。 一個(gè)月前我還...
    沈念sama閱讀 45,467評(píng)論 2 352
  • 正文 我出身青樓渊季,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親罚渐。 傳聞我的和親對(duì)象是個(gè)殘疾皇子却汉,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,762評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容

  • 微博視頻播放頁(yè)地址有如下幾類(lèi): http://weibo.com/p/230444897a6a26db6d0226...
    Maslino閱讀 28,333評(píng)論 3 2
  • 太長(zhǎng)了,還是轉(zhuǎn)載吧...今天在看博客的時(shí)候荷并,無(wú)意中發(fā)現(xiàn)了@Trinea在GitHub上的一個(gè)項(xiàng)目Android開(kāi)源...
    龐哈哈哈12138閱讀 20,140評(píng)論 3 283
  • 有那么一些人 不論何事 不問(wèn)原因 你總會(huì)站在ta那邊 即便那是件錯(cuò)事 他人可能會(huì)覺(jué)得 是那么的幼稚 不可理喻...
    大頭花閱讀 225評(píng)論 0 0
  • 結(jié)論合砂,唯一可行的方法是3,把matlab打包成exe源织,在unity中用代碼調(diào)用exe 直接在unity中使用MAT...
    Reyuwei閱讀 10,949評(píng)論 11 5
  • 最近治愈的事情 下了老友記十季的音頻 不離耳 定時(shí)關(guān)機(jī) 網(wǎng)速特別支持TED
    番茄fffff閱讀 221評(píng)論 0 0