PeerTube icon indicating copy to clipboard operation
PeerTube copied to clipboard

When `action:api.video.updated` is triggered, `videoFiles` might be empty.

Open lutangar opened this issue 3 years ago • 1 comments

Describe the current behavior

When action:api.video.updated is triggered at video creation, videoFiles might be empty.

It does work as expected when you actually edit the video.

Steps to reproduce

When action:api.video.updated hook is triggered, then I attempt to find a video file via peerTubeVideosHelpers.getFiles method, and hls.videoFiles is sometimes empty.

const videoFiles = await peerTubeVideosHelpers
  .getFiles(id)
  .then(({ hls: { videoFiles } }) => videoFiles.sort(({ size: sizeA }, { size: sizeB }) => sizeA - sizeB));

if (videoFiles.length === 0) {
  this.logger.info(`No valid video file found for video "${id}", skipping.`);
  return;
}

From what I understand the action:api.video.updated event is also triggered video creation and this seems to happen when the PeerTube transcoding is still ongoing.

On video edition, there's no such issue, the video file is always found.

Describe the expected behavior

When action:api.video.updated hook is triggered, hls.videoFiles should always be populated.

Additional information

Maybe action:api.video.updated should simply not be triggered at video creation time, but if it's the case, another reliable event should exists to get the video file reliabily.

lutangar avatar Aug 30 '22 07:08 lutangar

Possibly related to lower-level task queue bug #5213

emansom avatar Aug 31 '22 10:08 emansom

Hello,

action:api.video.updated is not triggered when you upload the file. But the web interface starts to upload the file in private, and then update the video when the user submits the second form.

If hls.videoFiles is empty it means HLS transcoded has not finished or is disabled. Then you should find files in webtorrent.videoFiles

Chocobozzz avatar Sep 16 '22 07:09 Chocobozzz

Sorry for the late reply and thanks for your feedback.

If it's the expected behaviour, from my point of view the following issue still stands :

another reliable event should exists to get the video file reliabily.

Then would it makes sense to add another hook when the HLS transcoding is completed ? Maybe something like action:api.video.transcoding_completed ? Meaning when this event occurs hls.videoFiles are available.

I can create another issue as a feature request if needed.

lutangar avatar Oct 10 '22 14:10 lutangar

I can create another issue as a feature request if needed.

This hook is a good idea. Yes, please create a dedicated issue I would still have questions like if you need a hook when every transcoding job completes or if you need a "final" hook when all transcoding jobs finished.

Chocobozzz avatar Oct 10 '22 14:10 Chocobozzz

If hls.videoFiles is empty it means HLS transcoded has not finished or is disabled. Then you should find files in webtorrent.videoFiles

After some more tests, I'm able to say that "sometimes" both videoFiles arrays are empty. This is pretty random but happens 1 to 2 times on ~10 attempts which is quite often I would say.

Lately, it happens when uploading a video from a URL (ex: from youtube). But I think it may also happens for a classic video upload.

So I suppose this issue could be reopen.

lutangar avatar Oct 13 '22 13:10 lutangar

Lately, it happens when uploading a video from a URL (ex: from youtube).

I'm not sure we have an action hook to be notified of an imported video :thinking:

Chocobozzz avatar Oct 14 '22 07:10 Chocobozzz

Well a video file is available half the time after the same hook is triggered action:api.video.updated even for imported video.

lutangar avatar Oct 15 '22 14:10 lutangar

Lately, it happens when uploading a video from a URL (ex: from youtube).

I can confirm that when uploading a video from a Youtube link, if the processing of the video isn't finished there are no videoFiles available. Is that expected ? Couldn't we have access to a webtorrent.videoFiles or equivalent ?

lutangar avatar Oct 18 '22 14:10 lutangar

I can confirm that when uploading a video from a Youtube link, if the processing of the video isn't finished there are no videoFiles available. Is that expected ?

If you talk about action:api.video.updated yes it is, the video metadata can be updated even if the video is not yet imported by peertube. If the video is not imported there is no webtorrent.videoFiles.

We need to add an action hook so you can add an handler when an import finished. With this hook + action:api.video.uploaded it should correctly fit your use case

Chocobozzz avatar Oct 24 '22 13:10 Chocobozzz

Superceded by #5343

lutangar avatar Apr 07 '23 14:04 lutangar