scrolller.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import json
  2. from .common import InfoExtractor
  3. from ..utils import determine_ext, int_or_none
  4. class ScrolllerIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:www\.)?scrolller\.com/(?P<id>[\w-]+)'
  6. _TESTS = [{
  7. 'url': 'https://scrolller.com/a-helping-hand-1k9pxikxkw',
  8. 'info_dict': {
  9. 'id': 'a-helping-hand-1k9pxikxkw',
  10. 'ext': 'mp4',
  11. 'thumbnail': 'https://zepto.scrolller.com/a-helping-hand-3ty9q8x094-540x960.jpg',
  12. 'title': 'A helping hand',
  13. 'age_limit': 0,
  14. },
  15. }, {
  16. 'url': 'https://scrolller.com/tigers-chasing-a-drone-c5d1f2so6j',
  17. 'info_dict': {
  18. 'id': 'tigers-chasing-a-drone-c5d1f2so6j',
  19. 'ext': 'mp4',
  20. 'thumbnail': 'https://zepto.scrolller.com/tigers-chasing-a-drone-az9pkpguwe-540x303.jpg',
  21. 'title': 'Tigers chasing a drone',
  22. 'age_limit': 0,
  23. },
  24. }, {
  25. 'url': 'https://scrolller.com/baby-rhino-smells-something-9chhugsv9p',
  26. 'info_dict': {
  27. 'id': 'baby-rhino-smells-something-9chhugsv9p',
  28. 'ext': 'mp4',
  29. 'thumbnail': 'https://atto.scrolller.com/hmm-whats-that-smell-bh54mf2c52-300x224.jpg',
  30. 'title': 'Baby rhino smells something',
  31. 'age_limit': 0,
  32. },
  33. }, {
  34. 'url': 'https://scrolller.com/its-all-fun-and-games-cco8jjmoh7',
  35. 'info_dict': {
  36. 'id': 'its-all-fun-and-games-cco8jjmoh7',
  37. 'ext': 'mp4',
  38. 'thumbnail': 'https://atto.scrolller.com/its-all-fun-and-games-3amk9vg7m3-540x649.jpg',
  39. 'title': 'It\'s all fun and games...',
  40. 'age_limit': 0,
  41. },
  42. }, {
  43. 'url': 'https://scrolller.com/may-the-force-be-with-you-octokuro-yeytg1fs7a',
  44. 'info_dict': {
  45. 'id': 'may-the-force-be-with-you-octokuro-yeytg1fs7a',
  46. 'ext': 'mp4',
  47. 'thumbnail': 'https://thumbs2.redgifs.com/DarkStarchyNautilus-poster.jpg',
  48. 'title': 'May the force be with you (Octokuro)',
  49. 'age_limit': 18,
  50. },
  51. }]
  52. def _real_extract(self, url):
  53. video_id = self._match_id(url)
  54. query = {
  55. 'query': '''{
  56. getSubredditPost(url:"/%s"){
  57. id
  58. title
  59. isNsfw
  60. mediaSources{
  61. url
  62. width
  63. height
  64. }
  65. }
  66. }''' % video_id, # noqa: UP031
  67. }
  68. video_data = self._download_json(
  69. 'https://api.scrolller.com/api/v2/graphql', video_id, data=json.dumps(query).encode(),
  70. headers={'Content-Type': 'application/json'})['data']['getSubredditPost']
  71. formats, thumbnails = [], []
  72. for source in video_data['mediaSources']:
  73. if determine_ext(source.get('url')) in ('jpg', 'png'):
  74. thumbnails.append({
  75. 'url': source['url'],
  76. 'width': int_or_none(source.get('width')),
  77. 'height': int_or_none(source.get('height')),
  78. })
  79. elif source.get('url'):
  80. formats.append({
  81. 'url': source['url'],
  82. 'width': int_or_none(source.get('width')),
  83. 'height': int_or_none(source.get('height')),
  84. })
  85. if not formats:
  86. self.raise_no_formats('There is no video.', expected=True, video_id=video_id)
  87. return {
  88. 'id': video_id,
  89. 'title': video_data.get('title'),
  90. 'thumbnails': thumbnails,
  91. 'formats': formats,
  92. 'age_limit': 18 if video_data.get('isNsfw') else 0,
  93. }