Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

75 lines
1.6KB

  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. )
  6. //display vimeo video in biukop brand
  7. const videoPrefix = "/v/"
  8. type vimeoPlayer struct {
  9. VideoId string
  10. playsinline int
  11. autoplay int
  12. autopause int
  13. loop int
  14. background int
  15. muted int
  16. Title string
  17. }
  18. func videoMain(w http.ResponseWriter, r *http.Request) {
  19. videoVimeo(w, r)
  20. }
  21. func videoVimeo(w http.ResponseWriter, r *http.Request) {
  22. vimeo := getVimeoParams(r)
  23. pattern := `
  24. <html>
  25. <title> %s </title>
  26. <body style="margin:0px">
  27. <style> iframe {width: 100vw; height: 100vh; overflow:hidden;} </style>
  28. <iframe src="%s"
  29. scrolling="no" frameborder="0"
  30. style="width: 100vw; height: 100vh; overflow:hidden;"
  31. allow="autoplay; fullscreen"
  32. webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
  33. </body>
  34. </html>`
  35. output := fmt.Sprintf(pattern, vimeo.Title, vimeo.getUrl())
  36. fmt.Fprintf(w, output)
  37. }
  38. func getVimeoParams(r *http.Request) (ret vimeoPlayer) {
  39. prefix := videoPrefix + "v/"
  40. ret.VideoId = r.URL.Path[len(prefix):]
  41. ret.Title = "Video"
  42. ret.autopause = 0
  43. ret.autoplay = 1
  44. ret.playsinline = 0
  45. ret.loop = 1
  46. ret.background = 0
  47. ret.muted = 0
  48. if r.URL.Path[:len(prefix)] == videoPrefix+"b/" {
  49. ret.playsinline = 1
  50. ret.background = 1
  51. ret.muted = 1 // autoplay video must be muted.
  52. }
  53. return
  54. }
  55. func (m *vimeoPlayer) getUrl() (ret string) {
  56. ret = fmt.Sprintf(
  57. "https://player.vimeo.com/video/%s?playsinline=%d&autoplay=%d&autopause=%d&loop=%d&background=%d&muted=%d",
  58. m.VideoId, m.playsinline, m.autoplay, m.autopause, m.loop, m.background, m.muted)
  59. return
  60. }