logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

pyvideo.py (2764B)


  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import int_or_none
  6. class PyvideoIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?pyvideo\.org/(?P<category>[^/]+)/(?P<id>[^/?#&.]+)'
  8. _TESTS = [{
  9. 'url': 'http://pyvideo.org/pycon-us-2013/become-a-logging-expert-in-30-minutes.html',
  10. 'info_dict': {
  11. 'id': 'become-a-logging-expert-in-30-minutes',
  12. },
  13. 'playlist_count': 2,
  14. }, {
  15. 'url': 'http://pyvideo.org/pygotham-2012/gloriajw-spotifywitherikbernhardsson182m4v.html',
  16. 'md5': '5fe1c7e0a8aa5570330784c847ff6d12',
  17. 'info_dict': {
  18. 'id': '2542',
  19. 'ext': 'm4v',
  20. 'title': 'Gloriajw-SpotifyWithErikBernhardsson182.m4v',
  21. },
  22. }]
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. category = mobj.group('category')
  26. video_id = mobj.group('id')
  27. entries = []
  28. data = self._download_json(
  29. 'https://raw.githubusercontent.com/pyvideo/data/master/%s/videos/%s.json'
  30. % (category, video_id), video_id, fatal=False)
  31. if data:
  32. for video in data['videos']:
  33. video_url = video.get('url')
  34. if video_url:
  35. if video.get('type') == 'youtube':
  36. entries.append(self.url_result(video_url, 'Youtube'))
  37. else:
  38. entries.append({
  39. 'id': compat_str(data.get('id') or video_id),
  40. 'url': video_url,
  41. 'title': data['title'],
  42. 'description': data.get('description') or data.get('summary'),
  43. 'thumbnail': data.get('thumbnail_url'),
  44. 'duration': int_or_none(data.get('duration')),
  45. })
  46. else:
  47. webpage = self._download_webpage(url, video_id)
  48. title = self._og_search_title(webpage)
  49. media_urls = self._search_regex(
  50. r'(?s)Media URL:(.+?)</li>', webpage, 'media urls')
  51. for m in re.finditer(
  52. r'<a[^>]+href=(["\'])(?P<url>http.+?)\1', media_urls):
  53. media_url = m.group('url')
  54. if re.match(r'https?://www\.youtube\.com/watch\?v=.*', media_url):
  55. entries.append(self.url_result(media_url, 'Youtube'))
  56. else:
  57. entries.append({
  58. 'id': video_id,
  59. 'url': media_url,
  60. 'title': title,
  61. })
  62. return self.playlist_result(entries, video_id)