godresource.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. determine_ext,
  5. str_or_none,
  6. unified_timestamp,
  7. url_or_none,
  8. )
  9. from ..utils.traversal import traverse_obj
  10. class GodResourceIE(InfoExtractor):
  11. _VALID_URL = r'https?://new\.godresource\.com/video/(?P<id>\w+)'
  12. _TESTS = [{
  13. # hls stream
  14. 'url': 'https://new.godresource.com/video/A01mTKjyf6w',
  15. 'info_dict': {
  16. 'id': 'A01mTKjyf6w',
  17. 'ext': 'mp4',
  18. 'view_count': int,
  19. 'timestamp': 1710978666,
  20. 'channel_id': '5',
  21. 'thumbnail': 'https://cdn-02.godresource.com/e42968ac-9e8b-4231-ab86-f4f9d775841f/thumbnail.jpg',
  22. 'channel': 'Stedfast Baptist Church',
  23. 'upload_date': '20240320',
  24. 'title': 'GodResource video #A01mTKjyf6w',
  25. },
  26. }, {
  27. # mp4 link
  28. 'url': 'https://new.godresource.com/video/01DXmBbQv_X',
  29. 'md5': '0e8f72aa89a106b9d5c011ba6f8717b7',
  30. 'info_dict': {
  31. 'id': '01DXmBbQv_X',
  32. 'ext': 'mp4',
  33. 'channel_id': '12',
  34. 'view_count': int,
  35. 'timestamp': 1687996800,
  36. 'thumbnail': 'https://cdn-02.godresource.com/sodomitedeception/thumbnail.jpg',
  37. 'channel': 'Documentaries',
  38. 'title': 'The Sodomite Deception',
  39. 'upload_date': '20230629',
  40. },
  41. }]
  42. def _real_extract(self, url):
  43. display_id = self._match_id(url)
  44. api_data = self._download_json(
  45. f'https://api.godresource.com/api/Streams/{display_id}', display_id)
  46. video_url = api_data['streamUrl']
  47. is_live = api_data.get('isLive') or False
  48. if (ext := determine_ext(video_url)) == 'm3u8':
  49. formats, subtitles = self._extract_m3u8_formats_and_subtitles(
  50. video_url, display_id, live=is_live)
  51. elif ext == 'mp4':
  52. formats, subtitles = [{
  53. 'url': video_url,
  54. 'ext': ext,
  55. }], {}
  56. else:
  57. raise ExtractorError(f'Unexpected video format {ext}')
  58. return {
  59. 'id': display_id,
  60. 'formats': formats,
  61. 'subtitles': subtitles,
  62. 'title': '',
  63. 'is_live': is_live,
  64. **traverse_obj(api_data, {
  65. 'title': ('title', {str}),
  66. 'thumbnail': ('thumbnail', {url_or_none}),
  67. 'view_count': ('views', {int}),
  68. 'channel': ('channelName', {str}),
  69. 'channel_id': ('channelId', {str_or_none}),
  70. 'timestamp': ('streamDateCreated', {unified_timestamp}),
  71. 'modified_timestamp': ('streamDataModified', {unified_timestamp}),
  72. }),
  73. }