worldstarhiphop.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import re
  2. from .common import InfoExtractor
  3. class WorldStarHipHopIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www|m)\.worldstar(?:candy|hiphop)\.com/videos/video\.php\?v=(?P<id>.*)'
  5. _TEST = {
  6. "url": "http://www.worldstarhiphop.com/videos/video.php?v=wshh6a7q1ny0G34ZwuIO",
  7. "file": "wshh6a7q1ny0G34ZwuIO.mp4",
  8. "md5": "9d04de741161603bf7071bbf4e883186",
  9. "info_dict": {
  10. "title": "Video: KO Of The Week: MMA Fighter Gets Knocked Out By Swift Head Kick!"
  11. }
  12. }
  13. def _real_extract(self, url):
  14. m = re.match(self._VALID_URL, url)
  15. video_id = m.group('id')
  16. webpage_src = self._download_webpage(url, video_id)
  17. video_url = re.search(r'videoId=(.*?)&amp?',
  18. webpage_src)
  19. if video_url:
  20. self.to_screen(u'Vevo video detected:')
  21. return self.url_result('vevo:%s' % video_url.group(1), ie='Vevo')
  22. video_url = self._search_regex(r'so\.addVariable\("file","(.*?)"\)',
  23. webpage_src, u'video URL')
  24. if video_url is None:
  25. video_url = self._search_regex(r'videoId=(.*?)&amp?',
  26. webpage_src, u'video URL')
  27. self.to_screen(u'Vevo video detected:')
  28. vevo_id = 'vevo:%s' % video_url
  29. return self.url_result(vevo_id, ie='Vevo')
  30. if 'youtube' in video_url:
  31. self.to_screen(u'Youtube video detected:')
  32. return self.url_result(video_url, ie='Youtube')
  33. if 'mp4' in video_url:
  34. ext = 'mp4'
  35. else:
  36. ext = 'flv'
  37. video_title = self._html_search_regex(r"<title>(.*)</title>",
  38. webpage_src, u'title')
  39. # Getting thumbnail and if not thumbnail sets correct title for WSHH candy video.
  40. thumbnail = self._html_search_regex(r'rel="image_src" href="(.*)" />',
  41. webpage_src, u'thumbnail', fatal=False)
  42. if not thumbnail:
  43. _title = r"""candytitles.*>(.*)</span>"""
  44. mobj = re.search(_title, webpage_src)
  45. if mobj is not None:
  46. video_title = mobj.group(1)
  47. results = [{
  48. 'id': video_id,
  49. 'url' : video_url,
  50. 'title' : video_title,
  51. 'thumbnail' : thumbnail,
  52. 'ext' : ext,
  53. }]
  54. return results