altcensored.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import re
  2. from .archiveorg import ArchiveOrgIE
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. InAdvancePagedList,
  6. clean_html,
  7. int_or_none,
  8. orderedSet,
  9. str_to_int,
  10. urljoin,
  11. )
  12. class AltCensoredIE(InfoExtractor):
  13. IE_NAME = 'altcensored'
  14. _VALID_URL = r'https?://(?:www\.)?altcensored\.com/(?:watch\?v=|embed/)(?P<id>[^/?#]+)'
  15. _TESTS = [{
  16. 'url': 'https://www.altcensored.com/watch?v=k0srjLSkga8',
  17. 'info_dict': {
  18. 'id': 'youtube-k0srjLSkga8',
  19. 'ext': 'webm',
  20. 'title': "QUELLES SONT LES CONSÉQUENCES DE L'HYPERSEXUALISATION DE LA SOCIÉTÉ ?",
  21. 'display_id': 'k0srjLSkga8.webm',
  22. 'release_date': '20180403',
  23. 'creators': ['Virginie Vota'],
  24. 'release_year': 2018,
  25. 'upload_date': '20230318',
  26. 'uploader': 'admin@altcensored.com',
  27. 'description': 'md5:0b38a8fc04103579d5c1db10a247dc30',
  28. 'timestamp': 1679161343,
  29. 'track': 'k0srjLSkga8',
  30. 'duration': 926.09,
  31. 'thumbnail': 'https://archive.org/download/youtube-k0srjLSkga8/youtube-k0srjLSkga8.thumbs/k0srjLSkga8_000925.jpg',
  32. 'view_count': int,
  33. 'categories': ['News & Politics'],
  34. },
  35. }]
  36. def _real_extract(self, url):
  37. video_id = self._match_id(url)
  38. webpage = self._download_webpage(url, video_id)
  39. category = clean_html(self._html_search_regex(
  40. r'<a href="/category/\d+">([^<]+)</a>', webpage, 'category', default=None))
  41. return {
  42. '_type': 'url_transparent',
  43. 'url': f'https://archive.org/details/youtube-{video_id}',
  44. 'ie_key': ArchiveOrgIE.ie_key(),
  45. 'view_count': str_to_int(self._html_search_regex(
  46. r'YouTube Views:(?:\s|&nbsp;)*([\d,]+)', webpage, 'view count', default=None)),
  47. 'categories': [category] if category else None,
  48. }
  49. class AltCensoredChannelIE(InfoExtractor):
  50. IE_NAME = 'altcensored:channel'
  51. _VALID_URL = r'https?://(?:www\.)?altcensored\.com/channel/(?!page|table)(?P<id>[^/?#]+)'
  52. _PAGE_SIZE = 24
  53. _TESTS = [{
  54. 'url': 'https://www.altcensored.com/channel/UCFPTO55xxHqFqkzRZHu4kcw',
  55. 'info_dict': {
  56. 'title': 'Virginie Vota',
  57. 'id': 'UCFPTO55xxHqFqkzRZHu4kcw',
  58. },
  59. 'playlist_count': 85,
  60. }, {
  61. 'url': 'https://altcensored.com/channel/UC9CcJ96HKMWn0LZlcxlpFTw',
  62. 'info_dict': {
  63. 'title': 'yukikaze775',
  64. 'id': 'UC9CcJ96HKMWn0LZlcxlpFTw',
  65. },
  66. 'playlist_count': 4,
  67. }, {
  68. 'url': 'https://altcensored.com/channel/UCfYbb7nga6-icsFWWgS-kWw',
  69. 'info_dict': {
  70. 'title': 'Mister Metokur',
  71. 'id': 'UCfYbb7nga6-icsFWWgS-kWw',
  72. },
  73. 'playlist_count': 121,
  74. }]
  75. def _real_extract(self, url):
  76. channel_id = self._match_id(url)
  77. webpage = self._download_webpage(
  78. url, channel_id, 'Download channel webpage', 'Unable to get channel webpage')
  79. title = self._html_search_meta('altcen_title', webpage, 'title', fatal=False)
  80. page_count = int_or_none(self._html_search_regex(
  81. r'<a[^>]+href="/channel/[\w-]+/page/(\d+)">(?:\1)</a>',
  82. webpage, 'page count', default='1'))
  83. def page_func(page_num):
  84. page_num += 1
  85. webpage = self._download_webpage(
  86. f'https://altcensored.com/channel/{channel_id}/page/{page_num}',
  87. channel_id, note=f'Downloading page {page_num}')
  88. items = re.findall(r'<a[^>]+href="(/watch\?v=[^"]+)', webpage)
  89. return [self.url_result(urljoin('https://www.altcensored.com', path), AltCensoredIE)
  90. for path in orderedSet(items)]
  91. return self.playlist_result(
  92. InAdvancePagedList(page_func, page_count, self._PAGE_SIZE),
  93. playlist_id=channel_id, playlist_title=title)