radiojavan.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. parse_resolution,
  5. str_to_int,
  6. unified_strdate,
  7. urlencode_postdata,
  8. urljoin,
  9. )
  10. class RadioJavanIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?radiojavan\.com/videos/video/(?P<id>[^/]+)/?'
  12. _TEST = {
  13. 'url': 'http://www.radiojavan.com/videos/video/chaartaar-ashoobam',
  14. 'md5': 'e85208ffa3ca8b83534fca9fe19af95b',
  15. 'info_dict': {
  16. 'id': 'chaartaar-ashoobam',
  17. 'ext': 'mp4',
  18. 'title': 'Chaartaar - Ashoobam',
  19. 'thumbnail': r're:^https?://.*\.jpe?g$',
  20. 'upload_date': '20150215',
  21. 'view_count': int,
  22. 'like_count': int,
  23. 'dislike_count': int,
  24. }
  25. }
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. download_host = self._download_json(
  29. 'https://www.radiojavan.com/videos/video_host', video_id,
  30. data=urlencode_postdata({'id': video_id}),
  31. headers={
  32. 'Content-Type': 'application/x-www-form-urlencoded',
  33. 'Referer': url,
  34. }).get('host', 'https://host1.rjmusicmedia.com')
  35. webpage = self._download_webpage(url, video_id)
  36. formats = []
  37. for format_id, _, video_path in re.findall(
  38. r'RJ\.video(?P<format_id>\d+[pPkK])\s*=\s*(["\'])(?P<url>(?:(?!\2).)+)\2',
  39. webpage):
  40. f = parse_resolution(format_id)
  41. f.update({
  42. 'url': urljoin(download_host, video_path),
  43. 'format_id': format_id,
  44. })
  45. formats.append(f)
  46. title = self._og_search_title(webpage)
  47. thumbnail = self._og_search_thumbnail(webpage)
  48. upload_date = unified_strdate(self._search_regex(
  49. r'class="date_added">Date added: ([^<]+)<',
  50. webpage, 'upload date', fatal=False))
  51. view_count = str_to_int(self._search_regex(
  52. r'class="views">Plays: ([\d,]+)',
  53. webpage, 'view count', fatal=False))
  54. like_count = str_to_int(self._search_regex(
  55. r'class="rating">([\d,]+) likes',
  56. webpage, 'like count', fatal=False))
  57. dislike_count = str_to_int(self._search_regex(
  58. r'class="rating">([\d,]+) dislikes',
  59. webpage, 'dislike count', fatal=False))
  60. return {
  61. 'id': video_id,
  62. 'title': title,
  63. 'thumbnail': thumbnail,
  64. 'upload_date': upload_date,
  65. 'view_count': view_count,
  66. 'like_count': like_count,
  67. 'dislike_count': dislike_count,
  68. 'formats': formats,
  69. }