Myaamori-Aegisub-Scripts icon indicating copy to clipboard operation
Myaamori-Aegisub-Scripts copied to clipboard

Sub Digest: Script to Python

Open MrFanservice-png opened this issue 1 year ago • 1 comments

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 avatar Sep 03 '24 20:09 MrFanservice-png

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.

FichteFoll avatar Sep 04 '24 22:09 FichteFoll