video-imports.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { VideoImportCreate } from '../../models/videos'
  2. import { makeGetRequest, makeUploadRequest } from '../requests/requests'
  3. import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
  4. function getYoutubeVideoUrl () {
  5. return 'https://www.youtube.com/watch?v=msX3jv1XdvM'
  6. }
  7. function getYoutubeHDRVideoUrl () {
  8. /**
  9. * The video is used to check format-selection correctness wrt. HDR,
  10. * which brings its own set of oddities outside of a MediaSource.
  11. * FIXME: refactor once HDR is supported at playback
  12. *
  13. * The video needs to have the following format_ids:
  14. * (which you can check by using `youtube-dl <url> -F`):
  15. * - 303 (1080p webm vp9)
  16. * - 299 (1080p mp4 avc1)
  17. * - 335 (1080p webm vp9.2 HDR)
  18. *
  19. * 15 jan. 2021: TEST VIDEO NOT CURRENTLY PROVIDING
  20. * - 400 (1080p mp4 av01)
  21. * - 315 (2160p webm vp9 HDR)
  22. * - 337 (2160p webm vp9.2 HDR)
  23. * - 401 (2160p mp4 av01 HDR)
  24. */
  25. return 'https://www.youtube.com/watch?v=MSJ25EqI19c'
  26. }
  27. function getMagnetURI () {
  28. // eslint-disable-next-line max-len
  29. return 'magnet:?xs=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Ftorrents%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.torrent&xt=urn:btih:0f498834733e8057ed5c6f2ee2b4efd8d84a76ee&dn=super+peertube2+video&tr=wss%3A%2F%2Fpeertube2.cpy.re%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube2.cpy.re%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Fwebseed%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.mp4'
  30. }
  31. function getBadVideoUrl () {
  32. return 'https://download.cpy.re/peertube/bad_video.mp4'
  33. }
  34. function getGoodVideoUrl () {
  35. return 'https://download.cpy.re/peertube/good_video.mp4'
  36. }
  37. function importVideo (
  38. url: string,
  39. token: string,
  40. attributes: VideoImportCreate & { torrentfile?: string },
  41. statusCodeExpected = HttpStatusCode.OK_200
  42. ) {
  43. const path = '/api/v1/videos/imports'
  44. let attaches: any = {}
  45. if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile }
  46. return makeUploadRequest({
  47. url,
  48. path,
  49. token,
  50. attaches,
  51. fields: attributes,
  52. statusCodeExpected
  53. })
  54. }
  55. function getMyVideoImports (url: string, token: string, sort?: string) {
  56. const path = '/api/v1/users/me/videos/imports'
  57. const query = {}
  58. if (sort) query['sort'] = sort
  59. return makeGetRequest({
  60. url,
  61. query,
  62. path,
  63. token,
  64. statusCodeExpected: HttpStatusCode.OK_200
  65. })
  66. }
  67. // ---------------------------------------------------------------------------
  68. export {
  69. getBadVideoUrl,
  70. getYoutubeVideoUrl,
  71. getYoutubeHDRVideoUrl,
  72. importVideo,
  73. getMagnetURI,
  74. getMyVideoImports,
  75. getGoodVideoUrl
  76. }