gofile.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import hashlib
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. try_get
  6. )
  7. class GofileIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?gofile\.io/d/(?P<id>[^/]+)'
  9. _TESTS = [{
  10. 'url': 'https://gofile.io/d/AMZyDw',
  11. 'info_dict': {
  12. 'id': 'AMZyDw',
  13. },
  14. 'playlist_mincount': 2,
  15. 'playlist': [{
  16. 'info_dict': {
  17. 'id': 'de571ac1-5edc-42e2-8ec2-bdac83ad4a31',
  18. 'filesize': 928116,
  19. 'ext': 'mp4',
  20. 'title': 'nuuh',
  21. 'release_timestamp': 1638338704,
  22. 'release_date': '20211201',
  23. }
  24. }]
  25. }, {
  26. 'url': 'https://gofile.io/d/is8lKr',
  27. 'info_dict': {
  28. 'id': 'TMjXd9',
  29. 'ext': 'mp4',
  30. },
  31. 'playlist_count': 0,
  32. 'skip': 'No video/audio found at provided URL.',
  33. }, {
  34. 'url': 'https://gofile.io/d/TMjXd9',
  35. 'info_dict': {
  36. 'id': 'TMjXd9',
  37. },
  38. 'playlist_count': 1,
  39. }, {
  40. 'url': 'https://gofile.io/d/gqOtRf',
  41. 'info_dict': {
  42. 'id': 'gqOtRf',
  43. },
  44. 'playlist_mincount': 1,
  45. 'params': {
  46. 'videopassword': 'password',
  47. },
  48. }]
  49. _TOKEN = None
  50. def _real_initialize(self):
  51. token = self._get_cookies('https://gofile.io/').get('accountToken')
  52. if token:
  53. self._TOKEN = token.value
  54. return
  55. account_data = self._download_json(
  56. 'https://api.gofile.io/createAccount', None, note='Getting a new guest account')
  57. self._TOKEN = account_data['data']['token']
  58. self._set_cookie('gofile.io', 'accountToken', self._TOKEN)
  59. def _entries(self, file_id):
  60. query_params = {
  61. 'contentId': file_id,
  62. 'token': self._TOKEN,
  63. 'websiteToken': 12345,
  64. }
  65. password = self.get_param('videopassword')
  66. if password:
  67. query_params['password'] = hashlib.sha256(password.encode('utf-8')).hexdigest()
  68. files = self._download_json(
  69. 'https://api.gofile.io/getContent', file_id, note='Getting filelist', query=query_params)
  70. status = files['status']
  71. if status == 'error-passwordRequired':
  72. raise ExtractorError(
  73. 'This video is protected by a password, use the --video-password option', expected=True)
  74. elif status != 'ok':
  75. raise ExtractorError(f'{self.IE_NAME} said: status {status}', expected=True)
  76. found_files = False
  77. for file in (try_get(files, lambda x: x['data']['contents'], dict) or {}).values():
  78. file_type, file_format = file.get('mimetype').split('/', 1)
  79. if file_type not in ('video', 'audio') and file_format != 'vnd.mts':
  80. continue
  81. found_files = True
  82. file_url = file.get('link')
  83. if file_url:
  84. yield {
  85. 'id': file['id'],
  86. 'title': file['name'].rsplit('.', 1)[0],
  87. 'url': file_url,
  88. 'filesize': file.get('size'),
  89. 'release_timestamp': file.get('createTime')
  90. }
  91. if not found_files:
  92. raise ExtractorError('No video/audio found at provided URL.', expected=True)
  93. def _real_extract(self, url):
  94. file_id = self._match_id(url)
  95. return self.playlist_result(self._entries(file_id), playlist_id=file_id)