video-imports.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /* tslint:disable:no-unused-expression */
  2. import * as chai from 'chai'
  3. import 'mocha'
  4. import { VideoDetails, VideoImport, VideoPrivacy } from '../../../../shared/models/videos'
  5. import {
  6. doubleFollow,
  7. flushAndRunMultipleServers,
  8. getMyUserInformation,
  9. getMyVideos,
  10. getVideo,
  11. getVideosList,
  12. immutableAssign,
  13. killallServers,
  14. ServerInfo,
  15. setAccessTokensToServers
  16. } from '../../../../shared/extra-utils'
  17. import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
  18. import { getMagnetURI, getYoutubeVideoUrl, importVideo, getMyVideoImports } from '../../../../shared/extra-utils/videos/video-imports'
  19. const expect = chai.expect
  20. describe('Test video imports', function () {
  21. let servers: ServerInfo[] = []
  22. let channelIdServer1: number
  23. let channelIdServer2: number
  24. async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) {
  25. const resHttp = await getVideo(url, idHttp)
  26. const videoHttp: VideoDetails = resHttp.body
  27. expect(videoHttp.name).to.equal('small video - youtube')
  28. expect(videoHttp.category.label).to.equal('News & Politics')
  29. expect(videoHttp.licence.label).to.equal('Attribution')
  30. expect(videoHttp.language.label).to.equal('Unknown')
  31. expect(videoHttp.nsfw).to.be.false
  32. expect(videoHttp.description).to.equal('this is a super description')
  33. expect(videoHttp.tags).to.deep.equal([ 'tag1', 'tag2' ])
  34. expect(videoHttp.files).to.have.lengthOf(1)
  35. const originallyPublishedAt = new Date(videoHttp.originallyPublishedAt)
  36. expect(originallyPublishedAt.getDate()).to.equal(14)
  37. expect(originallyPublishedAt.getMonth()).to.equal(0)
  38. expect(originallyPublishedAt.getFullYear()).to.equal(2019)
  39. const resMagnet = await getVideo(url, idMagnet)
  40. const videoMagnet: VideoDetails = resMagnet.body
  41. const resTorrent = await getVideo(url, idTorrent)
  42. const videoTorrent: VideoDetails = resTorrent.body
  43. for (const video of [ videoMagnet, videoTorrent ]) {
  44. expect(video.category.label).to.equal('Misc')
  45. expect(video.licence.label).to.equal('Unknown')
  46. expect(video.language.label).to.equal('Unknown')
  47. expect(video.nsfw).to.be.false
  48. expect(video.description).to.equal('this is a super torrent description')
  49. expect(video.tags).to.deep.equal([ 'tag_torrent1', 'tag_torrent2' ])
  50. expect(video.files).to.have.lengthOf(1)
  51. }
  52. expect(videoTorrent.name).to.contain('你好 世界 720p.mp4')
  53. expect(videoMagnet.name).to.contain('super peertube2 video')
  54. }
  55. async function checkVideoServer2 (url: string, id: number | string) {
  56. const res = await getVideo(url, id)
  57. const video = res.body
  58. expect(video.name).to.equal('my super name')
  59. expect(video.category.label).to.equal('Entertainment')
  60. expect(video.licence.label).to.equal('Public Domain Dedication')
  61. expect(video.language.label).to.equal('English')
  62. expect(video.nsfw).to.be.false
  63. expect(video.description).to.equal('my super description')
  64. expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ])
  65. expect(video.files).to.have.lengthOf(1)
  66. }
  67. before(async function () {
  68. this.timeout(30000)
  69. // Run servers
  70. servers = await flushAndRunMultipleServers(2)
  71. await setAccessTokensToServers(servers)
  72. {
  73. const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
  74. channelIdServer1 = res.body.videoChannels[ 0 ].id
  75. }
  76. {
  77. const res = await getMyUserInformation(servers[1].url, servers[1].accessToken)
  78. channelIdServer2 = res.body.videoChannels[ 0 ].id
  79. }
  80. await doubleFollow(servers[0], servers[1])
  81. })
  82. it('Should import videos on server 1', async function () {
  83. this.timeout(60000)
  84. const baseAttributes = {
  85. channelId: channelIdServer1,
  86. privacy: VideoPrivacy.PUBLIC
  87. }
  88. {
  89. const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })
  90. const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
  91. expect(res.body.video.name).to.equal('small video - youtube')
  92. }
  93. {
  94. const attributes = immutableAssign(baseAttributes, {
  95. magnetUri: getMagnetURI(),
  96. description: 'this is a super torrent description',
  97. tags: [ 'tag_torrent1', 'tag_torrent2' ]
  98. })
  99. const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
  100. expect(res.body.video.name).to.equal('super peertube2 video')
  101. }
  102. {
  103. const attributes = immutableAssign(baseAttributes, {
  104. torrentfile: 'video-720p.torrent',
  105. description: 'this is a super torrent description',
  106. tags: [ 'tag_torrent1', 'tag_torrent2' ]
  107. })
  108. const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
  109. expect(res.body.video.name).to.equal('你好 世界 720p.mp4')
  110. }
  111. })
  112. it('Should list the videos to import in my videos on server 1', async function () {
  113. const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt')
  114. expect(res.body.total).to.equal(3)
  115. const videos = res.body.data
  116. expect(videos).to.have.lengthOf(3)
  117. expect(videos[0].name).to.equal('small video - youtube')
  118. expect(videos[1].name).to.equal('super peertube2 video')
  119. expect(videos[2].name).to.equal('你好 世界 720p.mp4')
  120. })
  121. it('Should list the videos to import in my imports on server 1', async function () {
  122. const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt')
  123. expect(res.body.total).to.equal(3)
  124. const videoImports: VideoImport[] = res.body.data
  125. expect(videoImports).to.have.lengthOf(3)
  126. expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl())
  127. expect(videoImports[2].magnetUri).to.be.null
  128. expect(videoImports[2].torrentName).to.be.null
  129. expect(videoImports[2].video.name).to.equal('small video - youtube')
  130. expect(videoImports[1].targetUrl).to.be.null
  131. expect(videoImports[1].magnetUri).to.equal(getMagnetURI())
  132. expect(videoImports[1].torrentName).to.be.null
  133. expect(videoImports[1].video.name).to.equal('super peertube2 video')
  134. expect(videoImports[0].targetUrl).to.be.null
  135. expect(videoImports[0].magnetUri).to.be.null
  136. expect(videoImports[0].torrentName).to.equal('video-720p.torrent')
  137. expect(videoImports[0].video.name).to.equal('你好 世界 720p.mp4')
  138. })
  139. it('Should have the video listed on the two instances', async function () {
  140. this.timeout(120000)
  141. await waitJobs(servers)
  142. for (const server of servers) {
  143. const res = await getVideosList(server.url)
  144. expect(res.body.total).to.equal(3)
  145. expect(res.body.data).to.have.lengthOf(3)
  146. const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data
  147. await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
  148. }
  149. })
  150. it('Should import a video on server 2 with some fields', async function () {
  151. this.timeout(60000)
  152. const attributes = {
  153. targetUrl: getYoutubeVideoUrl(),
  154. channelId: channelIdServer2,
  155. privacy: VideoPrivacy.PUBLIC,
  156. category: 10,
  157. licence: 7,
  158. language: 'en',
  159. name: 'my super name',
  160. description: 'my super description',
  161. tags: [ 'supertag1', 'supertag2' ]
  162. }
  163. const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
  164. expect(res.body.video.name).to.equal('my super name')
  165. })
  166. it('Should have the videos listed on the two instances', async function () {
  167. this.timeout(120000)
  168. await waitJobs(servers)
  169. for (const server of servers) {
  170. const res = await getVideosList(server.url)
  171. expect(res.body.total).to.equal(4)
  172. expect(res.body.data).to.have.lengthOf(4)
  173. await checkVideoServer2(server.url, res.body.data[0].uuid)
  174. const [ ,videoHttp, videoMagnet, videoTorrent ] = res.body.data
  175. await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
  176. }
  177. })
  178. it('Should import a video that will be transcoded', async function () {
  179. this.timeout(120000)
  180. const attributes = {
  181. name: 'transcoded video',
  182. magnetUri: getMagnetURI(),
  183. channelId: channelIdServer2,
  184. privacy: VideoPrivacy.PUBLIC
  185. }
  186. const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
  187. const videoUUID = res.body.video.uuid
  188. await waitJobs(servers)
  189. for (const server of servers) {
  190. const res = await getVideo(server.url, videoUUID)
  191. const video: VideoDetails = res.body
  192. expect(video.name).to.equal('transcoded video')
  193. expect(video.files).to.have.lengthOf(4)
  194. }
  195. })
  196. after(function () {
  197. killallServers(servers)
  198. })
  199. })