PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/wagtail/wagtailembeds/oembed_providers.py

https://gitlab.com/hanswang2012/wagtail
Python | 321 lines | 311 code | 9 blank | 1 comment | 5 complexity | 25a7faec6fe307777a794261e95d6d9c MD5 | raw file
  1. OEMBED_ENDPOINTS = {
  2. "https://speakerdeck.com/oembed.{format}": [
  3. "^http(?:s)?://speakerdeck\\.com/.+$"
  4. ],
  5. "https://alpha-api.app.net/oembed": [
  6. "^http(?:s)?://alpha\\.app\\.net/[^#?/]+/post/.+$",
  7. "^http(?:s)?://photos\\.app\\.net/[^#?/]+/.+$"
  8. ],
  9. "http://www.youtube.com/oembed": [
  10. "^http(?:s)?://(?:[-\\w]+\\.)?youtube\\.com/watch.+$",
  11. "^http(?:s)?://(?:[-\\w]+\\.)?youtube\\.com/v/.+$",
  12. "^http(?:s)?://youtu\\.be/.+$",
  13. "^http(?:s)?://(?:[-\\w]+\\.)?youtube\\.com/user/.+$",
  14. "^http(?:s)?://(?:[-\\w]+\\.)?youtube\\.com/[^#?/]+#[^#?/]+/.+$",
  15. "^http(?:s)?://m\\.youtube\\.com/index.+$",
  16. "^http(?:s)?://(?:[-\\w]+\\.)?youtube\\.com/profile.+$",
  17. "^http(?:s)?://(?:[-\\w]+\\.)?youtube\\.com/view_play_list.+$",
  18. "^http(?:s)?://(?:[-\\w]+\\.)?youtube\\.com/playlist.+$"
  19. ],
  20. "http://backend.deviantart.com/oembed": [
  21. "^http://(?:[-\\w]+\\.)?deviantart\\.com/art/.+$",
  22. "^http://fav\\.me/.+$",
  23. "^http://sta\\.sh/.+$",
  24. "^http://(?:[-\\w]+\\.)?deviantart\\.com/[^#?/]+#/d.+$"
  25. ],
  26. "http://blip.tv/oembed/": [
  27. "^http://[-\\w]+\\.blip\\.tv/.+$"
  28. ],
  29. "http://www.dailymotion.com/api/oembed/": [
  30. "^http://[-\\w]+\\.dailymotion\\.com/.+$"
  31. ],
  32. "http://www.flickr.com/services/oembed/": [
  33. "^http://[-\\w]+\\.flickr\\.com/photos/.+$",
  34. "^http://flic\\.kr\\.com/.+$"
  35. ],
  36. "http://www.hulu.com/api/oembed.{format}": [
  37. "^http://www\\.hulu\\.com/watch/.+$"
  38. ],
  39. "http://www.nfb.ca/remote/services/oembed/": [
  40. "^http://(?:[-\\w]+\\.)?nfb\\.ca/film/.+$"
  41. ],
  42. "http://qik.com/api/oembed.{format}": [
  43. "^http://qik\\.com/.+$",
  44. "^http://qik\\.ly/.+$"
  45. ],
  46. "http://revision3.com/api/oembed/": [
  47. "^http://[-\\w]+\\.revision3\\.com/.+$"
  48. ],
  49. "http://www.scribd.com/services/oembed": [
  50. "^http://[-\\w]+\\.scribd\\.com/.+$"
  51. ],
  52. "http://www.viddler.com/oembed/": [
  53. "^http://[-\\w]+\\.viddler\\.com/v/.+$",
  54. "^http://[-\\w]+\\.viddler\\.com/explore/.+$"
  55. ],
  56. "http://www.vimeo.com/api/oembed.{format}": [
  57. "^http(?:s)?://(?:www\\.)?vimeo\\.com/.+$",
  58. "^http(?:s)?://player\\.vimeo\\.com/.+$"
  59. ],
  60. "http://dotsub.com/services/oembed": [
  61. "^http://dotsub\\.com/view/.+$"
  62. ],
  63. "http://www.yfrog.com/api/oembed": [
  64. "^http(?:s)?://(?:www\\.)?yfrog\\.com/.+$",
  65. "^http(?:s)?://(?:www\\.)?yfrog\\.us/.+$"
  66. ],
  67. "http://clikthrough.com/services/oembed": [
  68. "^http(?:s)?://(?:[-\\w]+\\.)?clikthrough\\.com/.+$"
  69. ],
  70. "http://www.kinomap.com/oembed": [
  71. "^http://[-\\w]+\\.kinomap\\.com/.+$"
  72. ],
  73. "https://photobucket.com/oembed": [
  74. "^http://(?:[-\\w]+\\.)?photobucket\\.com/albums/.+$",
  75. "^http://(?:[-\\w]+\\.)?photobucket\\.com/groups/.+$"
  76. ],
  77. "http://api.instagram.com/oembed": [
  78. "^http://instagr\\.am/p/.+$",
  79. "^http://instagram\\.com/p/.+$"
  80. ],
  81. "https://www.slideshare.net/api/oembed/2": [
  82. "^http://www\\.slideshare\\.net/.+$"
  83. ],
  84. "http://tv.majorleaguegaming.com/oembed": [
  85. "^http://mlg\\.tv/.+$",
  86. "^http://tv\\.majorleaguegaming\\.com/.+$"
  87. ],
  88. "http://my.opera.com/service/oembed": [
  89. "^http://my\\.opera\\.com/.+$"
  90. ],
  91. "http://skitch.com/oembed": [
  92. "^http(?:s)?://(?:www\\.)?skitch\\.com/.+$",
  93. "^http://skit\\.ch/.+$"
  94. ],
  95. "https://api.twitter.com/1/statuses/oembed.{format}": [
  96. "^http(?:s)?://twitter\\.com/(?:#!)?[^#?/]+/status/.+$"
  97. ],
  98. "https://soundcloud.com/oembed": [
  99. "^https://soundcloud\\.com/[^#?/]+/.+$"
  100. ],
  101. "http://www.collegehumor.com/oembed.{format}": [
  102. "^http://(?:www\\.)?collegehumor\\.com/video/.+$",
  103. "^http://(?:www\\.)?collegehumor\\.com/video:.+$"
  104. ],
  105. "http://www.polleverywhere.com/services/oembed/": [
  106. "^http://www\\.polleverywhere\\.com/polls/.+$",
  107. "^http://www\\.polleverywhere\\.com/multiple_choice_polls/.+$",
  108. "^http://www\\.polleverywhere\\.com/free_text_polls/.+$"
  109. ],
  110. "http://www.ifixit.com/Embed": [
  111. "^http://www\\.ifixit\\.com/[^#?/]+/[^#?/]+/.+$"
  112. ],
  113. "http://api.smugmug.com/services/oembed/": [
  114. "^http(?:s)?://(?:www\\.)?smugmug\\.com/[^#?/]+/.+$"
  115. ],
  116. "https://github.com/api/oembed": [
  117. "^http(?:s)?://gist\\.github\\.com/.+$"
  118. ],
  119. "http://animoto.com/services/oembed": [
  120. "^http://animoto\\.com/play/.+$"
  121. ],
  122. "http://www.rdio.com/api/oembed": [
  123. "^http://(?:wwww\\.)?rdio\\.com/people/[^#?/]+/playlists/.+$",
  124. "^http://[-\\w]+\\.rdio\\.com/artist/[^#?/]+/album/.+$"
  125. ],
  126. "http://api.5min.com/oembed.{format}": [
  127. "^http://www\\.5min\\.com/video/.+$"
  128. ],
  129. "http://500px.com/photo/{1}/oembed.{format}": [
  130. "^http://500px\\.com/photo/([^#?/]+)(?:.+)?$"
  131. ],
  132. "http://api.dipdive.com/oembed.{format}": [
  133. "^http://[-\\w]+\\.dipdive\\.com/media/.+$"
  134. ],
  135. "http://video.yandex.ru/oembed.{format}": [
  136. "^http://video\\.yandex\\.ru/users/[^#?/]+/view/.+$"
  137. ],
  138. "http://www.mixcloud.com/oembed/": [
  139. "^http://www\\.mixcloud\\.com/oembed/[^#?/]+/.+$"
  140. ],
  141. "http://www.kickstarter.com/services/oembed": [
  142. "^http(?:s)://[-\\w]+\\.kickstarter\\.com/projects/.+$"
  143. ],
  144. "http://coub.com/api/oembed.{format}": [
  145. "^http(?:s)?://coub\\.com/view/.+$",
  146. "^http(?:s)?://coub\\.com/embed/.+$"
  147. ],
  148. "http://www.screenr.com/api/oembed.{format}": [
  149. "^http://www\\.screenr\\.com/.+$"
  150. ],
  151. "http://www.funnyordie.com/oembed.{format}": [
  152. "^http://www\\.funnyordie\\.com/videos/.+$"
  153. ],
  154. "http://fast.wistia.com/oembed.{format}": [
  155. "^http://[-\\w]+\\.wista\\.com/medias/.+$"
  156. ],
  157. "http://www.ustream.tv/oembed": [
  158. "^http(?:s)?://(?:www\\.)?ustream\\.tv/.+$",
  159. "^http(?:s)?://(?:www\\.)?ustream\\.com/.+$",
  160. "^http://ustre\\.am/.+$"
  161. ],
  162. "http://wordpress.tv/oembed/": [
  163. "^http://wordpress\\.tv/.+$"
  164. ],
  165. "http://polldaddy.com/oembed/": [
  166. "^http(?:s)?://(?:[-\\w]+\\.)?polldaddy\\.com/.+$"
  167. ],
  168. "http://api.bambuser.com/oembed.{format}": [
  169. "^http://bambuser\\.com/channel/[^#?/]+/broadcast/.+$",
  170. "^http://bambuser\\.com/channel/.+$",
  171. "^http://bambuser\\.com/v/.+$"
  172. ],
  173. "http://www.ted.com/talks/oembed.{format}": [
  174. "^http(?:s)?://(?:www\\.)?ted\\.com/talks/.+$",
  175. "^http(?:s)?://(?:www\\.)?ted\\.com/talks/lang/[^#?/]+/.+$",
  176. "^http(?:s)?://(?:www\\.)?ted\\.com/index\\.php/talks/.+$",
  177. "^http(?:s)?://(?:www\\.)?ted\\.com/index\\.php/talks/lang/[^#?/]+/.+$"
  178. ],
  179. "http://chirb.it/oembed.{format}": [
  180. "^http://chirb\\.it/.+$"
  181. ],
  182. "https://www.circuitlab.com/circuit/oembed/": [
  183. "^http(?:s)?://(?:www\\.)?circuitlab\\.com/circuit/.+$"
  184. ],
  185. "http://api.geograph.org.uk/api/oembed": [
  186. "^http://(?:[-\\w]+\\.)?geograph\\.org\\.uk/.+$",
  187. "^http://(?:[-\\w]+\\.)?geograph\\.co\\.uk/.+$",
  188. "^http://(?:[-\\w]+\\.)?geograph\\.ie/.+$"
  189. ],
  190. "http://geo.hlipp.de/restapi.php/api/oembed": [
  191. "^http://geo-en\\.hlipp\\.de/.+$",
  192. "^http://geo\\.hlipp\\.de/.+$",
  193. "^http://germany\\.geograph\\.org/.+$"
  194. ],
  195. "http://www.geograph.org.gg/api/oembed": [
  196. "^http://(?:[-\\w]+\\.)?geograph\\.org\\.gg/.+$",
  197. "^http://(?:[-\\w]+\\.)?geograph\\.org\\.je/.+$",
  198. "^http://channel-islands\\.geograph\\.org/.+$",
  199. "^http://channel-islands\\.geographs\\.org/.+$",
  200. "^http://(?:[-\\w]+\\.)?channel\\.geographs\\.org/.+$"
  201. ],
  202. "http://vzaar.com/api/videos/{1}.{format}": [
  203. "^http://(?:www\\.)?vzaar\\.com/videos/([^#?/]+)(?:.+)?$",
  204. "^http://www\\.vzaar\\.tv/([^#?/]+)(?:.+)?$",
  205. "^http://vzaar\\.tv/([^#?/]+)(?:.+)?$",
  206. "^http://vzaar\\.me/([^#?/]+)(?:.+)?$",
  207. "^http://[-\\w]+\\.vzaar\\.me/([^#?/]+)(?:.+)?$"
  208. ],
  209. "http://api.minoto-video.com/services/oembed.{format}": [
  210. "^http://api\\.minoto-video\\.com/publishers/[^#?/]+/videos/.+$",
  211. "^http://dashboard\\.minoto-video\\.com/main/video/details/.+$",
  212. "^http://embed\\.minoto-video\\.com/.+$"
  213. ],
  214. "http://www.videojug.com/oembed.{format}": [
  215. "^http(?:s)?://(?:[-\\w]+\\.)?videojug\\.com/film/.+$",
  216. "^http(?:s)?://(?:[-\\w]+\\.)?videojug\\.com/payer/.+$",
  217. "^http(?:s)?://(?:[-\\w]+\\.)?videojug\\.com/interview/.+$"
  218. ],
  219. "http://videos.sapo.pt/oembed": [
  220. "^http(?:s)?://videos\\.sapo\\.pt/.+$"
  221. ],
  222. "http://vhx.tv/services/oembed.{format}": [
  223. "^http(?:s)?://(?:www\\.)?vhx\\.tv/.+$"
  224. ],
  225. "http://api.justin.tv/api/embed/from_url.{format}": [
  226. "^http(?:s)?://(?:www\\.)?justin\\.tv/.+$"
  227. ],
  228. "http://official.fm/services/oembed.{format}": [
  229. "^http(?:s)?://official\\.fm/.+$"
  230. ],
  231. "http://huffduffer.com/oembed": [
  232. "^http(?:s)?://(?:www\\.)?huffduffer\\.com/[^#?/]+/.+$"
  233. ],
  234. "https://embed.spotify.com/oembed/": [
  235. "^http(?:s)?://open\\.spotify\\.com/.+$",
  236. "^http(?:s)?://spoti\\.fi/.+$"
  237. ],
  238. "http://shoudio.com/api/oembed": [
  239. "^http://shoudio\\.com/.+$",
  240. "^http://shoud\\.io/.+$"
  241. ],
  242. "http://api.mobypicture.com/oEmbed": [
  243. "^http(?:s)?://(?:www\\.)?mobypicture\\.com/user/[^#?/]+/view/.+$",
  244. "^http(?:s)?://(?:www\\.)?moby\\.to/.+$"
  245. ],
  246. "http://www.23hq.com/23/oembed": [
  247. "^http(?:s)?://(?:www\\.)?23hq\\.com/[^#?/]+/photo/.+$"
  248. ],
  249. "http://gmep.org/oembed.{format}": [
  250. "^http(?:s)?://(?:www\\.)?gmep\\.org/.+$",
  251. "^http(?:s)?://gmep\\.imeducate\\.com/.+$"
  252. ],
  253. "http://oembed.urtak.com/1/oembed": [
  254. "^http(?:s)?://(?:[-\\w]+\\.)?urtak\\.com/.+$"
  255. ],
  256. "http://cacoo.com/oembed.{format}": [
  257. "^http(?:s)?://cacoo\\.com/.+$"
  258. ],
  259. "http://api.dailymile.com/oembed": [
  260. "^http(?:s)?://(?:www\\.)?dailymile\\.com/people/[^#?/]+/entries/.+$"
  261. ],
  262. "http://www.dipity.com/oembed/timeline/": [
  263. "^http(?:s)?://(?:www\\.)?dipity\\.com/timeline/.+$",
  264. "^http(?:s)?://(?:www\\.)?dipity\\.com/voaweb/.+$"
  265. ],
  266. "https://sketchfab.com/oembed": [
  267. "^http(?:s)?://sketchfab\\.com/show/.+$"
  268. ],
  269. "https://api.meetup.com/oembed": [
  270. "^http(?:s)?://(?:www\\.)?meetup\\.com/.+$",
  271. "^http(?:s)?://(?:www\\.)?meetup\\.ps/.+$"
  272. ],
  273. "https://roomshare.jp/oembed.{format}": [
  274. "^http(?:s)?://(?:www\\.)?roomshare\\.jp/(?:en/)?post/.+$"
  275. ],
  276. "http://crowdranking.com/api/oembed.{format}": [
  277. "^http(?:s)?://crowdranking\\.com/crowdrankings/.+$",
  278. "^http(?:s)?://crowdranking\\.com/rankings/.+$",
  279. "^http(?:s)?://crowdranking\\.com/topics/.+$",
  280. "^http(?:s)?://crowdranking\\.com/widgets/.+$",
  281. "^http(?:s)?://crowdranking\\.com/r/.+$"
  282. ],
  283. "http://openapi.etsy.com/svc/oembed/": [
  284. "^http(?:s)?://(?:www\\.)?etsy\\.com/listing/.+$"
  285. ],
  286. "https://audioboo.fm/publishing/oembed.{format}": [
  287. "^http(?:s)?://audioboo\\.fm/boos/.+$"
  288. ],
  289. "http://demo.clikthrough.com/services/oembed/": [
  290. "^http(?:s)?://demo\\.clikthrough\\.com/theater/video/.+$"
  291. ],
  292. "http://www.ifttt.com/oembed/": [
  293. "^http(?:s)?://ifttt\\.com/recipes/.+$"
  294. ]
  295. }
  296. # Compile endpoints into regular expression objects
  297. import re
  298. def compile_endpoints():
  299. endpoints = {}
  300. for endpoint in OEMBED_ENDPOINTS.keys():
  301. endpoint_key = endpoint.replace('{format}', 'json')
  302. endpoints[endpoint_key] = []
  303. for pattern in OEMBED_ENDPOINTS[endpoint]:
  304. endpoints[endpoint_key].append(re.compile(pattern))
  305. return endpoints
  306. OEMBED_ENDPOINTS_COMPILED = compile_endpoints()
  307. def get_oembed_provider(url):
  308. for endpoint in OEMBED_ENDPOINTS_COMPILED.keys():
  309. for pattern in OEMBED_ENDPOINTS_COMPILED[endpoint]:
  310. if re.match(pattern, url):
  311. return endpoint
  312. return