Skip to content

Commit

Permalink
[ie/bilibili] Extract format_id (#7555)
Browse files Browse the repository at this point in the history
Authored by: c-basalt
  • Loading branch information
c-basalt committed Sep 16, 2023
1 parent 9bf14be commit 5336bf5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion yt_dlp/extractor/bilibili.py
Expand Up @@ -3,6 +3,7 @@
import hashlib
import itertools
import math
import re
import time
import urllib.parse

Expand Down Expand Up @@ -38,6 +39,8 @@


class BilibiliBaseIE(InfoExtractor):
_FORMAT_ID_RE = re.compile(r'-(\d+)\.m4s\?')

def extract_formats(self, play_info):
format_names = {
r['quality']: traverse_obj(r, 'new_description', 'display_desc')
Expand All @@ -54,7 +57,8 @@ def extract_formats(self, play_info):
'acodec': audio.get('codecs'),
'vcodec': 'none',
'tbr': float_or_none(audio.get('bandwidth'), scale=1000),
'filesize': int_or_none(audio.get('size'))
'filesize': int_or_none(audio.get('size')),
'format_id': str_or_none(audio.get('id')),
} for audio in audios]

formats.extend({
Expand All @@ -68,6 +72,9 @@ def extract_formats(self, play_info):
'tbr': float_or_none(video.get('bandwidth'), scale=1000),
'filesize': int_or_none(video.get('size')),
'quality': int_or_none(video.get('id')),
'format_id': traverse_obj(
video, (('baseUrl', 'base_url'), {self._FORMAT_ID_RE.search}, 1),
('id', {str_or_none}), get_all=False),
'format': format_names.get(video.get('id')),
} for video in traverse_obj(play_info, ('dash', 'video', ...)))

Expand Down

0 comments on commit 5336bf5

Please sign in to comment.