diff options
-rwxr-xr-x | scripts/update-host.ts | 6 | ||||
-rw-r--r-- | server/controllers/api/videos/update.ts | 12 | ||||
-rw-r--r-- | server/helpers/webtorrent.ts | 15 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/move-to-object-storage.ts | 4 | ||||
-rw-r--r-- | server/models/video/video-playlist-element.ts | 2 | ||||
-rw-r--r-- | server/models/video/video.ts | 15 | ||||
-rw-r--r-- | shared/extra-utils/videos/videos.ts | 1 |
7 files changed, 42 insertions, 13 deletions
diff --git a/scripts/update-host.ts b/scripts/update-host.ts index c6eb9d533..f752082fd 100755 --- a/scripts/update-host.ts +++ b/scripts/update-host.ts | |||
@@ -17,7 +17,7 @@ import { VideoCommentModel } from '../server/models/video/video-comment' | |||
17 | import { AccountModel } from '../server/models/account/account' | 17 | import { AccountModel } from '../server/models/account/account' |
18 | import { VideoChannelModel } from '../server/models/video/video-channel' | 18 | import { VideoChannelModel } from '../server/models/video/video-channel' |
19 | import { initDatabaseModels } from '../server/initializers/database' | 19 | import { initDatabaseModels } from '../server/initializers/database' |
20 | import { updateTorrentUrls } from '@server/helpers/webtorrent' | 20 | import { updateTorrentMetadata } from '@server/helpers/webtorrent' |
21 | import { getServerActor } from '@server/models/application/application' | 21 | import { getServerActor } from '@server/models/application/application' |
22 | 22 | ||
23 | run() | 23 | run() |
@@ -126,7 +126,7 @@ async function run () { | |||
126 | 126 | ||
127 | for (const file of video.VideoFiles) { | 127 | for (const file of video.VideoFiles) { |
128 | console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid) | 128 | console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid) |
129 | await updateTorrentUrls(video, file) | 129 | await updateTorrentMetadata(video, file) |
130 | 130 | ||
131 | await file.save() | 131 | await file.save() |
132 | } | 132 | } |
@@ -135,7 +135,7 @@ async function run () { | |||
135 | for (const file of (playlist?.VideoFiles || [])) { | 135 | for (const file of (playlist?.VideoFiles || [])) { |
136 | console.log('Updating fragmented torrent file %s of video %s.', file.resolution, video.uuid) | 136 | console.log('Updating fragmented torrent file %s of video %s.', file.resolution, video.uuid) |
137 | 137 | ||
138 | await updateTorrentUrls(video, file) | 138 | await updateTorrentMetadata(video, file) |
139 | 139 | ||
140 | await file.save() | 140 | await file.save() |
141 | } | 141 | } |
diff --git a/server/controllers/api/videos/update.ts b/server/controllers/api/videos/update.ts index 3fcff3e86..6f14a6788 100644 --- a/server/controllers/api/videos/update.ts +++ b/server/controllers/api/videos/update.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { Transaction } from 'sequelize/types' | 2 | import { Transaction } from 'sequelize/types' |
3 | import { updateTorrentMetadata } from '@server/helpers/webtorrent' | ||
3 | import { changeVideoChannelShare } from '@server/lib/activitypub/share' | 4 | import { changeVideoChannelShare } from '@server/lib/activitypub/share' |
4 | import { buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' | 5 | import { buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' |
5 | import { openapiOperationDoc } from '@server/middlewares/doc' | 6 | import { openapiOperationDoc } from '@server/middlewares/doc' |
@@ -149,9 +150,8 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
149 | return videoInstanceUpdated | 150 | return videoInstanceUpdated |
150 | }) | 151 | }) |
151 | 152 | ||
152 | if (wasConfidentialVideo) { | 153 | if (videoInfoToUpdate.name) await updateTorrentsMetadata(videoInstanceUpdated) |
153 | Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated) | 154 | if (wasConfidentialVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated) |
154 | } | ||
155 | 155 | ||
156 | Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body, req, res }) | 156 | Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body, req, res }) |
157 | } catch (err) { | 157 | } catch (err) { |
@@ -199,3 +199,9 @@ function updateSchedule (videoInstance: MVideoFullLight, videoInfoToUpdate: Vide | |||
199 | return ScheduleVideoUpdateModel.deleteByVideoId(videoInstance.id, transaction) | 199 | return ScheduleVideoUpdateModel.deleteByVideoId(videoInstance.id, transaction) |
200 | } | 200 | } |
201 | } | 201 | } |
202 | |||
203 | async function updateTorrentsMetadata (video: MVideoFullLight) { | ||
204 | for (const file of video.getAllFiles()) { | ||
205 | await updateTorrentMetadata(video, file) | ||
206 | } | ||
207 | } | ||
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts index c75c058e4..b350c9718 100644 --- a/server/helpers/webtorrent.ts +++ b/server/helpers/webtorrent.ts | |||
@@ -94,7 +94,7 @@ function createTorrentAndSetInfoHash (videoOrPlaylist: MVideo | MStreamingPlayli | |||
94 | 94 | ||
95 | const options = { | 95 | const options = { |
96 | // Keep the extname, it's used by the client to stream the file inside a web browser | 96 | // Keep the extname, it's used by the client to stream the file inside a web browser |
97 | name: `${video.name} ${videoFile.resolution}p${videoFile.extname}`, | 97 | name: buildInfoName(video, videoFile), |
98 | createdBy: 'PeerTube', | 98 | createdBy: 'PeerTube', |
99 | announceList: buildAnnounceList(), | 99 | announceList: buildAnnounceList(), |
100 | urlList: buildUrlList(video, videoFile) | 100 | urlList: buildUrlList(video, videoFile) |
@@ -120,7 +120,7 @@ function createTorrentAndSetInfoHash (videoOrPlaylist: MVideo | MStreamingPlayli | |||
120 | }) | 120 | }) |
121 | } | 121 | } |
122 | 122 | ||
123 | async function updateTorrentUrls (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { | 123 | async function updateTorrentMetadata (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { |
124 | const video = extractVideo(videoOrPlaylist) | 124 | const video = extractVideo(videoOrPlaylist) |
125 | 125 | ||
126 | const oldTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename) | 126 | const oldTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename) |
@@ -133,10 +133,13 @@ async function updateTorrentUrls (videoOrPlaylist: MVideo | MStreamingPlaylistVi | |||
133 | 133 | ||
134 | decoded['url-list'] = buildUrlList(video, videoFile) | 134 | decoded['url-list'] = buildUrlList(video, videoFile) |
135 | 135 | ||
136 | decoded.info.name = buildInfoName(video, videoFile) | ||
137 | decoded['creation date'] = Math.ceil(Date.now() / 1000) | ||
138 | |||
136 | const newTorrentFilename = generateTorrentFileName(videoOrPlaylist, videoFile.resolution) | 139 | const newTorrentFilename = generateTorrentFileName(videoOrPlaylist, videoFile.resolution) |
137 | const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, newTorrentFilename) | 140 | const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, newTorrentFilename) |
138 | 141 | ||
139 | logger.info('Updating torrent URLs %s -> %s.', oldTorrentPath, newTorrentPath) | 142 | logger.info('Updating torrent metadata %s -> %s.', oldTorrentPath, newTorrentPath) |
140 | 143 | ||
141 | await writeFile(newTorrentPath, encode(decoded)) | 144 | await writeFile(newTorrentPath, encode(decoded)) |
142 | await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)) | 145 | await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)) |
@@ -171,7 +174,7 @@ function generateMagnetUri ( | |||
171 | 174 | ||
172 | export { | 175 | export { |
173 | createTorrentPromise, | 176 | createTorrentPromise, |
174 | updateTorrentUrls, | 177 | updateTorrentMetadata, |
175 | createTorrentAndSetInfoHash, | 178 | createTorrentAndSetInfoHash, |
176 | generateMagnetUri, | 179 | generateMagnetUri, |
177 | downloadWebTorrentVideo | 180 | downloadWebTorrentVideo |
@@ -226,3 +229,7 @@ function buildAnnounceList () { | |||
226 | function buildUrlList (video: MVideo, videoFile: MVideoFile) { | 229 | function buildUrlList (video: MVideo, videoFile: MVideoFile) { |
227 | return [ videoFile.getFileUrl(video) ] | 230 | return [ videoFile.getFileUrl(video) ] |
228 | } | 231 | } |
232 | |||
233 | function buildInfoName (video: MVideo, videoFile: MVideoFile) { | ||
234 | return `${video.name} ${videoFile.resolution}p${videoFile.extname}` | ||
235 | } | ||
diff --git a/server/lib/job-queue/handlers/move-to-object-storage.ts b/server/lib/job-queue/handlers/move-to-object-storage.ts index 54a7c566b..b5eea0184 100644 --- a/server/lib/job-queue/handlers/move-to-object-storage.ts +++ b/server/lib/job-queue/handlers/move-to-object-storage.ts | |||
@@ -2,7 +2,7 @@ import { Job } from 'bull' | |||
2 | import { remove } from 'fs-extra' | 2 | import { remove } from 'fs-extra' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { logger } from '@server/helpers/logger' | 4 | import { logger } from '@server/helpers/logger' |
5 | import { updateTorrentUrls } from '@server/helpers/webtorrent' | 5 | import { updateTorrentMetadata } from '@server/helpers/webtorrent' |
6 | import { CONFIG } from '@server/initializers/config' | 6 | import { CONFIG } from '@server/initializers/config' |
7 | import { P2P_MEDIA_LOADER_PEER_VERSION } from '@server/initializers/constants' | 7 | import { P2P_MEDIA_LOADER_PEER_VERSION } from '@server/initializers/constants' |
8 | import { storeHLSFile, storeWebTorrentFile } from '@server/lib/object-storage' | 8 | import { storeHLSFile, storeWebTorrentFile } from '@server/lib/object-storage' |
@@ -113,7 +113,7 @@ async function onFileMoved (options: { | |||
113 | file.fileUrl = fileUrl | 113 | file.fileUrl = fileUrl |
114 | file.storage = VideoStorage.OBJECT_STORAGE | 114 | file.storage = VideoStorage.OBJECT_STORAGE |
115 | 115 | ||
116 | await updateTorrentUrls(videoOrPlaylist, file) | 116 | await updateTorrentMetadata(videoOrPlaylist, file) |
117 | await file.save() | 117 | await file.save() |
118 | 118 | ||
119 | logger.debug('Removing %s because it\'s now on object storage', oldPath) | 119 | logger.debug('Removing %s because it\'s now on object storage', oldPath) |
diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts index 82c832188..a87b2bcae 100644 --- a/server/models/video/video-playlist-element.ts +++ b/server/models/video/video-playlist-element.ts | |||
@@ -276,7 +276,7 @@ export class VideoPlaylistElementModel extends Model<Partial<AttributesOnly<Vide | |||
276 | } | 276 | } |
277 | 277 | ||
278 | const positionQuery = Sequelize.literal(`${newPosition} + "position" - ${firstPosition}`) | 278 | const positionQuery = Sequelize.literal(`${newPosition} + "position" - ${firstPosition}`) |
279 | return VideoPlaylistElementModel.update({ position: positionQuery as any }, query) | 279 | return VideoPlaylistElementModel.update({ position: positionQuery }, query) |
280 | } | 280 | } |
281 | 281 | ||
282 | static increasePositionOf ( | 282 | static increasePositionOf ( |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 1050463d2..801e23f55 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -1539,6 +1539,21 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1539 | return this.VideoChannel.Account.Actor.Server?.isBlocked() || this.VideoChannel.Account.isBlocked() | 1539 | return this.VideoChannel.Account.Actor.Server?.isBlocked() || this.VideoChannel.Account.isBlocked() |
1540 | } | 1540 | } |
1541 | 1541 | ||
1542 | getAllFiles () { | ||
1543 | let files: MVideoFile[] = [] | ||
1544 | |||
1545 | if (Array.isArray(this.VideoFiles)) { | ||
1546 | files = files.concat(this.VideoFiles) | ||
1547 | } | ||
1548 | |||
1549 | const hls = this.getHLSPlaylist() | ||
1550 | if (hls) { | ||
1551 | files = files.concat(hls.VideoFiles) | ||
1552 | } | ||
1553 | |||
1554 | return files | ||
1555 | } | ||
1556 | |||
1542 | getQualityFileBy<T extends MVideoWithFile> (this: T, fun: (files: MVideoFile[], it: (file: MVideoFile) => number) => MVideoFile) { | 1557 | getQualityFileBy<T extends MVideoWithFile> (this: T, fun: (files: MVideoFile[], it: (file: MVideoFile) => number) => MVideoFile) { |
1543 | // We first transcode to WebTorrent format, so try this array first | 1558 | // We first transcode to WebTorrent format, so try this array first |
1544 | if (Array.isArray(this.VideoFiles) && this.VideoFiles.length !== 0) { | 1559 | if (Array.isArray(this.VideoFiles) && this.VideoFiles.length !== 0) { |
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts index 4d2784dde..c05c2be6c 100644 --- a/shared/extra-utils/videos/videos.ts +++ b/shared/extra-utils/videos/videos.ts | |||
@@ -217,6 +217,7 @@ async function completeVideoCheck ( | |||
217 | expect(torrent.files).to.be.an('array') | 217 | expect(torrent.files).to.be.an('array') |
218 | expect(torrent.files.length).to.equal(1) | 218 | expect(torrent.files.length).to.equal(1) |
219 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | 219 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') |
220 | expect(torrent.files[0].name).to.equal(`${videoDetails.name} ${file.resolution.id}p${extension}`) | ||
220 | } | 221 | } |
221 | 222 | ||
222 | expect(videoDetails.thumbnailPath).to.exist | 223 | expect(videoDetails.thumbnailPath).to.exist |