Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@phattantran1997
Copy link
Contributor

  • Update Download Logic for YoutubeDownloader with additional option: Subtitles' Language.
  • Add new column "SubtitleLanguage" for model YoutubeDownloadQueueItem.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @phattantran1997, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request by phattantran1997 introduces the functionality to download subtitles for YouTube videos. It updates the download logic for the YoutubeDownloader, adding a subtitle language option. A new column, "SubtitleLanguage", is added to the YoutubeDownloadQueueItem model to store the selected subtitle language. The UI is updated to include a checkbox to enable subtitle downloading and a dropdown to select the desired language.

Highlights

  • New Feature: Subtitle Download: Adds the ability to download subtitles along with YouTube videos.
  • UI Enhancement: Introduces a checkbox and dropdown in the UI to control subtitle downloading and language selection.
  • Model Update: Adds a 'SubtitleLanguage' property to the 'YoutubeDownloadQueueItem' model.
  • Backend Logic: Modifies the YoutubeDownloadQueueService and YtdlpService to handle subtitle downloading based on user selection.

Changelog

Click here to see the changelog
  • SaveHere/SaveHere/Components/Download/DownloadVideoAudio.razor
    • Added a MudStack containing a MudCheckBox for enabling subtitle download and a MudSelect for choosing the subtitle language.
    • The MudSelect is disabled when the subtitle download checkbox is unchecked.
  • SaveHere/SaveHere/Components/Utility/SpotifySearch.razor
    • Modified the call to YoutubeDownloadQueueService.AddQueueItemAsync to pass null for the subtitleLanguage parameter.
  • SaveHere/SaveHere/Models/YoutubeDownloadQueueItem.cs
    • Added a SubtitleLanguage property of type string? with a default value of "en".
  • SaveHere/SaveHere/Services/YoutubeDownloadQueueService.cs
    • Modified the AddQueueItemAsync method to accept a subtitleLanguage parameter.
    • Updated the AddQueueItemAsync method to set the SubtitleLanguage property of the YoutubeDownloadQueueItem.
    • Modified the StartDownloadAsync method to pass the SubtitleLanguage to the _ytdlpService.DownloadVideo method.
  • SaveHere/SaveHere/Services/YtdlpService.cs
    • Modified the DownloadVideo method to accept a subtitleLanguage parameter.
    • Added logic to construct subtitle-related arguments for the youtube-dlp command based on the subtitleLanguage parameter.
    • Included the subtitle arguments in the final youtube-dlp command.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A download's quest,
Subtitles appear at best,
Words dance on the screen.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the functionality to download subtitles for YouTube videos, enhancing the application's capabilities. The changes involve adding a new UI element for subtitle selection, updating the data model, and modifying the download logic to include subtitle options. Overall, the implementation seems well-structured, but there are a few areas that could be improved.

Summary of Findings

  • Missing Input Validation: The _subtitleLanguage field is directly passed to the yt-dlp command without any validation. This could lead to command injection vulnerabilities if a malicious user inputs a crafted string. Input validation is crucial to ensure the application's security.
  • Hardcoded Subtitle Languages: The subtitle languages are hardcoded in the UI. It would be better to fetch these languages dynamically from yt-dlp or a configuration file to allow for more flexibility and easier updates.
  • Error Handling: There is no specific error handling for subtitle downloads. If the subtitle download fails, the user might not be notified, or the download process might be interrupted. Proper error handling is essential for a smooth user experience.

Merge Readiness

While the pull request introduces a valuable feature, there are some concerns that need to be addressed before merging. Specifically, the lack of input validation for the subtitle language poses a security risk. Additionally, the hardcoded subtitle languages and missing error handling could lead to a less-than-ideal user experience. I recommend addressing these issues before merging. I am unable to approve this pull request, and others should review and approve this code before merging.

Comment on lines +227 to +231
string subtitleArgs = "";
if (!string.IsNullOrWhiteSpace(subtitleLanguage))
{
subtitleArgs = $"--write-sub --write-auto-sub --sub-lang \"{subtitleLanguage}\"";
}

Choose a reason for hiding this comment

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

high

The subtitleLanguage variable is directly embedded into the command line arguments without any validation. This could lead to command injection vulnerabilities if a malicious user inputs a crafted string. Implement input validation to ensure that the subtitleLanguage variable only contains valid language codes or "auto".

Comment on lines +59 to +69
<MudSelect T="string" @bind-Value="_subtitleLanguage"
Label="Subtitle Language"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Class="ml-4"
Disabled="@(!_downloadSubtitles)">
<MudSelectItem Value="@("en")">English</MudSelectItem>
<MudSelectItem Value="@("vi")">Vietnamese</MudSelectItem>
<MudSelectItem Value="@("ja")">Japanese</MudSelectItem>
<MudSelectItem Value="@("auto")">Auto-detect</MudSelectItem>
</MudSelect>

Choose a reason for hiding this comment

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

medium

Consider fetching the subtitle languages dynamically from yt-dlp or a configuration file instead of hardcoding them. This would allow for more flexibility and easier updates. Also, consider adding a default value for the _subtitleLanguage field in case the user doesn't select a language.

Comment on lines +228 to +230
if (!string.IsNullOrWhiteSpace(subtitleLanguage))
{
subtitleArgs = $"--write-sub --write-auto-sub --sub-lang \"{subtitleLanguage}\"";

Choose a reason for hiding this comment

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

medium

Consider adding error handling to check if the subtitle download was successful. If the download fails, notify the user and log the error.

Quality = selectedQuality,
Proxy = proxyUrl,
DownloadFolder = downloadFolderName,
SubtitleLanguage = subtitleLanguage,

Choose a reason for hiding this comment

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

medium

Consider adding a check to ensure that the subtitleLanguage is not null or empty before assigning it to the YoutubeDownloadQueueItem. This can prevent potential null reference exceptions.

@phattantran1997
Copy link
Contributor Author

@gudarzi can you check this PR?

@gudarzi gudarzi merged commit 58cf917 into gudarzi:v3.0 May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants