- encoding = encodings.find(code)
- if encoding is None:
- continue
- encoding_url = encoding.find('FILENAME').text
- formats.append({
- 'url': encoding_url,
- 'format_id': code.lower(),
- 'quality': pref,
- })
+ encoding = xpath_element(encodings, code)
+ if encoding is not None:
+ encoding_url = xpath_text(encoding, 'FILENAME')
+ if encoding_url:
+ tbr = xpath_text(encoding, 'AVERAGEBITRATE', 1000)
+ if tbr:
+ tbr = int_or_none(tbr.replace(',', '.'))
+ f = {
+ 'url': encoding_url,
+ 'format_id': code.lower(),
+ 'quality': pref,
+ 'tbr': tbr,
+ 'vcodec': xpath_text(encoding, 'CODEC'),
+ }
+ mobj = re.search(r'(\d+)x(\d+)_(\d+)\.mp4', encoding_url)
+ if mobj:
+ f.update({
+ 'width': int(mobj.group(1)),
+ 'height': int(mobj.group(2)),
+ 'tbr': tbr or int(mobj.group(3)),
+ })
+ formats.append(f)