Announcement

Collapse
No announcement yet.

[Abandoned] Trying to get two actions on a single file in a Dolphin Service menu

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [Abandoned] Trying to get two actions on a single file in a Dolphin Service menu

    I use Dolphin service menus to extract subtitles from video files. Then, if the subtitle is ssa format, I use a second service menu to convert it to srt. Independently, they both work fine. I'd like to combine this into a single service menu; i.e extract and convert automatically when the file type is ssa.

    The subtitle extraction is done with a python script that I call from the service menu like this:
    Code:
    Exec=$HOME/.local/share/applications/mkvextract-allsubs-eng %u
    The conversion to srt is much simpler and uses ffmpeg, so it's a one-liner:
    Code:
    ffmpeg -i "$fn" "${fn%.*}".srt
    I suspect I could add the conversion function to the python script, but I don't know python at all - the python script is something I found on the 'net.

    I have attempted this in the service menu:
    Code:
    Exec=$HOME/.local/share/applications/mkvextract-allsubs-eng %u; fn=%u; if [[ "${fn#"${fn%???}"}" = "ssa" ]]; then ffmpeg -i "$fn" "${fn%.*}".srt; rm "$fn"; fi
    The results are the extraction occurs but not the conversion.

    All the pieces in the if statement work from the command line so I think the issue is in the Service Menu action itself - like once the python script is called the service menu stops provessing.

    Looking for ideas..

    Please Read Me

    #2
    Originally posted by oshunluvr View Post
    Looking for ideas..
    Put the actions in a .desktop file and call that from your custom Service menu?
    Windows no longer obstruct my view.
    Using Kubuntu Linux since March 23, 2007.
    "It is a capital mistake to theorize before one has data." - Sherlock Holmes

    Comment


      #3
      Originally posted by Snowhog View Post
      Put the actions in a .desktop file and call that from your custom Service menu?
      I don't seem to be able to call two actions from a single Exec= line. Here's the desktop file:

      Code:
      [Desktop Entry]
      Type=Service
      Icon=video-x-matroska
      X-KDE-ServiceTypes=KonqPopupMenu/Plugin
      MimeType=video/x-matroska;text/x-microdvd
      Actions=geteng
      Encoding=UTF-8
      
      [Desktop Action geteng]
      Name=Extract English subs
      Icon=archive-extract
      Exec=$HOME/.local/share/applications/mkvextract-allsubs-eng %u; fn=%u; if [[ "${fn#"${fn%???}"}" = "ssa" ]]; then ffmpeg -i "$fn" "${fn%.*}".srt; rm "$fn"; fi



      But maybe calling a script that then calls the Python script and finally then the rename action might work? Not sure how I'd handle the variables though...

      Please Read Me

      Comment


        #4
        AI Overview

        Standard .desktop files do not support multiple Exec= lines within a single [Desktop Entry] section. If you include more than one, only one will be recognized.

        To run multiple commands or applications from one file, use one of the following methods:

        1. Chain Commands in One Line

        You can use a shell wrapper to execute multiple commands sequentially or simultaneously:
        • Sequential (Wait for completion): Runs command 2 after command 1 finishes successfully.
          Exec=sh -c "command1 && command2"
        • Unconditional Sequence: Runs command 2 after command 1 finishes, regardless of whether command 1 succeeded.
          Exec=sh -c "command1; command2"
        • Simultaneous (Background): Runs both at the same time.
          Exec=sh -c "command1 & command2"

        2. Use a Shell Script

        For complex sequences, write a separate shell script and point the Exec= line to it.
        • Create a file (e.g., myscript.sh) and make it executable: chmod +x myscript.sh.
        • Set the full path in your .desktop file:
          Exec=/home/user/scripts/myscript.sh
        Windows no longer obstruct my view.
        Using Kubuntu Linux since March 23, 2007.
        "It is a capital mistake to theorize before one has data." - Sherlock Holmes

        Comment


          #5
          I don't seem to be able to call two actions from a single Exec= line. Here's the desktop file:
          ​Replace your Exec= line with this:
          Exec=bash -c '$HOME/.local/share/applications/mkvextract-allsubs-eng "$1"; for f in "${1%.*}".*.ss[a]; do [ -e "$f" ] || continue; ffmpeg -i "$f" "${f%.*}.srt"; rm "$f"; done' _ %u
          then after editing run
          Code:
          kbuildsycoca6
          (or kbuildsycoca5) depending on your KDE version.
          then restart dolphin
          Code:
          killall dolphin
          see if it works ?
          ʟɨռʊӼ ʄօʀ ʟɨʄɛ

          Comment


            #6
            Originally posted by die.boer View Post
            ​Replace your Exec= line with this:
            Exec=bash -c '$HOME/.local/share/applications/mkvextract-allsubs-eng "$1"; for f in "${1%.*}".*.ss[a]; do [ -e "$f" ] || continue; ffmpeg -i "$f" "${f%.*}.srt"; rm "$f"; done' _ %u
            then after editing run
            Code:
            kbuildsycoca6
            (or kbuildsycoca5) depending on your KDE version.
            then restart dolphin
            Code:
            killall dolphin
            see if it works ?
            Here's the errors when using the above:

            Code:
            kf.config.core: Skipping Action "_SEPARATOR_" due to empty Name field in file "/home/stuart/.local/share/kio/servicemenus/subvol_manager.desktop"
            kf.service.services: The action "geteng" in the desktop file "/home/stuart/.local/share/kio/servicemenus/mkvsubextract.desktop" has no Exec key and not D-Bus activatable
            kf.kio.core: No Exec field in "/home/stuart/.local/share/kio/servicemenus/mkvsubextract.desktop"
            kf.kio.gui: "" "No Exec field in /home/stuart/.local/share/kio/servicemenus/mkvsubextract.desktop"
            ​

            Please Read Me

            Comment


              #7
              why not just write a script that does what you need done, and then call the script from the service menu.

              some stuff i did: https://github.com/droidgoo

              Intel® Core™ i7-14700K | 64 GiB of RAM | AMD RX 6800

              Comment


                #8
                Originally posted by oshunluvr View Post

                Here's the errors when using the above:

                Code:
                kf.config.core: Skipping Action "_SEPARATOR_" due to empty Name field in file "/home/stuart/.local/share/kio/servicemenus/subvol_manager.desktop"
                kf.service.services: The action "geteng" in the desktop file "/home/stuart/.local/share/kio/servicemenus/mkvsubextract.desktop" has no Exec key and not D-Bus activatable
                kf.kio.core: No Exec field in "/home/stuart/.local/share/kio/servicemenus/mkvsubextract.desktop"
                kf.kio.gui: "" "No Exec field in /home/stuart/.local/share/kio/servicemenus/mkvsubextract.desktop"
                ​
                hmm think KDE's parser breaks if the command gets too complex inline,specially with ' inside EXEC=
                best is to probably just make a script and run it from the service menu ,like others suggested.
                it'll be more reliable
                ʟɨռʊӼ ʄօʀ ʟɨʄɛ

                Comment


                  #9
                  Thank you to everyone who offered help, but this is now a dead issue.

                  I think the real problem is I screwed up: The extracted "ssa" filename does not match the source MKV file - it's amended by the python script and includes "English" and a couple other tags like track number and track type. This causes the if statement in the service menu to always return "false" so the conversion is not happening. The Service Menu itself IS working, it's just not written correctly.

                  I didn't think it all the way through.

                  To further complicate this, a movie file can have more than one English subtitle track type and quite often has 3 - a full subtitle track, a "hearing impaired" track (includes text of various sound effects), and a "forced" track (English to replace a foreign language). The python script extracts ALL English subtitle tracks, which is desired.

                  So clearly, my desired goal is not achievable using this method.

                  I also tried doing the ffmpeg conversion by running a "watch" on the folder using "inotifywait" which worked on the ssa files but for some reason blocked the python script from working at all. I could move an ssa file into the folder and it would convert. But the extraction action using the python script would not extract anything while the inotifywait action was active.

                  Back to the drawing board...


                  ...or maybe some Python training, LOL
                  Last edited by oshunluvr; Today, 02:54 PM.

                  Please Read Me

                  Comment

                  Users Viewing This Topic

                  Collapse

                  There are 0 users viewing this topic.

                  Working...
                  X