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.

81 lines
2.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import urlencode_postdata
  5. import re
  6. class TwitCastingIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:[^/]+\.)?twitcasting\.tv/(?P<uploader_id>[^/]+)/movie/(?P<id>\d+)'
  8. _TESTS = [{
  9. 'url': 'https://twitcasting.tv/ivetesangalo/movie/2357609',
  10. 'md5': '745243cad58c4681dc752490f7540d7f',
  11. 'info_dict': {
  12. 'id': '2357609',
  13. 'ext': 'mp4',
  14. 'title': 'Live #2357609',
  15. 'uploader_id': 'ivetesangalo',
  16. 'description': "Moi! I'm live on TwitCasting from my iPhone.",
  17. 'thumbnail': r're:^https?://.*\.jpg$',
  18. },
  19. 'params': {
  20. 'skip_download': True,
  21. },
  22. }, {
  23. 'url': 'https://twitcasting.tv/mttbernardini/movie/3689740',
  24. 'info_dict': {
  25. 'id': '3689740',
  26. 'ext': 'mp4',
  27. 'title': 'Live playing something #3689740',
  28. 'uploader_id': 'mttbernardini',
  29. 'description': "I'm live on TwitCasting from my iPad. password: abc (Santa Marinella/Lazio, Italia)",
  30. 'thumbnail': r're:^https?://.*\.jpg$',
  31. },
  32. 'params': {
  33. 'skip_download': True,
  34. 'videopassword': 'abc',
  35. },
  36. }]
  37. def _real_extract(self, url):
  38. mobj = re.match(self._VALID_URL, url)
  39. video_id = mobj.group('id')
  40. uploader_id = mobj.group('uploader_id')
  41. video_password = self._downloader.params.get('videopassword')
  42. request_data = None
  43. if video_password:
  44. request_data = urlencode_postdata({
  45. 'password': video_password,
  46. })
  47. webpage = self._download_webpage(url, video_id, data=request_data)
  48. title = self._html_search_regex(
  49. r'(?s)<[^>]+id=["\']movietitle[^>]+>(.+?)</',
  50. webpage, 'title', default=None) or self._html_search_meta(
  51. 'twitter:title', webpage, fatal=True)
  52. m3u8_url = self._search_regex(
  53. (r'data-movie-url=(["\'])(?P<url>(?:(?!\1).)+)\1',
  54. r'(["\'])(?P<url>http.+?\.m3u8.*?)\1'),
  55. webpage, 'm3u8 url', group='url')
  56. formats = self._extract_m3u8_formats(
  57. m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native',
  58. m3u8_id='hls')
  59. thumbnail = self._og_search_thumbnail(webpage)
  60. description = self._og_search_description(
  61. webpage, default=None) or self._html_search_meta(
  62. 'twitter:description', webpage)
  63. return {
  64. 'id': video_id,
  65. 'title': title,
  66. 'description': description,
  67. 'thumbnail': thumbnail,
  68. 'uploader_id': uploader_id,
  69. 'formats': formats,
  70. }