You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.7 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. parse_resolution,
  6. str_to_int,
  7. unified_strdate,
  8. urlencode_postdata,
  9. urljoin,
  10. )
  11. class RadioJavanIE(InfoExtractor):
  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. self._sort_formats(formats)
  48. title = self._og_search_title(webpage)
  49. thumbnail = self._og_search_thumbnail(webpage)
  50. upload_date = unified_strdate(self._search_regex(
  51. r'class="date_added">Date added: ([^<]+)<',
  52. webpage, 'upload date', fatal=False))
  53. view_count = str_to_int(self._search_regex(
  54. r'class="views">Plays: ([\d,]+)',
  55. webpage, 'view count', fatal=False))
  56. like_count = str_to_int(self._search_regex(
  57. r'class="rating">([\d,]+) likes',
  58. webpage, 'like count', fatal=False))
  59. dislike_count = str_to_int(self._search_regex(
  60. r'class="rating">([\d,]+) dislikes',
  61. webpage, 'dislike count', fatal=False))
  62. return {
  63. 'id': video_id,
  64. 'title': title,
  65. 'thumbnail': thumbnail,
  66. 'upload_date': upload_date,
  67. 'view_count': view_count,
  68. 'like_count': like_count,
  69. 'dislike_count': dislike_count,
  70. 'formats': formats,
  71. }