Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BitChute] - Fix 'uploader' and playlist tests md5 result #8507

Merged
merged 4 commits into from
Dec 11, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 19 additions & 4 deletions yt_dlp/extractor/bitchute.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
ExtractorError,
OnDemandPagedList,
clean_html,
extract_attributes,
get_element_by_class,
get_element_by_id,
get_element_html_by_class,
get_elements_html_by_class,
int_or_none,
orderedSet,
Expand All @@ -21,7 +23,7 @@


class BitChuteIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?bitchute\.com/(?:video|embed|torrent/[^/]+)/(?P<id>[^/?#&]+)'
_VALID_URL = r'(?P<base_url>https?://(?:www\.)?bitchute\.com)/(?:video|embed|torrent/[^/]+)/(?P<id>[^/?#&]+)'
_EMBED_REGEX = [rf'<(?:script|iframe)[^>]+\bsrc=(["\'])(?P<url>{_VALID_URL})']
_TESTS = [{
'url': 'https://www.bitchute.com/video/UGlrF9o9b-Q/',
Expand All @@ -34,6 +36,8 @@ class BitChuteIE(InfoExtractor):
'thumbnail': r're:^https?://.*\.jpg$',
'uploader': 'BitChute',
'upload_date': '20170103',
'uploader_url': 'https://www.bitchute.com/profile/I5NgtHZn9vPj/',
'channel_url': 'https://www.bitchute.com/channel/bitchute/'
},
}, {
# video not downloadable in browser, but we can recover it
Expand All @@ -48,6 +52,8 @@ class BitChuteIE(InfoExtractor):
'thumbnail': r're:^https?://.*\.jpg$',
'uploader': 'BitChute',
'upload_date': '20181113',
'uploader_url': 'https://www.bitchute.com/profile/I5NgtHZn9vPj/',
'channel_url': 'https://www.bitchute.com/channel/bitchute/'
},
'params': {'check_formats': None},
}, {
Expand Down Expand Up @@ -100,13 +106,18 @@ def _raise_if_restricted(self, webpage):
self.raise_geo_restricted(reason)

def _real_extract(self, url):
video_id = self._match_id(url)
base_url, video_id = self._match_valid_url(url).group('base_url', 'id')
webpage = self._download_webpage(
f'https://www.bitchute.com/video/{video_id}', video_id, headers=self._HEADERS)

self._raise_if_restricted(webpage)
publish_date = clean_html(get_element_by_class('video-publish-date', webpage))
entries = self._parse_html5_media_entries(url, webpage, video_id)
details = get_element_by_class('details', webpage) or ''
uploader_path = extract_attributes(
get_element_html_by_class('spa', get_element_html_by_class('creator', details)) or '').get('href')
channel_path = extract_attributes(
get_element_html_by_class('spa', get_element_html_by_class('name', details)) or '').get('href')
Copy link
Member

@bashonly bashonly Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. all of this "details" extraction should be moved down near the return for better code flow/readability
  2. uploader_path and channel_path are currently fatal because get_element_html_by_class can return None and throws when its html input is None
  3. matching base_url in _VALID_URL is overkill, we can always just use https://www.bitchute.com
  4. use utils.urljoin
  5. move duplicated code into a function
        details = get_element_by_class('details', webpage) or ''
        uploader_html = get_element_html_by_class('creator', details) or ''
        channel_html = get_element_html_by_class('name', details) or ''

        def construct_url(html):
            path = extract_attributes(get_element_html_by_class('spa', html) or '').get('href')
            return urljoin('https://www.bitchute.com', path)

        return {
            # ...
            'uploader': clean_html(uploader_html),
            'channel': clean_html(channel_html),
            'uploader_url': construct_url(uploader_html),
            'channel_url': construct_url(channel_html),
            # ...
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestions @bashonly . I applied those and reverted the base_url change.


formats = []
for format_ in traverse_obj(entries, (0, 'formats', ...)):
Expand All @@ -126,9 +137,11 @@ def _real_extract(self, url):
'title': self._html_extract_title(webpage) or self._og_search_title(webpage),
'description': self._og_search_description(webpage, default=None),
'thumbnail': self._og_search_thumbnail(webpage),
'uploader': clean_html(get_element_by_class('owner', webpage)),
'uploader': clean_html(get_element_by_class('name', details)),
'upload_date': unified_strdate(self._search_regex(
r'at \d+:\d+ UTC on (.+?)\.', publish_date, 'upload date', fatal=False)),
'uploader_url': f'{base_url}{uploader_path}' if uploader_path else None,
'channel_url': f'{base_url}{channel_path}' if channel_path else None,
'formats': formats,
}

Expand All @@ -154,6 +167,8 @@ class BitChuteChannelIE(InfoExtractor):
'thumbnail': r're:^https?://.*\.jpg$',
'uploader': 'BitChute',
'upload_date': '20170103',
'uploader_url': 'https://www.bitchute.com/profile/I5NgtHZn9vPj/',
'channel_url': 'https://www.bitchute.com/channel/bitchute/',
'duration': 16,
'view_count': int,
},
Expand All @@ -169,7 +184,7 @@ class BitChuteChannelIE(InfoExtractor):
'info_dict': {
'id': 'wV9Imujxasw9',
'title': 'Bruce MacDonald and "The Light of Darkness"',
'description': 'md5:04913227d2714af1d36d804aa2ab6b1e',
'description': 'md5:747724ef404eebdfc04277714f81863e',
}
}]

Expand Down