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