+import { doRequest, doRequestAndSaveToFile } from '../helpers/requests'
+import { generateRandomString } from '../helpers/utils'
+import { flatten, uniq } from 'lodash'
+import { VideoFileModel } from '../models/video/video-file'
+import { CONFIG } from '../initializers/config'
+import { sequelizeTypescript } from '../initializers/database'
+import { MVideoWithFile } from '@server/typings/models'
+
+async function updateStreamingPlaylistsInfohashesIfNeeded () {
+ const playlistsToUpdate = await VideoStreamingPlaylistModel.listByIncorrectPeerVersion()
+
+ // Use separate SQL queries, because we could have many videos to update
+ for (const playlist of playlistsToUpdate) {
+ await sequelizeTypescript.transaction(async t => {
+ const videoFiles = await VideoFileModel.listByStreamingPlaylist(playlist.id, t)
+
+ playlist.p2pMediaLoaderInfohashes = VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlist.playlistUrl, videoFiles)
+ playlist.p2pMediaLoaderPeerVersion = P2P_MEDIA_LOADER_PEER_VERSION
+ await playlist.save({ transaction: t })
+ })
+ }
+}