blerp.py 4.6 KB

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