logo

youtube-dl

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

biqle.py (3864B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from .vk import VKIE
  5. from ..compat import (
  6. compat_b64decode,
  7. compat_urllib_parse_unquote,
  8. )
  9. from ..utils import int_or_none
  10. class BIQLEIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?biqle\.(?:com|org|ru)/watch/(?P<id>-?\d+_\d+)'
  12. _TESTS = [{
  13. # Youtube embed
  14. 'url': 'https://biqle.ru/watch/-115995369_456239081',
  15. 'md5': '97af5a06ee4c29bbf9c001bdb1cf5c06',
  16. 'info_dict': {
  17. 'id': '8v4f-avW-VI',
  18. 'ext': 'mp4',
  19. 'title': "PASSE-PARTOUT - L'ete c'est fait pour jouer",
  20. 'description': 'Passe-Partout',
  21. 'uploader_id': 'mrsimpsonstef3',
  22. 'uploader': 'Phanolito',
  23. 'upload_date': '20120822',
  24. },
  25. }, {
  26. 'url': 'http://biqle.org/watch/-44781847_168547604',
  27. 'md5': '7f24e72af1db0edf7c1aaba513174f97',
  28. 'info_dict': {
  29. 'id': '-44781847_168547604',
  30. 'ext': 'mp4',
  31. 'title': 'Ребенок в шоке от автоматической мойки',
  32. 'timestamp': 1396633454,
  33. 'uploader': 'Dmitry Kotov',
  34. 'upload_date': '20140404',
  35. 'uploader_id': '47850140',
  36. },
  37. }]
  38. def _real_extract(self, url):
  39. video_id = self._match_id(url)
  40. webpage = self._download_webpage(url, video_id)
  41. embed_url = self._proto_relative_url(self._search_regex(
  42. r'<iframe.+?src="((?:https?:)?//(?:daxab\.com|dxb\.to|[^/]+/player)/[^"]+)".*?></iframe>',
  43. webpage, 'embed url'))
  44. if VKIE.suitable(embed_url):
  45. return self.url_result(embed_url, VKIE.ie_key(), video_id)
  46. embed_page = self._download_webpage(
  47. embed_url, video_id, headers={'Referer': url})
  48. video_ext = self._get_cookies(embed_url).get('video_ext')
  49. if video_ext:
  50. video_ext = compat_urllib_parse_unquote(video_ext.value)
  51. if not video_ext:
  52. video_ext = compat_b64decode(self._search_regex(
  53. r'video_ext\s*:\s*[\'"]([A-Za-z0-9+/=]+)',
  54. embed_page, 'video_ext')).decode()
  55. video_id, sig, _, access_token = video_ext.split(':')
  56. item = self._download_json(
  57. 'https://api.vk.com/method/video.get', video_id,
  58. headers={'User-Agent': 'okhttp/3.4.1'}, query={
  59. 'access_token': access_token,
  60. 'sig': sig,
  61. 'v': 5.44,
  62. 'videos': video_id,
  63. })['response']['items'][0]
  64. title = item['title']
  65. formats = []
  66. for f_id, f_url in item.get('files', {}).items():
  67. if f_id == 'external':
  68. return self.url_result(f_url)
  69. ext, height = f_id.split('_')
  70. formats.append({
  71. 'format_id': height + 'p',
  72. 'url': f_url,
  73. 'height': int_or_none(height),
  74. 'ext': ext,
  75. })
  76. self._sort_formats(formats)
  77. thumbnails = []
  78. for k, v in item.items():
  79. if k.startswith('photo_') and v:
  80. width = k.replace('photo_', '')
  81. thumbnails.append({
  82. 'id': width,
  83. 'url': v,
  84. 'width': int_or_none(width),
  85. })
  86. return {
  87. 'id': video_id,
  88. 'title': title,
  89. 'formats': formats,
  90. 'comment_count': int_or_none(item.get('comments')),
  91. 'description': item.get('description'),
  92. 'duration': int_or_none(item.get('duration')),
  93. 'thumbnails': thumbnails,
  94. 'timestamp': int_or_none(item.get('date')),
  95. 'uploader': item.get('owner_id'),
  96. 'view_count': int_or_none(item.get('views')),
  97. }