pornhub.py 1000 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python3
  2. # coding=utf-8
  3. import logging
  4. from typing import Optional
  5. from praw.models import Submission
  6. from bdfr.exceptions import SiteDownloaderError
  7. from bdfr.resource import Resource
  8. from bdfr.site_authenticator import SiteAuthenticator
  9. from bdfr.site_downloaders.youtube import Youtube
  10. logger = logging.getLogger(__name__)
  11. class PornHub(Youtube):
  12. def __init__(self, post: Submission):
  13. super().__init__(post)
  14. def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
  15. ytdl_options = {
  16. 'format': 'best',
  17. 'nooverwrites': True,
  18. }
  19. if video_attributes := super().get_video_attributes(self.post.url):
  20. extension = video_attributes['ext']
  21. else:
  22. raise SiteDownloaderError()
  23. out = Resource(
  24. self.post,
  25. self.post.url,
  26. super()._download_video(ytdl_options),
  27. extension,
  28. )
  29. return [out]