|
| 1 | + |
| 2 | +from .common import InfoExtractor |
| 3 | +from ..utils import ( |
| 4 | + float_or_none, |
| 5 | + int_or_none, |
| 6 | + js_to_json, |
| 7 | + url_or_none, |
| 8 | +) |
| 9 | +from ..utils.traversal import traverse_obj |
| 10 | +from datetime import datetime |
| 11 | + |
| 12 | + |
| 13 | +class XiaoYuZhouIE(InfoExtractor): |
| 14 | + _VALID_URL = r'https?://www\.xiaoyuzhoufm\.com/episode/(?P<id>[\da-f]+)' |
| 15 | + IE_DESC = '小宇宙' |
| 16 | + _TESTS = [{ |
| 17 | + 'url': 'https://www.xiaoyuzhoufm.com/episode/670f2a7e0d2f24f289727fdc', |
| 18 | + 'info_dict': { |
| 19 | + 'id': '670f2a7e0d2f24f289727fdc', |
| 20 | + 'ext': 'm4a', |
| 21 | + 'description': str, |
| 22 | + 'title': '是不飘了?研究上私募了?没100万也不耽误听', |
| 23 | + 'duration': 6741, |
| 24 | + 'uploader': '面基', |
| 25 | + 'uploader_id': '6388760f22567e8ea6ad070f', |
| 26 | + 'uploader_url': 'https://www.xiaoyuzhoufm.com/podcast/6388760f22567e8ea6ad070f', |
| 27 | + }, |
| 28 | + }] |
| 29 | + |
| 30 | + def _real_extract(self, url): |
| 31 | + display_id = self._match_id(url) |
| 32 | + webpage = self._download_webpage(url, display_id) |
| 33 | + initial_state = self._search_json( |
| 34 | + r'<script id="__NEXT_DATA__" type="application/json">', webpage, 'json_data', display_id) |
| 35 | + |
| 36 | + episode_info = traverse_obj(initial_state, ('props', 'pageProps', 'episode')) |
| 37 | + |
| 38 | + episode_title = traverse_obj(episode_info, ('title', {str})) |
| 39 | + audio_url = traverse_obj(episode_info, ('enclosure', 'url', {url_or_none})) |
| 40 | + description = traverse_obj(episode_info, ('description', {str})) |
| 41 | + duration = traverse_obj(episode_info, ('duration', {float_or_none})) |
| 42 | + pubDateStr = traverse_obj(episode_info, ('pubDate', {str})) |
| 43 | + |
| 44 | + upload_datetime = datetime.strptime(pubDateStr, "%Y-%m-%dT%H:%M:%S.%fZ") # `2024-10-16T09:30:00.000Z`格式 |
| 45 | + |
| 46 | + # podcast 是指一个播客节目,包含多个 episode,podcast由多个实际user主持 |
| 47 | + podcast_id = traverse_obj(episode_info, ('pid', {str})) |
| 48 | + podcast_title = traverse_obj(episode_info, ('podcast', 'title', {str})) |
| 49 | + podcast_description = traverse_obj(episode_info, ('podcast', 'description', {str})) |
| 50 | + podcast_url = f'https://www.xiaoyuzhoufm.com/podcast/{podcast_id}' |
| 51 | + |
| 52 | + podcast_user_list = traverse_obj(episode_info, ('podcast', 'podcasters', ...)) |
| 53 | + |
| 54 | + ext = None |
| 55 | + if '.' in audio_url.split('/')[-1]: |
| 56 | + ext = audio_url.split('.')[-1] |
| 57 | + |
| 58 | + formats = [] |
| 59 | + formats.append({ |
| 60 | + 'url': audio_url, |
| 61 | + 'vcodec': 'none', |
| 62 | + 'ext': ext, |
| 63 | + }) |
| 64 | + |
| 65 | + return { |
| 66 | + 'id': display_id, |
| 67 | + 'formats': formats, |
| 68 | + 'title': episode_title, |
| 69 | + 'description': description, |
| 70 | + 'duration': duration, |
| 71 | + 'timestamp': upload_datetime.timestamp(), |
| 72 | + 'uploader': podcast_title, |
| 73 | + 'uploader_id': podcast_id, |
| 74 | + 'uploader_url': podcast_url, |
| 75 | + } |
0 commit comments