diff options
author | Chocobozzz <me@florianbigard.com> | 2022-02-11 10:51:33 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-02-28 10:42:19 +0100 |
commit | c729caf6cc34630877a0e5a1bda1719384cd0c8a (patch) | |
tree | 1d2e13722e518c73d2c9e6f0969615e29d51cf8c /server/helpers/webtorrent.ts | |
parent | a24bf4dc659cebb65d887862bf21d7a35e9ec791 (diff) | |
download | PeerTube-c729caf6cc34630877a0e5a1bda1719384cd0c8a.tar.gz PeerTube-c729caf6cc34630877a0e5a1bda1719384cd0c8a.tar.zst PeerTube-c729caf6cc34630877a0e5a1bda1719384cd0c8a.zip |
Add basic video editor support
Diffstat (limited to 'server/helpers/webtorrent.ts')
-rw-r--r-- | server/helpers/webtorrent.ts | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts index 68d532c48..88bdb16b6 100644 --- a/server/helpers/webtorrent.ts +++ b/server/helpers/webtorrent.ts | |||
@@ -91,6 +91,16 @@ async function downloadWebTorrentVideo (target: { uri: string, torrentName?: str | |||
91 | } | 91 | } |
92 | 92 | ||
93 | function createTorrentAndSetInfoHash (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { | 93 | function createTorrentAndSetInfoHash (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { |
94 | return VideoPathManager.Instance.makeAvailableVideoFile(videoFile.withVideoOrPlaylist(videoOrPlaylist), videoPath => { | ||
95 | return createTorrentAndSetInfoHashFromPath(videoOrPlaylist, videoFile, videoPath) | ||
96 | }) | ||
97 | } | ||
98 | |||
99 | async function createTorrentAndSetInfoHashFromPath ( | ||
100 | videoOrPlaylist: MVideo | MStreamingPlaylistVideo, | ||
101 | videoFile: MVideoFile, | ||
102 | filePath: string | ||
103 | ) { | ||
94 | const video = extractVideo(videoOrPlaylist) | 104 | const video = extractVideo(videoOrPlaylist) |
95 | 105 | ||
96 | const options = { | 106 | const options = { |
@@ -101,24 +111,22 @@ function createTorrentAndSetInfoHash (videoOrPlaylist: MVideo | MStreamingPlayli | |||
101 | urlList: buildUrlList(video, videoFile) | 111 | urlList: buildUrlList(video, videoFile) |
102 | } | 112 | } |
103 | 113 | ||
104 | return VideoPathManager.Instance.makeAvailableVideoFile(videoFile.withVideoOrPlaylist(videoOrPlaylist), async videoPath => { | 114 | const torrentContent = await createTorrentPromise(filePath, options) |
105 | const torrentContent = await createTorrentPromise(videoPath, options) | ||
106 | 115 | ||
107 | const torrentFilename = generateTorrentFileName(videoOrPlaylist, videoFile.resolution) | 116 | const torrentFilename = generateTorrentFileName(videoOrPlaylist, videoFile.resolution) |
108 | const torrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, torrentFilename) | 117 | const torrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, torrentFilename) |
109 | logger.info('Creating torrent %s.', torrentPath) | 118 | logger.info('Creating torrent %s.', torrentPath) |
110 | 119 | ||
111 | await writeFile(torrentPath, torrentContent) | 120 | await writeFile(torrentPath, torrentContent) |
112 | 121 | ||
113 | // Remove old torrent file if it existed | 122 | // Remove old torrent file if it existed |
114 | if (videoFile.hasTorrent()) { | 123 | if (videoFile.hasTorrent()) { |
115 | await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)) | 124 | await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)) |
116 | } | 125 | } |
117 | 126 | ||
118 | const parsedTorrent = parseTorrent(torrentContent) | 127 | const parsedTorrent = parseTorrent(torrentContent) |
119 | videoFile.infoHash = parsedTorrent.infoHash | 128 | videoFile.infoHash = parsedTorrent.infoHash |
120 | videoFile.torrentFilename = torrentFilename | 129 | videoFile.torrentFilename = torrentFilename |
121 | }) | ||
122 | } | 130 | } |
123 | 131 | ||
124 | async function updateTorrentMetadata (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { | 132 | async function updateTorrentMetadata (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { |
@@ -177,7 +185,10 @@ function generateMagnetUri ( | |||
177 | export { | 185 | export { |
178 | createTorrentPromise, | 186 | createTorrentPromise, |
179 | updateTorrentMetadata, | 187 | updateTorrentMetadata, |
188 | |||
180 | createTorrentAndSetInfoHash, | 189 | createTorrentAndSetInfoHash, |
190 | createTorrentAndSetInfoHashFromPath, | ||
191 | |||
181 | generateMagnetUri, | 192 | generateMagnetUri, |
182 | downloadWebTorrentVideo | 193 | downloadWebTorrentVideo |
183 | } | 194 | } |