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.

84 lines
2.9 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. class TeamcocoIE(InfoExtractor):
  5. _VALID_URL = r'http://teamcoco\.com/video/(?P<video_id>[0-9]+)?/?(?P<display_id>.*)'
  6. _TESTS = [
  7. {
  8. 'url': 'http://teamcoco.com/video/80187/conan-becomes-a-mary-kay-beauty-consultant',
  9. 'file': '80187.mp4',
  10. 'md5': '3f7746aa0dc86de18df7539903d399ea',
  11. 'info_dict': {
  12. 'title': 'Conan Becomes A Mary Kay Beauty Consultant',
  13. 'description': 'Mary Kay is perhaps the most trusted name in female beauty, so of course Conan is a natural choice to sell their products.'
  14. }
  15. }, {
  16. 'url': 'http://teamcoco.com/video/louis-ck-interview-george-w-bush',
  17. 'file': '19705.mp4',
  18. 'md5': 'cde9ba0fa3506f5f017ce11ead928f9a',
  19. 'info_dict': {
  20. "description": "Louis C.K. got starstruck by George W. Bush, so what? Part one.",
  21. "title": "Louis C.K. Interview Pt. 1 11/3/11"
  22. }
  23. }
  24. ]
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. display_id = mobj.group('display_id')
  28. webpage = self._download_webpage(url, display_id)
  29. video_id = mobj.group("video_id")
  30. if not video_id:
  31. video_id = self._html_search_regex(
  32. r'data-node-id="(\d+?)"',
  33. webpage, 'video id')
  34. data_url = 'http://teamcoco.com/cvp/2.0/%s.xml' % video_id
  35. data = self._download_xml(
  36. data_url, display_id, 'Downloading data webpage')
  37. qualities = ['500k', '480p', '1000k', '720p', '1080p']
  38. formats = []
  39. for filed in data.findall('files/file'):
  40. if filed.attrib.get('playmode') == 'all':
  41. # it just duplicates one of the entries
  42. break
  43. file_url = filed.text
  44. m_format = re.search(r'(\d+(k|p))\.mp4', file_url)
  45. if m_format is not None:
  46. format_id = m_format.group(1)
  47. else:
  48. format_id = filed.attrib['bitrate']
  49. tbr = (
  50. int(filed.attrib['bitrate'])
  51. if filed.attrib['bitrate'].isdigit()
  52. else None)
  53. try:
  54. quality = qualities.index(format_id)
  55. except ValueError:
  56. quality = -1
  57. formats.append({
  58. 'url': file_url,
  59. 'ext': 'mp4',
  60. 'tbr': tbr,
  61. 'format_id': format_id,
  62. 'quality': quality,
  63. })
  64. self._sort_formats(formats)
  65. return {
  66. 'id': video_id,
  67. 'display_id': display_id,
  68. 'formats': formats,
  69. 'title': self._og_search_title(webpage),
  70. 'thumbnail': self._og_search_thumbnail(webpage),
  71. 'description': self._og_search_description(webpage),
  72. }