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.

88 lines
3.3 KiB

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