logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

varzesh3.py (3238B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse_urlparse,
  6. compat_parse_qs,
  7. )
  8. from ..utils import (
  9. clean_html,
  10. remove_start,
  11. )
  12. class Varzesh3IE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?video\.varzesh3\.com/(?:[^/]+/)+(?P<id>[^/]+)/?'
  14. _TESTS = [{
  15. 'url': 'http://video.varzesh3.com/germany/bundesliga/5-%D9%88%D8%A7%DA%A9%D9%86%D8%B4-%D8%A8%D8%B1%D8%AA%D8%B1-%D8%AF%D8%B1%D9%88%D8%A7%D8%B2%D9%87%E2%80%8C%D8%A8%D8%A7%D9%86%D8%A7%D9%86%D8%9B%D9%87%D9%81%D8%AA%D9%87-26-%D8%A8%D9%88%D9%86%D8%AF%D8%B3/',
  16. 'md5': '2a933874cb7dce4366075281eb49e855',
  17. 'info_dict': {
  18. 'id': '76337',
  19. 'ext': 'mp4',
  20. 'title': '۵ واکنش برتر دروازه‌بانان؛هفته ۲۶ بوندسلیگا',
  21. 'description': 'فصل ۲۰۱۵-۲۰۱۴',
  22. 'thumbnail': r're:^https?://.*\.jpg$',
  23. },
  24. 'skip': 'HTTP 404 Error',
  25. }, {
  26. 'url': 'http://video.varzesh3.com/video/112785/%D8%AF%D9%84%D9%87-%D8%B9%D9%84%DB%8C%D8%9B-%D8%B3%D8%AA%D8%A7%D8%B1%D9%87-%D9%86%D9%88%D8%B8%D9%87%D9%88%D8%B1-%D9%84%DB%8C%DA%AF-%D8%A8%D8%B1%D8%AA%D8%B1-%D8%AC%D8%B2%DB%8C%D8%B1%D9%87',
  27. 'md5': '841b7cd3afbc76e61708d94e53a4a4e7',
  28. 'info_dict': {
  29. 'id': '112785',
  30. 'ext': 'mp4',
  31. 'title': 'دله علی؛ ستاره نوظهور لیگ برتر جزیره',
  32. 'description': 'فوتبال 120',
  33. },
  34. 'expected_warnings': ['description'],
  35. }]
  36. def _real_extract(self, url):
  37. display_id = self._match_id(url)
  38. webpage = self._download_webpage(url, display_id)
  39. video_url = self._search_regex(
  40. r'<source[^>]+src="([^"]+)"', webpage, 'video url')
  41. title = remove_start(self._html_search_regex(
  42. r'<title>([^<]+)</title>', webpage, 'title'), 'ویدیو ورزش 3 | ')
  43. description = self._html_search_regex(
  44. r'(?s)<div class="matn">(.+?)</div>',
  45. webpage, 'description', default=None)
  46. if description is None:
  47. description = clean_html(self._html_search_meta('description', webpage))
  48. thumbnail = self._og_search_thumbnail(webpage, default=None)
  49. if thumbnail is None:
  50. fb_sharer_url = self._search_regex(
  51. r'<a[^>]+href="(https?://www\.facebook\.com/sharer/sharer\.php?[^"]+)"',
  52. webpage, 'facebook sharer URL', fatal=False)
  53. sharer_params = compat_parse_qs(compat_urllib_parse_urlparse(fb_sharer_url).query)
  54. thumbnail = sharer_params.get('p[images][0]', [None])[0]
  55. video_id = self._search_regex(
  56. r"<link[^>]+rel='(?:canonical|shortlink)'[^>]+href='/\?p=([^']+)'",
  57. webpage, display_id, default=None)
  58. if video_id is None:
  59. video_id = self._search_regex(
  60. r'var\s+VideoId\s*=\s*(\d+);', webpage, 'video id',
  61. default=display_id)
  62. return {
  63. 'url': video_url,
  64. 'id': video_id,
  65. 'title': title,
  66. 'description': description,
  67. 'thumbnail': thumbnail,
  68. }