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.

68 lines
2.6 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. unified_strdate
  8. )
  9. class LifeNewsIE(InfoExtractor):
  10. IE_NAME = 'lifenews'
  11. IE_DESC = 'LIFE | NEWS'
  12. _VALID_URL = r'http://lifenews\.ru/(?:mobile/)?news/(?P<id>\d+)'
  13. _TEST = {
  14. 'url': 'http://lifenews.ru/news/126342',
  15. 'md5': 'e1b50a5c5fb98a6a544250f2e0db570a',
  16. 'info_dict': {
  17. 'id': '126342',
  18. 'ext': 'mp4',
  19. 'title': 'МВД разыскивает мужчин, оставивших в IKEA сумку с автоматом',
  20. 'description': 'Камеры наблюдения гипермаркета зафиксировали троих мужчин, спрятавших оружейный арсенал в камере хранения.',
  21. 'thumbnail': 'http://lifenews.ru/static/posts/2014/1/126342/.video.jpg',
  22. 'upload_date': '20140130',
  23. }
  24. }
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('id')
  28. webpage = self._download_webpage('http://lifenews.ru/mobile/news/%s' % video_id, video_id, 'Downloading page')
  29. video_url = self._html_search_regex(
  30. r'<video.*?src="([^"]+)".*?></video>', webpage, 'video URL')
  31. thumbnail = self._html_search_regex(
  32. r'<video.*?poster="([^"]+)".*?"></video>', webpage, 'video thumbnail')
  33. title = self._og_search_title(webpage)
  34. TITLE_SUFFIX = ' - Первый по срочным новостям — LIFE | NEWS'
  35. if title.endswith(TITLE_SUFFIX):
  36. title = title[:-len(TITLE_SUFFIX)]
  37. description = self._og_search_description(webpage)
  38. view_count = self._html_search_regex(
  39. r'<div class=\'views\'>(\d+)</div>', webpage, 'view count', fatal=False)
  40. comment_count = self._html_search_regex(
  41. r'<div class=\'comments\'>(\d+)</div>', webpage, 'comment count', fatal=False)
  42. upload_date = self._html_search_regex(
  43. r'<time datetime=\'([^\']+)\'>', webpage, 'upload date',fatal=False)
  44. if upload_date is not None:
  45. upload_date = unified_strdate(upload_date)
  46. return {
  47. 'id': video_id,
  48. 'url': video_url,
  49. 'thumbnail': thumbnail,
  50. 'title': title,
  51. 'description': description,
  52. 'view_count': int_or_none(view_count),
  53. 'comment_count': int_or_none(comment_count),
  54. 'upload_date': upload_date,
  55. }