1
0

amcnetworks.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .theplatform import ThePlatformIE
  4. from ..utils import (
  5. update_url_query,
  6. parse_age_limit,
  7. )
  8. class AMCNetworksIE(ThePlatformIE):
  9. _VALID_URL = r'https?://(?:www\.)?(?:amc|bbcamerica|ifc|wetv)\.com/(?:movies/|shows/[^/]+/(?:full-episodes/)?season-\d+/episode-\d+(?:-(?:[^/]+/)?|/))(?P<id>[^/?#]+)'
  10. _TESTS = [{
  11. 'url': 'http://www.ifc.com/shows/maron/season-04/episode-01/step-1',
  12. 'md5': '',
  13. 'info_dict': {
  14. 'id': 's3MX01Nl4vPH',
  15. 'ext': 'mp4',
  16. 'title': 'Step 1',
  17. 'description': 'In denial about his current situation, Marc is reluctantly convinced by his friends to enter rehab. Starring Marc Maron and Constance Zimmer.',
  18. 'age_limit': 17,
  19. 'upload_date': '20160505',
  20. 'timestamp': 1462468831,
  21. 'uploader': 'AMCN',
  22. },
  23. 'params': {
  24. # m3u8 download
  25. 'skip_download': True,
  26. },
  27. }, {
  28. 'url': 'http://www.bbcamerica.com/shows/the-hunt/full-episodes/season-1/episode-01-the-hardest-challenge',
  29. 'only_matching': True,
  30. }, {
  31. 'url': 'http://www.amc.com/shows/preacher/full-episodes/season-01/episode-00/pilot',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'http://www.wetv.com/shows/million-dollar-matchmaker/season-01/episode-06-the-dumped-dj-and-shallow-hal',
  35. 'only_matching': True,
  36. }, {
  37. 'url': 'http://www.ifc.com/movies/chaos',
  38. 'only_matching': True,
  39. }]
  40. def _real_extract(self, url):
  41. display_id = self._match_id(url)
  42. webpage = self._download_webpage(url, display_id)
  43. query = {
  44. 'mbr': 'true',
  45. 'manifest': 'm3u',
  46. }
  47. media_url = self._search_regex(r'window\.platformLinkURL\s*=\s*[\'"]([^\'"]+)', webpage, 'media url')
  48. theplatform_metadata = self._download_theplatform_metadata(self._search_regex(
  49. r'https?://link.theplatform.com/s/([^?]+)', media_url, 'theplatform_path'), display_id)
  50. info = self._parse_theplatform_metadata(theplatform_metadata)
  51. video_id = theplatform_metadata['pid']
  52. title = theplatform_metadata['title']
  53. rating = theplatform_metadata['ratings'][0]['rating']
  54. auth_required = self._search_regex(r'window\.authRequired\s*=\s*(true|false);', webpage, 'auth required')
  55. if auth_required == 'true':
  56. requestor_id = self._search_regex(r'window\.requestor_id\s*=\s*[\'"]([^\'"]+)', webpage, 'requestor id')
  57. resource = self._get_mvpd_resource(requestor_id, title, video_id, rating)
  58. query['auth'] = self._extract_mvpd_auth(url, video_id, requestor_id, resource)
  59. media_url = update_url_query(media_url, query)
  60. formats, subtitles = self._extract_theplatform_smil(media_url, video_id)
  61. self._sort_formats(formats)
  62. info.update({
  63. 'id': video_id,
  64. 'subtiles': subtitles,
  65. 'formats': formats,
  66. 'age_limit': parse_age_limit(parse_age_limit(rating)),
  67. })
  68. return info