zetland.py 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from .common import InfoExtractor
  2. from ..utils import merge_dicts, unified_timestamp, url_or_none
  3. from ..utils.traversal import traverse_obj
  4. class ZetlandDKArticleIE(InfoExtractor):
  5. _VALID_URL = r'https?://www\.zetland\.dk/\w+/(?P<id>(?P<story_id>\w{8})-(?P<uploader_id>\w{8})-(?:\w{5}))'
  6. _TESTS = [{
  7. 'url': 'https://www.zetland.dk/historie/sO9aq2MY-a81VP3BY-66e69?utm_source=instagram&utm_medium=linkibio&utm_campaign=artikel',
  8. 'info_dict': {
  9. 'id': 'sO9aq2MY-a81VP3BY-66e69',
  10. 'ext': 'mp3',
  11. 'modified_date': '20240118',
  12. 'title': 'Afsnit 1: “Det føltes som en kidnapning.” ',
  13. 'upload_date': '20240116',
  14. 'uploader_id': 'a81VP3BY',
  15. 'modified_timestamp': 1705568739,
  16. 'release_timestamp': 1705377592,
  17. 'uploader_url': 'https://www.zetland.dk/skribent/a81VP3BY',
  18. 'uploader': 'Helle Fuusager',
  19. 'release_date': '20240116',
  20. 'thumbnail': r're:https://zetland\.imgix\.net/2aafe500-b14e-11ee-bf83-65d5e1283a57/Zetland_Image_1\.jpg',
  21. 'description': 'md5:9619d426772c133f5abb26db27f26a01',
  22. 'timestamp': 1705377592,
  23. 'series_id': '62d54630-e87b-4ab1-a255-8de58dbe1b14',
  24. },
  25. }]
  26. def _real_extract(self, url):
  27. display_id, uploader_id = self._match_valid_url(url).group('id', 'uploader_id')
  28. webpage = self._download_webpage(url, display_id)
  29. next_js_data = self._search_nextjs_data(webpage, display_id)['props']['pageProps']
  30. story_data = traverse_obj(next_js_data, ('initialState', 'consume', 'story', 'story'))
  31. formats = []
  32. for audio_url in traverse_obj(story_data, ('story_content', 'meta', 'audioFiles', ..., {url_or_none})):
  33. formats.append({
  34. 'url': audio_url,
  35. 'vcodec': 'none',
  36. })
  37. return merge_dicts({
  38. 'id': display_id,
  39. 'formats': formats,
  40. 'uploader_id': uploader_id,
  41. }, traverse_obj(story_data, {
  42. 'title': ((('story_content', 'content', 'title'), 'title'), {str}),
  43. 'uploader': ('sharer', 'name'),
  44. 'uploader_id': ('sharer', 'sharer_id'),
  45. 'description': ('story_content', 'content', 'socialDescription'),
  46. 'series_id': ('story_content', 'meta', 'seriesId'),
  47. 'release_timestamp': ('published_at', {unified_timestamp}),
  48. 'modified_timestamp': ('revised_at', {unified_timestamp}),
  49. }, get_all=False), traverse_obj(next_js_data, ('metaInfo', {
  50. 'title': ((('meta', 'title'), ('ld', 'headline'), ('og', 'og:title'), ('og', 'twitter:title')), {str}),
  51. 'description': ((('meta', 'description'), ('ld', 'description'), ('og', 'og:description'), ('og', 'twitter:description')), {str}),
  52. 'uploader': ((('meta', 'author'), ('ld', 'author', 'name')), {str}),
  53. 'uploader_url': ('ld', 'author', 'url', {url_or_none}),
  54. 'thumbnail': ((('ld', 'image'), ('og', 'og:image'), ('og', 'twitter:image')), {url_or_none}),
  55. 'modified_timestamp': ('ld', 'dateModified', {unified_timestamp}),
  56. 'release_timestamp': ('ld', 'datePublished', {unified_timestamp}),
  57. 'timestamp': ('ld', 'dateCreated', {unified_timestamp}),
  58. }), get_all=False), {
  59. 'title': self._html_search_meta(['title', 'og:title', 'twitter:title'], webpage),
  60. 'description': self._html_search_meta(['description', 'og:description', 'twitter:description'], webpage),
  61. 'thumbnail': self._html_search_meta(['og:image', 'twitter:image'], webpage),
  62. 'uploader': self._html_search_meta(['author'], webpage),
  63. 'release_timestamp': unified_timestamp(self._html_search_meta(['article:published_time'], webpage)),
  64. }, self._search_json_ld(webpage, display_id, fatal=False))