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

Sub Digest: Script to Python #27

Open
MrFanservice-png opened this issue Sep 3, 2024 · 1 comment
Open

Sub Digest: Script to Python #27

MrFanservice-png opened this issue Sep 3, 2024 · 1 comment

Comments

@MrFanservice-png
Copy link

MrFanservice-png commented Sep 3, 2024

How do I convert this script into a working python (.py) file where I can drag and drop the subtitle files to extract the necessary text from it?
for %I in (*.ass) do python -m subdigest -i "%I" --selection-set "text" "\\p" --remove-selected --selection-set style "Sign|OP|ED|op|ed|kfx|Karaoke|Eyecatch|Signs" --remove-selected --remove-all-tags --remove-comments --get-field text -o "%~nI.txt"

@MrFanservice-png MrFanservice-png changed the title Sub Digest: Extract Certain Text Styles Sub Digest: Script to Python Sep 4, 2024
@FichteFoll
Copy link

FichteFoll commented Sep 4, 2024

via ChatGPT:

How do I convert this batch script into one file where I can drag and drop the subtitle files to extract the necessary text from it?

for %I in (*.ass) do python -m subdigest -i "%I" --selection-set "text" "\p" --remove-selected --selection-set style "Sign|OP|ED|op|ed|kfx|Karaoke|Eyecatch|Signs" --remove-selected --remove-all-tags --remove-comments --get-field text -o "%~nI.txt"


To convert this batch script into one file that can process subtitle files by drag-and-dropping them onto it, you need to adapt it to work as a standalone script. This is achieved by using the following approach:

  1. Convert the batch script logic to handle drag-and-drop: When you drag and drop files onto a batch script, the dropped file paths are passed as arguments to the script. You need to loop through these arguments and apply the command to each file.

  2. Replace %I with appropriate syntax for processing each dropped file: The %1, %2, etc., will represent the file paths of the dropped files.

Here is how you can modify the script:
New Batch Script

@echo off
:: Loop through all files dragged and dropped onto the batch script
for %%I in (%*) do (
    :: Run your python command for each file
    python -m subdigest -i "%%~I" --selection-set "text" "\\p" --remove-selected --selection-set style "Sign|OP|ED|op|ed|kfx|Karaoke|Eyecatch|Signs" --remove-selected --remove-all-tags --remove-comments --get-field text -o "%%~nI.txt"
)
pause

Explanation:

  • %* represents all the files passed to the batch script (i.e., the subtitle files you drag and drop).
  • %%I is used in batch scripts (as opposed to %I, which is for use in command line directly).
  • %%~I represents the full path of each dropped file.
  • %%~nI extracts the filename without the extension.
  • The pause command ensures that the command prompt stays open so you can see the result.

Usage:

  • Save this script with a .bat extension, such as process_subtitles.bat.
  • Drag and drop .ass subtitle files onto the .bat file, and it will run the Python command on each one and output the processed text files.

This way, you don't have to run the script manually for each file. Just drag and drop the files onto the batch script.

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

No branches or pull requests

2 participants