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.

78 lines
2.8 KiB

10 years ago
  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': 'mp4',
  13. 'title': 'VICE_COWBOYCAPITALISTS_PART01_v1_VICE_WM_1080p.mov',
  14. 'duration': 725.983,
  15. },
  16. 'params': {
  17. # Requires ffmpeg (m3u8 manifest)
  18. 'skip_download': True,
  19. },
  20. }, {
  21. 'url': 'https://news.vice.com/video/experimenting-on-animals-inside-the-monkey-lab',
  22. 'only_matching': True,
  23. }, {
  24. 'url': 'http://www.vice.com/ru/video/big-night-out-ibiza-clive-martin-229',
  25. 'only_matching': True,
  26. }, {
  27. 'url': 'https://munchies.vice.com/en/videos/watch-the-trailer-for-our-new-series-the-pizza-show',
  28. 'only_matching': True,
  29. }]
  30. def _real_extract(self, url):
  31. video_id = self._match_id(url)
  32. webpage = self._download_webpage(url, video_id)
  33. try:
  34. embed_code = self._search_regex(
  35. r'embedCode=([^&\'"]+)', webpage,
  36. 'ooyala embed code')
  37. ooyala_url = OoyalaIE._url_for_embed_code(embed_code)
  38. except ExtractorError:
  39. raise ExtractorError('The page doesn\'t contain a video', expected=True)
  40. return self.url_result(ooyala_url, ie='Ooyala')
  41. class ViceShowIE(InfoExtractor):
  42. _VALID_URL = r'https?://(?:.+?\.)?vice\.com/(?:[^/]+/)?show/(?P<id>[^/?#&]+)'
  43. _TEST = {
  44. 'url': 'https://munchies.vice.com/en/show/fuck-thats-delicious-2',
  45. 'info_dict': {
  46. 'id': 'fuck-thats-delicious-2',
  47. 'title': "Fuck, That's Delicious",
  48. 'description': 'Follow the culinary adventures of rapper Action Bronson during his ongoing world tour.',
  49. },
  50. 'playlist_count': 17,
  51. }
  52. def _real_extract(self, url):
  53. show_id = self._match_id(url)
  54. webpage = self._download_webpage(url, show_id)
  55. entries = [
  56. self.url_result(video_url, ViceIE.ie_key())
  57. for video_url, _ in re.findall(
  58. r'<h2[^>]+class="article-title"[^>]+data-id="\d+"[^>]*>\s*<a[^>]+href="(%s.*?)"'
  59. % ViceIE._VALID_URL, webpage)]
  60. title = self._search_regex(
  61. r'<title>(.+?)</title>', webpage, 'title', default=None)
  62. if title:
  63. title = re.sub(r'(.+)\s*\|\s*.+$', r'\1', title).strip()
  64. description = self._html_search_meta('description', webpage, 'description')
  65. return self.playlist_result(entries, show_id, title, description)