pokemon.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. extract_attributes,
  7. int_or_none,
  8. )
  9. class PokemonIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?pokemon\.com/[a-z]{2}(?:.*?play=(?P<id>[a-z0-9]{32})|/pokemon-episodes/(?P<display_id>[^/?#]+))'
  11. _TESTS = [{
  12. 'url': 'http://www.pokemon.com/us/pokemon-episodes/19_01-from-a-to-z/?play=true',
  13. 'md5': '9fb209ae3a569aac25de0f5afc4ee08f',
  14. 'info_dict': {
  15. 'id': 'd0436c00c3ce4071ac6cee8130ac54a1',
  16. 'ext': 'mp4',
  17. 'title': 'From A to Z!',
  18. 'description': 'Bonnie makes a new friend, Ash runs into an old friend, and a terrifying premonition begins to unfold!',
  19. 'timestamp': 1460478136,
  20. 'upload_date': '20160412',
  21. },
  22. 'add_id': ['LimelightMedia']
  23. }, {
  24. 'url': 'http://www.pokemon.com/uk/pokemon-episodes/?play=2e8b5c761f1d4a9286165d7748c1ece2',
  25. 'only_matching': True,
  26. }]
  27. def _real_extract(self, url):
  28. video_id, display_id = re.match(self._VALID_URL, url).groups()
  29. webpage = self._download_webpage(url, video_id or display_id)
  30. video_data = extract_attributes(self._search_regex(
  31. r'(<[^>]+data-video-id="%s"[^>]*>)' % (video_id if video_id else '[a-z0-9]{32}'),
  32. webpage, 'video data element'))
  33. video_id = video_data['data-video-id']
  34. title = video_data['data-video-title']
  35. return {
  36. '_type': 'url_transparent',
  37. 'id': video_id,
  38. 'url': 'limelight:media:%s' % video_id,
  39. 'title': title,
  40. 'description': video_data.get('data-video-summary'),
  41. 'thumbnail': video_data.get('data-video-poster'),
  42. 'series': 'Pokémon',
  43. 'season_number': int_or_none(video_data.get('data-video-season')),
  44. 'episode': title,
  45. 'episode_number': int_or_none(video_data.get('data-video-episode')),
  46. 'ie_key': 'LimelightMedia',
  47. }