planetmarathi.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. try_get,
  4. unified_strdate,
  5. )
  6. class PlanetMarathiIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?planetmarathi\.com/titles/(?P<id>[^/#&?$]+)'
  8. _TESTS = [{
  9. 'url': 'https://www.planetmarathi.com/titles/ek-unad-divas',
  10. 'playlist_mincount': 2,
  11. 'info_dict': {
  12. 'id': 'ek-unad-divas',
  13. },
  14. 'playlist': [{
  15. 'info_dict': {
  16. 'id': 'ASSETS-MOVIE-ASSET-01_ek-unad-divas',
  17. 'ext': 'mp4',
  18. 'title': 'ek unad divas',
  19. 'alt_title': 'चित्रपट',
  20. 'description': 'md5:41c7ed6b041c2fea9820a3f3125bd881',
  21. 'season_number': None,
  22. 'episode_number': 1,
  23. 'duration': 5539,
  24. 'upload_date': '20210829',
  25. },
  26. }] # Trailer skipped
  27. }, {
  28. 'url': 'https://www.planetmarathi.com/titles/baap-beep-baap-season-1',
  29. 'playlist_mincount': 10,
  30. 'info_dict': {
  31. 'id': 'baap-beep-baap-season-1',
  32. },
  33. 'playlist': [{
  34. 'info_dict': {
  35. 'id': 'ASSETS-CHARACTER-PROFILE-SEASON-01-ASSET-01_baap-beep-baap-season-1',
  36. 'ext': 'mp4',
  37. 'title': 'Manohar Kanhere',
  38. 'alt_title': 'मनोहर कान्हेरे',
  39. 'description': 'md5:285ed45d5c0ab5522cac9a043354ebc6',
  40. 'season_number': 1,
  41. 'episode_number': 1,
  42. 'duration': 29,
  43. 'upload_date': '20210829',
  44. },
  45. }] # Trailers, Episodes, other Character profiles skipped
  46. }]
  47. def _real_extract(self, url):
  48. id = self._match_id(url)
  49. entries = []
  50. json_data = self._download_json(f'https://www.planetmarathi.com/api/v1/titles/{id}/assets', id)['assets']
  51. for asset in json_data:
  52. asset_title = asset['mediaAssetName']['en']
  53. if asset_title == 'Movie':
  54. asset_title = id.replace('-', ' ')
  55. asset_id = f'{asset["sk"]}_{id}'.replace('#', '-')
  56. formats, subtitles = self._extract_m3u8_formats_and_subtitles(asset['mediaAssetURL'], asset_id)
  57. entries.append({
  58. 'id': asset_id,
  59. 'title': asset_title,
  60. 'alt_title': try_get(asset, lambda x: x['mediaAssetName']['mr']),
  61. 'description': try_get(asset, lambda x: x['mediaAssetDescription']['en']),
  62. 'season_number': asset.get('mediaAssetSeason'),
  63. 'episode_number': asset.get('mediaAssetIndexForAssetType'),
  64. 'duration': asset.get('mediaAssetDurationInSeconds'),
  65. 'upload_date': unified_strdate(asset.get('created')),
  66. 'formats': formats,
  67. 'subtitles': subtitles,
  68. })
  69. return self.playlist_result(entries, playlist_id=id)