telebruxelles.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import re
  2. from .common import InfoExtractor
  3. class TeleBruxellesIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?(?:telebruxelles|bx1)\.be/(?:[^/]+/)*(?P<id>[^/#?]+)'
  5. _TESTS = [{
  6. 'url': 'http://bx1.be/news/que-risque-lauteur-dune-fausse-alerte-a-la-bombe/',
  7. 'md5': 'a2a67a5b1c3e8c9d33109b902f474fd9',
  8. 'info_dict': {
  9. 'id': '158856',
  10. 'display_id': 'que-risque-lauteur-dune-fausse-alerte-a-la-bombe',
  11. 'ext': 'mp4',
  12. 'title': 'Que risque l’auteur d’une fausse alerte à la bombe ?',
  13. 'description': 'md5:3cf8df235d44ebc5426373050840e466',
  14. },
  15. }, {
  16. 'url': 'http://bx1.be/sport/futsal-schaerbeek-sincline-5-3-a-thulin/',
  17. 'md5': 'dfe07ecc9c153ceba8582ac912687675',
  18. 'info_dict': {
  19. 'id': '158433',
  20. 'display_id': 'futsal-schaerbeek-sincline-5-3-a-thulin',
  21. 'ext': 'mp4',
  22. 'title': 'Futsal : Schaerbeek s’incline 5-3 à Thulin',
  23. 'description': 'md5:fd013f1488d5e2dceb9cebe39e2d569b',
  24. },
  25. }, {
  26. 'url': 'http://bx1.be/emission/bxenf1-gastronomie/',
  27. 'only_matching': True,
  28. }, {
  29. 'url': 'https://bx1.be/berchem-sainte-agathe/personnel-carrefour-de-berchem-sainte-agathe-inquiet/',
  30. 'only_matching': True,
  31. }, {
  32. 'url': 'https://bx1.be/dernier-jt/',
  33. 'only_matching': True,
  34. }, {
  35. # live stream
  36. 'url': 'https://bx1.be/lives/direct-tv/',
  37. 'only_matching': True,
  38. }]
  39. def _real_extract(self, url):
  40. display_id = self._match_id(url)
  41. webpage = self._download_webpage(url, display_id)
  42. article_id = self._html_search_regex(
  43. r'<article[^>]+\bid=["\']post-(\d+)', webpage, 'article ID', default=None)
  44. title = self._html_search_regex(
  45. r'<h1[^>]*>(.+?)</h1>', webpage, 'title',
  46. default=None) or self._og_search_title(webpage)
  47. description = self._og_search_description(webpage, default=None)
  48. rtmp_url = self._html_search_regex(
  49. r'file["\']?\s*:\s*"(r(?:tm|mt)ps?://[^/]+/(?:vod/mp4:"\s*\+\s*"[^"]+"\s*\+\s*"\.mp4|stream/live))"',
  50. webpage, 'RTMP url')
  51. # Yes, they have a typo in scheme name for live stream URLs (e.g.
  52. # https://bx1.be/lives/direct-tv/)
  53. rtmp_url = re.sub(r'^rmtp', 'rtmp', rtmp_url)
  54. rtmp_url = re.sub(r'"\s*\+\s*"', '', rtmp_url)
  55. formats = self._extract_wowza_formats(rtmp_url, article_id or display_id)
  56. is_live = 'stream/live' in rtmp_url
  57. return {
  58. 'id': article_id or display_id,
  59. 'display_id': display_id,
  60. 'title': title,
  61. 'description': description,
  62. 'formats': formats,
  63. 'is_live': is_live,
  64. }