deuxm.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from .common import InfoExtractor
  2. from ..utils import url_or_none
  3. class DeuxMIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?2m\.ma/[^/]+/replay/single/(?P<id>([\w.]{1,24})+)'
  5. _TESTS = [{
  6. 'url': 'https://2m.ma/fr/replay/single/6351d439b15e1a613b3debe8',
  7. 'md5': '5f761f04c9d686e553b685134dca5d32',
  8. 'info_dict': {
  9. 'id': '6351d439b15e1a613b3debe8',
  10. 'ext': 'mp4',
  11. 'title': 'Grand Angle : Jeudi 20 Octobre 2022',
  12. 'thumbnail': r're:^https?://2msoread-ww.amagi.tv/mediasfiles/videos/images/.*\.png$',
  13. },
  14. }, {
  15. 'url': 'https://2m.ma/fr/replay/single/635c0aeab4eec832622356da',
  16. 'md5': 'ad6af2f5e4d5b2ad2194a84b6e890b4c',
  17. 'info_dict': {
  18. 'id': '635c0aeab4eec832622356da',
  19. 'ext': 'mp4',
  20. 'title': 'Journal Amazigh : Vendredi 28 Octobre 2022',
  21. 'thumbnail': r're:^https?://2msoread-ww.amagi.tv/mediasfiles/videos/images/.*\.png$',
  22. },
  23. }]
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. video = self._download_json(
  27. f'https://2m.ma/api/watchDetail/{video_id}', video_id)['response']['News']
  28. return {
  29. 'id': video_id,
  30. 'title': video.get('titre'),
  31. 'url': video['url'],
  32. 'description': video.get('description'),
  33. 'thumbnail': url_or_none(video.get('image')),
  34. }
  35. class DeuxMNewsIE(InfoExtractor):
  36. _VALID_URL = r'https?://(?:www\.)?2m\.ma/(?P<lang>\w+)/news/(?P<id>[^/#?]+)'
  37. _TESTS = [{
  38. 'url': 'https://2m.ma/fr/news/Kan-Ya-Mkan-d%C3%A9poussi%C3%A8re-l-histoire-du-phare-du-Cap-Beddouza-20221028',
  39. 'md5': '43d5e693a53fa0b71e8a5204c7d4542a',
  40. 'info_dict': {
  41. 'id': '635c5d1233b83834e35b282e',
  42. 'ext': 'mp4',
  43. 'title': 'Kan Ya Mkan d\u00e9poussi\u00e8re l\u2019histoire du phare du Cap Beddouza',
  44. 'description': 'md5:99dcf29b82f1d7f2a4acafed1d487527',
  45. 'thumbnail': r're:^https?://2msoread-ww.amagi.tv/mediasfiles/videos/images/.*\.png$',
  46. },
  47. }, {
  48. 'url': 'https://2m.ma/fr/news/Interview-Casablanca-hors-des-sentiers-battus-avec-Abderrahim-KASSOU-Replay--20221017',
  49. 'md5': '7aca29f02230945ef635eb8290283c0c',
  50. 'info_dict': {
  51. 'id': '634d9e108b70d40bc51a844b',
  52. 'ext': 'mp4',
  53. 'title': 'Interview: Casablanca hors des sentiers battus avec Abderrahim KASSOU (Replay) ',
  54. 'description': 'md5:3b8e78111de9fcc6ef7f7dd6cff2430c',
  55. 'thumbnail': r're:^https?://2msoread-ww.amagi.tv/mediasfiles/videos/images/.*\.png$',
  56. },
  57. }]
  58. def _real_extract(self, url):
  59. article_name, lang = self._match_valid_url(url).group('id', 'lang')
  60. video = self._download_json(
  61. f'https://2m.ma/api/articlesByUrl?lang={lang}&url=/news/{article_name}', article_name)['response']['article'][0]
  62. return {
  63. 'id': video['id'],
  64. 'title': video.get('title'),
  65. 'url': video['image'][0],
  66. 'description': video.get('content'),
  67. 'thumbnail': url_or_none(video.get('cover')),
  68. }