+
+ try {
+ await generateThumbnailFromUrl(options.video, options.videoObject.icon)
+ } catch (err) {
+ logger.warn('Cannot generate thumbnail of %s.', options.videoObject.id, { err })
+ }
+}
+
+async function refreshVideoIfNeeded (options: {
+ video: VideoModel,
+ fetchedType: VideoFetchByUrlType,
+ syncParam: SyncParam
+}): Promise<VideoModel> {
+ if (!options.video.isOutdated()) return options.video
+
+ // We need more attributes if the argument video was fetched with not enough joints
+ const video = options.fetchedType === 'all' ? options.video : await VideoModel.loadByUrlAndPopulateAccount(options.video.url)
+
+ try {
+ const { response, videoObject } = await fetchRemoteVideo(video.url)
+ if (response.statusCode === 404) {
+ logger.info('Cannot refresh remote video %s: video does not exist anymore. Deleting it.', video.url)
+
+ // Video does not exist anymore
+ await video.destroy()
+ return undefined
+ }
+
+ if (videoObject === undefined) {
+ logger.warn('Cannot refresh remote video %s: invalid body.', video.url)
+
+ await video.setAsRefreshed()
+ return video
+ }
+
+ const channelActor = await getOrCreateVideoChannelFromVideoObject(videoObject)
+ const account = await AccountModel.load(channelActor.VideoChannel.accountId)
+
+ const updateOptions = {
+ video,
+ videoObject,
+ account,
+ channel: channelActor.VideoChannel
+ }
+ await retryTransactionWrapper(updateVideoFromAP, updateOptions)
+ await syncVideoExternalAttributes(video, videoObject, options.syncParam)
+
+ return video
+ } catch (err) {
+ logger.warn('Cannot refresh video %s.', options.video.url, { err })
+
+ // Don't refresh in loop
+ await video.setAsRefreshed()
+ return video
+ }