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.

91 lines
3.4 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import ExtractorError
  5. class ViceIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:.+?\.)?vice\.com/(?:[^/]+/)?videos?/(?P<id>[^/?#&]+)'
  7. _TESTS = [{
  8. 'url': 'http://www.vice.com/video/cowboy-capitalists-part-1',
  9. 'md5': 'e9d77741f9e42ba583e683cd170660f7',
  10. 'info_dict': {
  11. 'id': '43cW1mYzpia9IlestBjVpd23Yu3afAfp',
  12. 'ext': 'flv',
  13. 'title': 'VICE_COWBOYCAPITALISTS_PART01_v1_VICE_WM_1080p.mov',
  14. 'duration': 725.983,
  15. },
  16. 'add_ie': ['Ooyala'],
  17. }, {
  18. 'url': 'http://www.vice.com/video/how-to-hack-a-car',
  19. 'md5': '6fb2989a3fed069fb8eab3401fc2d3c9',
  20. 'info_dict': {
  21. 'id': '3jstaBeXgAs',
  22. 'ext': 'mp4',
  23. 'title': 'How to Hack a Car: Phreaked Out (Episode 2)',
  24. 'description': 'md5:ee95453f7ff495db8efe14ae8bf56f30',
  25. 'uploader_id': 'MotherboardTV',
  26. 'uploader': 'Motherboard',
  27. 'upload_date': '20140529',
  28. },
  29. 'add_ie': ['Youtube'],
  30. }, {
  31. 'url': 'https://news.vice.com/video/experimenting-on-animals-inside-the-monkey-lab',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'http://www.vice.com/ru/video/big-night-out-ibiza-clive-martin-229',
  35. 'only_matching': True,
  36. }, {
  37. 'url': 'https://munchies.vice.com/en/videos/watch-the-trailer-for-our-new-series-the-pizza-show',
  38. 'only_matching': True,
  39. }]
  40. def _real_extract(self, url):
  41. video_id = self._match_id(url)
  42. webpage = self._download_webpage(url, video_id)
  43. try:
  44. embed_code = self._search_regex(
  45. r'embedCode=([^&\'"]+)', webpage,
  46. 'ooyala embed code', default=None)
  47. if embed_code:
  48. return self.url_result('ooyala:%s' % embed_code, 'Ooyala')
  49. youtube_id = self._search_regex(
  50. r'data-youtube-id="([^"]+)"', webpage, 'youtube id')
  51. return self.url_result(youtube_id, 'Youtube')
  52. except ExtractorError:
  53. raise ExtractorError('The page doesn\'t contain a video', expected=True)
  54. class ViceShowIE(InfoExtractor):
  55. _VALID_URL = r'https?://(?:.+?\.)?vice\.com/(?:[^/]+/)?show/(?P<id>[^/?#&]+)'
  56. _TEST = {
  57. 'url': 'https://munchies.vice.com/en/show/fuck-thats-delicious-2',
  58. 'info_dict': {
  59. 'id': 'fuck-thats-delicious-2',
  60. 'title': "Fuck, That's Delicious",
  61. 'description': 'Follow the culinary adventures of rapper Action Bronson during his ongoing world tour.',
  62. },
  63. 'playlist_count': 17,
  64. }
  65. def _real_extract(self, url):
  66. show_id = self._match_id(url)
  67. webpage = self._download_webpage(url, show_id)
  68. entries = [
  69. self.url_result(video_url, ViceIE.ie_key())
  70. for video_url, _ in re.findall(
  71. r'<h2[^>]+class="article-title"[^>]+data-id="\d+"[^>]*>\s*<a[^>]+href="(%s.*?)"'
  72. % ViceIE._VALID_URL, webpage)]
  73. title = self._search_regex(
  74. r'<title>(.+?)</title>', webpage, 'title', default=None)
  75. if title:
  76. title = re.sub(r'(.+)\s*\|\s*.+$', r'\1', title).strip()
  77. description = self._html_search_meta('description', webpage, 'description')
  78. return self.playlist_result(entries, show_id, title, description)