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.

74 lines
2.9 KiB

10 years ago
10 years ago
  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. ExtractorError,
  9. )
  10. class LifeNewsIE(InfoExtractor):
  11. IE_NAME = 'lifenews'
  12. IE_DESC = 'LIFE | NEWS'
  13. _VALID_URL = r'http://lifenews\.ru/(?:mobile/)?news/(?P<id>\d+)'
  14. _TEST = {
  15. 'url': 'http://lifenews.ru/news/126342',
  16. 'md5': 'e1b50a5c5fb98a6a544250f2e0db570a',
  17. 'info_dict': {
  18. 'id': '126342',
  19. 'ext': 'mp4',
  20. 'title': 'МВД разыскивает мужчин, оставивших в IKEA сумку с автоматом',
  21. 'description': 'Камеры наблюдения гипермаркета зафиксировали троих мужчин, спрятавших оружейный арсенал в камере хранения.',
  22. 'thumbnail': 're:http://.*\.jpg',
  23. 'upload_date': '20140130',
  24. }
  25. }
  26. def _real_extract(self, url):
  27. mobj = re.match(self._VALID_URL, url)
  28. video_id = mobj.group('id')
  29. webpage = self._download_webpage('http://lifenews.ru/news/%s' % video_id, video_id, 'Downloading page')
  30. videos = re.findall(r'<video.*?poster="(?P<poster>[^"]+)".*?src="(?P<video>[^"]+)".*?></video>', webpage)
  31. if not videos:
  32. raise ExtractorError('No media links available for %s' % video_id)
  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\'>\s*(\d+)\s*</div>', webpage, 'view count', fatal=False)
  40. comment_count = self._html_search_regex(
  41. r'<div class=\'comments\'>\s*<span class=\'counter\'>\s*(\d+)\s*</span>', 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. def make_entry(video_id, media, video_number=None):
  47. return {
  48. 'id': video_id,
  49. 'url': media[1],
  50. 'thumbnail': media[0],
  51. 'title': title if video_number is None else '%s-video%s' % (title, video_number),
  52. 'description': description,
  53. 'view_count': int_or_none(view_count),
  54. 'comment_count': int_or_none(comment_count),
  55. 'upload_date': upload_date,
  56. }
  57. if len(videos) == 1:
  58. return make_entry(video_id, videos[0])
  59. else:
  60. return [make_entry(video_id, media, video_number + 1) for video_number, media in enumerate(videos)]