logo

youtube-dl

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

blerp.py (4803B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. from ..utils import (
  5. strip_or_none,
  6. traverse_obj,
  7. )
  8. from .common import InfoExtractor
  9. class BlerpIE(InfoExtractor):
  10. IE_NAME = 'blerp'
  11. _VALID_URL = r'https?://(?:www\.)?blerp\.com/soundbites/(?P<id>[0-9a-zA-Z]+)'
  12. _TESTS = [{
  13. 'url': 'https://blerp.com/soundbites/6320fe8745636cb4dd677a5a',
  14. 'info_dict': {
  15. 'id': '6320fe8745636cb4dd677a5a',
  16. 'title': 'Samsung Galaxy S8 Over the Horizon Ringtone 2016',
  17. 'uploader': 'luminousaj',
  18. 'uploader_id': '5fb81e51aa66ae000c395478',
  19. 'ext': 'mp3',
  20. 'tags': ['samsung', 'galaxy', 's8', 'over the horizon', '2016', 'ringtone'],
  21. }
  22. }, {
  23. 'url': 'https://blerp.com/soundbites/5bc94ef4796001000498429f',
  24. 'info_dict': {
  25. 'id': '5bc94ef4796001000498429f',
  26. 'title': 'Yee',
  27. 'uploader': '179617322678353920',
  28. 'uploader_id': '5ba99cf71386730004552c42',
  29. 'ext': 'mp3',
  30. 'tags': ['YEE', 'YEET', 'wo ha haah catchy tune yee', 'yee']
  31. }
  32. }]
  33. _GRAPHQL_OPERATIONNAME = "webBitePageGetBite"
  34. _GRAPHQL_QUERY = (
  35. '''query webBitePageGetBite($_id: MongoID!) {
  36. web {
  37. biteById(_id: $_id) {
  38. ...bitePageFrag
  39. __typename
  40. }
  41. __typename
  42. }
  43. }
  44. fragment bitePageFrag on Bite {
  45. _id
  46. title
  47. userKeywords
  48. keywords
  49. color
  50. visibility
  51. isPremium
  52. owned
  53. price
  54. extraReview
  55. isAudioExists
  56. image {
  57. filename
  58. original {
  59. url
  60. __typename
  61. }
  62. __typename
  63. }
  64. userReactions {
  65. _id
  66. reactions
  67. createdAt
  68. __typename
  69. }
  70. topReactions
  71. totalSaveCount
  72. saved
  73. blerpLibraryType
  74. license
  75. licenseMetaData
  76. playCount
  77. totalShareCount
  78. totalFavoriteCount
  79. totalAddedToBoardCount
  80. userCategory
  81. userAudioQuality
  82. audioCreationState
  83. transcription
  84. userTranscription
  85. description
  86. createdAt
  87. updatedAt
  88. author
  89. listingType
  90. ownerObject {
  91. _id
  92. username
  93. profileImage {
  94. filename
  95. original {
  96. url
  97. __typename
  98. }
  99. __typename
  100. }
  101. __typename
  102. }
  103. transcription
  104. favorited
  105. visibility
  106. isCurated
  107. sourceUrl
  108. audienceRating
  109. strictAudienceRating
  110. ownerId
  111. reportObject {
  112. reportedContentStatus
  113. __typename
  114. }
  115. giphy {
  116. mp4
  117. gif
  118. __typename
  119. }
  120. audio {
  121. filename
  122. original {
  123. url
  124. __typename
  125. }
  126. mp3 {
  127. url
  128. __typename
  129. }
  130. __typename
  131. }
  132. __typename
  133. }
  134. ''')
  135. def _real_extract(self, url):
  136. audio_id = self._match_id(url)
  137. data = {
  138. 'operationName': self._GRAPHQL_OPERATIONNAME,
  139. 'query': self._GRAPHQL_QUERY,
  140. 'variables': {
  141. '_id': audio_id
  142. }
  143. }
  144. headers = {
  145. 'Content-Type': 'application/json'
  146. }
  147. json_result = self._download_json('https://api.blerp.com/graphql',
  148. audio_id, data=json.dumps(data).encode('utf-8'), headers=headers)
  149. bite_json = json_result['data']['web']['biteById']
  150. info_dict = {
  151. 'id': bite_json['_id'],
  152. 'url': bite_json['audio']['mp3']['url'],
  153. 'title': bite_json['title'],
  154. 'uploader': traverse_obj(bite_json, ('ownerObject', 'username'), expected_type=strip_or_none),
  155. 'uploader_id': traverse_obj(bite_json, ('ownerObject', '_id'), expected_type=strip_or_none),
  156. 'ext': 'mp3',
  157. 'tags': list(filter(None, map(strip_or_none, (traverse_obj(bite_json, 'userKeywords', expected_type=list) or []))) or None)
  158. }
  159. return info_dict