nfhsnetwork.py 5.7 KB

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