vice.py 3.4 KB

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