Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Advanced Paste] Add paste actions to allow transcoding of media files #37188

Open
wants to merge 94 commits into
base: main
Choose a base branch
from

Conversation

drawbyperpetual
Copy link
Collaborator

Summary of the Pull Request

See linked issue for more information.

PR Checklist

Detailed Description of the Pull Request / Additional comments

A CancellationToken is now propagated to all leaf paste actions to allow for cancellation, as is an IProgress<double> for progress reporting.

Validation Steps Performed

  • Tested new functionality
  • Tested existing Advanced Paste functionality

@crutkas
Copy link
Member

crutkas commented Feb 6, 2025

This is going to be so 🔥

@crutkas crutkas added the Needs-Review This Pull Request awaits the review of a maintainer. label Feb 19, 2025
Copy link
Collaborator

@snickler snickler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged the latest main into this branch so we can see the CI kick off properly, but it LGTM! Worked perfectly with transcoding a few mp4 videos, a few AVI files, transcoding a video to mp3, converting files on my QNAP, and didn't crash when I tried to feed it something invalid. Awesome job @drawbyperpetual!

@shuaiyuanxx
Copy link
Contributor

Everything else looks great! This is a fantastic PR—really appreciate your contribution. ❤️
Maybe we can consider adding support for more format conversions in the future.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 24 out of 39 changed files in this pull request and generated 1 comment.

Files not reviewed (15)
  • src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Controls/AnimatedContentControl/AnimatedContentControl.xaml: Language not supported
  • src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Controls/PromptBox.xaml: Language not supported
  • src/modules/AdvancedPaste/AdvancedPaste.UnitTests/Mocks/NoOpKernelQueryCacheService.cs: Evaluated as low risk
  • src/modules/AdvancedPaste/AdvancedPaste/Helpers/UserSettings.cs: Evaluated as low risk
  • src/modules/AdvancedPaste/AdvancedPaste.UnitTests/ServicesTests/AIServiceBatchIntegrationTests.cs: Evaluated as low risk
  • src/modules/AdvancedPaste/AdvancedPaste/Helpers/TransformHelpers.cs: Evaluated as low risk
  • src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/Controls/PromptBox.xaml.cs: Evaluated as low risk
  • src/modules/AdvancedPaste/AdvancedPaste.UnitTests/ServicesTests/KernelServiceIntegrationTests.cs: Evaluated as low risk
  • src/modules/AdvancedPaste/AdvancedPaste/Helpers/OcrHelpers.cs: Evaluated as low risk
  • src/modules/AdvancedPaste/AdvancedPaste/Helpers/KernelExtensions.cs: Evaluated as low risk
  • src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/MainWindow.xaml.cs: Evaluated as low risk
  • src/modules/AdvancedPaste/AdvancedPaste/Models/ClipboardFormat.cs: Evaluated as low risk
  • src/modules/AdvancedPaste/AdvancedPaste/Models/PasteActionError.cs: Evaluated as low risk
  • src/modules/AdvancedPaste/AdvancedPaste/Models/PasteFormats.cs: Evaluated as low risk
  • src/modules/AdvancedPaste/AdvancedPaste/Services/ICustomTextTransformService.cs: Evaluated as low risk
Comments suppressed due to low confidence (2)

src/modules/AdvancedPaste/AdvancedPaste/Helpers/DataPackageHelpers.cs:53

  • The array passed to File.WriteAllBytesAsync is empty, which will result in an empty file being created. This may not be the intended behavior.
await File.WriteAllBytesAsync(outputFilePath, [], cancellationToken); // TranscodeAsync seems to require the output file to exist

src/modules/AdvancedPaste/AdvancedPaste/Helpers/DataPackageHelpers.cs:239

  • [nitpick] The variable name extension is ambiguous. It should be renamed to fileExtension for clarity.
where extension.StartsWith('.')

Comment on lines +53 to +54
await File.WriteAllBytesAsync(outputFilePath, [], cancellationToken); // TranscodeAsync seems to require the output file to exist

Copy link
Preview

Copilot AI Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace empty array [] with a valid byte array, e.g., new byte[0].

Suggested change
await File.WriteAllBytesAsync(outputFilePath, [], cancellationToken); // TranscodeAsync seems to require the output file to exist
await File.WriteAllBytesAsync(outputFilePath, new byte[0], cancellationToken); // TranscodeAsync seems to require the output file to exist

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Contributor

@shuaiyuanxx shuaiyuanxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


if (!prepareOp.CanTranscode)
{
throw new InvalidOperationException($"Error transcoding; {nameof(prepareOp.FailureReason)}={prepareOp.FailureReason}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m wondering if there’s a better way to display an error message explaining why the media cannot be transcoded. Perhaps we should validate the media beforehand to check if it's supported. Otherwise, if the transcoding fails, the user may not understand the reason—just like in the image below.
image

}

private static async Task TranscodeMediaAsync(StorageFile inputFile, StorageFile outputFile, MediaEncodingProfile outputProfile, CancellationToken cancellationToken, IProgress<double> progress)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we check if the media is already in the target format before starting transcoding to avoid redundant processing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In for .89 Needs-Review This Pull Request awaits the review of a maintainer.
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

6 participants