nfhsnetwork.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. from .common import InfoExtractor
  2. from ..utils import try_get, unified_strdate, unified_timestamp
  3. class NFHSNetworkIE(InfoExtractor):
  4. IE_NAME = 'NFHSNetwork'
  5. _VALID_URL = r'https?://(?:www\.)?nfhsnetwork\.com/events/[\w-]+/(?P<id>(?:gam|evt|dd|)?[\w\d]{0,10})'
  6. _TESTS = [{
  7. # Auto-generated two-team sport (pixellot)
  8. 'url': 'https://www.nfhsnetwork.com/events/rockford-high-school-rockford-mi/gamcf7e54cfbc',
  9. 'info_dict': {
  10. 'id': 'gamcf7e54cfbc',
  11. 'ext': 'mp4',
  12. 'title': 'Rockford vs Spring Lake - Girls Varsity Lacrosse 03/27/2021',
  13. 'uploader': 'MHSAA - Michigan: Rockford High School, Rockford, MI',
  14. 'uploader_id': 'cd2622cf76',
  15. 'uploader_url': 'https://www.nfhsnetwork.com/schools/rockford-high-school-rockford-mi',
  16. 'location': 'Rockford, Michigan',
  17. 'timestamp': 1616859000,
  18. 'upload_date': '20210327',
  19. },
  20. 'params': {
  21. # m3u8 download
  22. 'skip_download': True,
  23. },
  24. }, {
  25. # Non-sport activity with description
  26. 'url': 'https://www.nfhsnetwork.com/events/limon-high-school-limon-co/evt4a30e3726c',
  27. 'info_dict': {
  28. 'id': 'evt4a30e3726c',
  29. 'ext': 'mp4',
  30. 'title': 'Drama Performance Limon High School vs. Limon High School - 12/13/2020',
  31. 'description': 'Join the broadcast of the Limon High School Musical Performance at 2 PM.',
  32. 'uploader': 'CHSAA: Limon High School, Limon, CO',
  33. 'uploader_id': '7d2d121332',
  34. 'uploader_url': 'https://www.nfhsnetwork.com/schools/limon-high-school-limon-co',
  35. 'location': 'Limon, Colorado',
  36. 'timestamp': 1607893200,
  37. 'upload_date': '20201213',
  38. },
  39. 'params': {
  40. # m3u8 download
  41. 'skip_download': True,
  42. },
  43. }, {
  44. # Postseason game
  45. 'url': 'https://www.nfhsnetwork.com/events/nfhs-network-special-events/dd8de71d45',
  46. 'info_dict': {
  47. 'id': 'dd8de71d45',
  48. 'ext': 'mp4',
  49. 'title': '2015 UA Holiday Classic Tournament: National Division - 12/26/2015',
  50. 'uploader': 'SoCal Sports Productions',
  51. 'uploader_id': '063dba0150',
  52. 'uploader_url': 'https://www.nfhsnetwork.com/affiliates/socal-sports-productions',
  53. 'location': 'San Diego, California',
  54. 'timestamp': 1451187000,
  55. 'upload_date': '20151226',
  56. },
  57. 'params': {
  58. # m3u8 download
  59. 'skip_download': True,
  60. },
  61. }, {
  62. # Video with no broadcasts object
  63. 'url': 'https://www.nfhsnetwork.com/events/wiaa-wi/9aa2f92f82',
  64. 'info_dict': {
  65. 'id': '9aa2f92f82',
  66. 'ext': 'mp4',
  67. 'title': 'Competitive Equity - 01/21/2015',
  68. 'description': 'Committee members discuss points of their research regarding a competitive equity plan',
  69. 'uploader': 'WIAA - Wisconsin: Wisconsin Interscholastic Athletic Association',
  70. 'uploader_id': 'a49f7d1002',
  71. 'uploader_url': 'https://www.nfhsnetwork.com/associations/wiaa-wi',
  72. 'location': 'Stevens Point, Wisconsin',
  73. 'timestamp': 1421856000,
  74. 'upload_date': '20150121',
  75. },
  76. 'params': {
  77. # m3u8 download
  78. 'skip_download': True,
  79. },
  80. },
  81. ]
  82. def _real_extract(self, url):
  83. video_id = self._match_id(url)
  84. webpage = self._download_webpage(url, video_id)
  85. data = self._download_json(
  86. 'https://cfunity.nfhsnetwork.com/v2/game_or_event/' + video_id,
  87. video_id)
  88. publisher = data.get('publishers')[0] # always exists
  89. broadcast = (publisher.get('broadcasts') or publisher.get('vods'))[0] # some (older) videos don't have a broadcasts object
  90. uploader = publisher.get('formatted_name') or publisher.get('name')
  91. uploader_id = publisher.get('publisher_key')
  92. pub_type = publisher.get('type')
  93. uploader_prefix = (
  94. 'schools' if pub_type == 'school'
  95. else 'associations' if 'association' in pub_type
  96. else 'affiliates' if (pub_type == 'publisher' or pub_type == 'affiliate')
  97. else 'schools')
  98. uploader_page = 'https://www.nfhsnetwork.com/{}/{}'.format(uploader_prefix, publisher.get('slug'))
  99. location = '{}, {}'.format(data.get('city'), data.get('state_name'))
  100. description = broadcast.get('description')
  101. is_live = broadcast.get('on_air') or broadcast.get('status') == 'on_air' or False
  102. timestamp = unified_timestamp(data.get('local_start_time'))
  103. upload_date = unified_strdate(data.get('local_start_time'))
  104. title = (
  105. self._og_search_title(webpage)
  106. or self._html_search_regex(r'<h1 class="sr-hidden">(.*?)</h1>', webpage, 'title'))
  107. title = title.split('|')[0].strip()
  108. video_type = 'broadcasts' if is_live else 'vods'
  109. key = broadcast.get('key') if is_live else try_get(publisher, lambda x: x['vods'][0]['key'])
  110. m3u8_url = self._download_json(
  111. f'https://cfunity.nfhsnetwork.com/v2/{video_type}/{key}/url',
  112. video_id).get('video_url')
  113. formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', live=is_live)
  114. return {
  115. 'id': video_id,
  116. 'title': title,
  117. 'formats': formats,
  118. 'description': description,
  119. 'timestamp': timestamp,
  120. 'uploader': uploader,
  121. 'uploader_id': uploader_id,
  122. 'uploader_url': uploader_page,
  123. 'location': location,
  124. 'upload_date': upload_date,
  125. 'is_live': is_live,
  126. '_format_sort_fields': ('res', 'tbr'),
  127. }