Browse Source

[bilibili] Catch API call failures

JSON are returned in a failed API call
totalwebcasting
Yen Chi Hsuan 10 years ago
parent
commit
6d00a2dcd1
1 changed files with 11 additions and 1 deletions
  1. +11
    -1
      youtube_dl/extractor/bilibili.py

+ 11
- 1
youtube_dl/extractor/bilibili.py View File

@ -3,6 +3,8 @@ from __future__ import unicode_literals
import re import re
import itertools import itertools
import json
import xml.etree.ElementTree as ET
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
@ -67,11 +69,19 @@ class BiliBiliIE(InfoExtractor):
entries = [] entries = []
lq_doc = self._download_xml(
lq_page = self._download_webpage(
'http://interface.bilibili.com/v_cdn_play?appkey=1&cid=%s' % cid, 'http://interface.bilibili.com/v_cdn_play?appkey=1&cid=%s' % cid,
video_id, video_id,
note='Downloading LQ video info' note='Downloading LQ video info'
) )
try:
err_info = json.loads(lq_page)
raise ExtractorError(
'BiliBili said: ' + err_info['error_text'], expected=True)
except ValueError:
pass
lq_doc = ET.fromstring(lq_page)
lq_durls = lq_doc.findall('./durl') lq_durls = lq_doc.findall('./durl')
hq_doc = self._download_xml( hq_doc = self._download_xml(


Loading…
Cancel
Save