ukdtom / SRT2UTF-8.bundle

Plex Agent, that'll convert sidecar subtitle files into UTF-8, if not
126 stars 14 forks source link

Add option to keep original file after adding language code #52

Closed GabrielNagy closed 3 years ago

GabrielNagy commented 3 years ago

This commit expands on the work done in 14c2f1bc24efeb5fe5a67d6e11a4c4ec4185f2e3 by adding an option to configure whether the original subtitle file is removed after the language code is appended to the filename.

Default this to true to maintain backwards compatibility.

This option is useful when the subtitles operated on by SRT2UTF-8 are part of torrents still being seeded. By setting the new option to false, we don't tamper with the original subtitle file and we ensure that the torrent checksum does not change.

haarismemon commented 3 years ago

This is a great idea @GabrielNagy. Have you tested this change just to make sure that the intended behaviour works when the new option is set as true and when set as false?

haarismemon commented 3 years ago

Also, it would be good to have something added to the README file. Would you be able to add something brief after the sentence starting with "If the renaming is enabled..." in the README file about the new functionality your new option provides?

GabrielNagy commented 3 years ago

Thanks for the review! I manually tested the change and it works as expected:

  1. with the option unticked (set to False), the subtitle file is copied, leaving the original in place:
2020-12-02 20:10:00,655 (7f5bcd7fa700) :  DEBUG (__init__:434) - Found a valid subtitle file named "movie.srt"
2020-12-02 20:10:00,656 (7f5bcd7fa700) :  DEBUG (__init__:202) - No language code detected for the file: /media/movies/movie/movie.srt
2020-12-02 20:10:00,657 (7f5bcd7fa700) :  DEBUG (__init__:232) - Copying: From /media/movies/movie/movie.srt to /media/movies/movie/movie.ro.srt
2020-12-02 20:10:00,686 (7f5bcd7fa700) :  DEBUG (__init__:150) - Chared is supported for this language
2020-12-02 20:10:00,847 (7f5bcd7fa700) :  DEBUG (__init__:358) - /media/movies/movie/movie.ro.srt Chared encoding detected as iso8859_2
2020-12-02 20:10:00,862 (7f5bcd7fa700) :  DEBUG (__init__:472) - Making a backup of /media/movies/movie/movie.ro.srt as /media/movies/movie/movie.ro.srt.Srt2Utf-8
2020-12-02 20:10:01,116 (7f5bcd7fa700) :  DEBUG (__init__:243) - Converting file: /media/movies/movie/movie.ro.srt with the encoding of iso8859_2 into utf-8
2020-12-02 20:10:01,192 (7f5bcd7fa700) :  INFO (__init__:256) - Successfully converted /media/movies/movie/movie.ro.srt to utf-8 from iso8859_2

Output from ls:

> ls -l *.srt*
-rw-r--r-- 1 gabi gabi 84647 Dec  2 20:10 movie.ro.srt
-rw-r--r-- 1 gabi gabi 87391 Dec  2 20:10 movie.ro.srt.Srt2Utf-8
-rw-r--r-- 1 gabi gabi 87391 Dec  2 20:10 movie.srt
  1. with the option ticked (set to True), the file is moved - this is the default behavior:
2020-12-02 20:14:36,717 (7f5bcd7fa700) :  DEBUG (__init__:434) - Found a valid subtitle file named "movie.srt"
2020-12-02 20:14:36,717 (7f5bcd7fa700) :  DEBUG (__init__:202) - No language code detected for the file: /media/movies/movie/movie.srt
2020-12-02 20:14:36,718 (7f5bcd7fa700) :  DEBUG (__init__:229) - Renaming: From /media/movies/movie/movie.srt to /media/movies/movie/movie.ro.srt
2020-12-02 20:14:36,742 (7f5bcd7fa700) :  DEBUG (__init__:150) - Chared is supported for this language
2020-12-02 20:14:36,892 (7f5bcd7fa700) :  DEBUG (__init__:358) - /media/movies/movie/movie.ro.srt Chared encoding detected as iso8859_2
2020-12-02 20:14:36,896 (7f5bcd7fa700) :  DEBUG (__init__:472) - Making a backup of /media/movies/movie/movie.ro.srt as /media/movies/movie/movie.ro.srt.Srt2Utf-8
2020-12-02 20:14:36,897 (7f5bcd7fa700) :  DEBUG (__init__:243) - Converting file: /media/movies/movie/movie.ro.srt with the encoding of iso8859_2 into utf-8
2020-12-02 20:14:36,898 (7f5bcd7fa700) :  INFO (__init__:256) - Successfully converted /media/movies/movie/movie.ro.srt to utf-8 from iso8859_2

Output from ls:

> ls -l *.srt*
-rw-r--r-- 1 gabi gabi 84647 Dec  2 20:14 movie.ro.srt
-rw-r--r-- 1 gabi gabi 87391 Dec  2 20:14 movie.ro.srt.Srt2Utf-8
GabrielNagy commented 3 years ago

The wiki should also be updated with the new option. Here's my suggested change:

### Remove the original subtitle file after adding the language code

Only takes effect if the "Add language code" option is also enabled. If disabled, the agent will copy the subtitle file instead of moving (renaming) it, leaving the original file in place.
haarismemon commented 3 years ago

Yeah, this looks good to me. I'd be happy for this to be merged in (once that is done, I can update the wiki). @ukdtom, you have any thoughts before I merge it in?

ukdtom commented 3 years ago

Sadly completely sidetracked here with real work, so at the moment no time until 14 days from now :(

But if you all already tested the way you did, I fully trust you @haarismemon (Otherwise I would never ever have made you a collaborator :D )

So do go ahead, as well as update both the wiki and the forum thread, and do remember to give credits ;)

And when said, just by reading this, it's so cool, so HUGE thanks from Denmark

haarismemon commented 3 years ago

Sounds good!

haarismemon commented 3 years ago

The wiki has been updated, and an update has been posted on the forum thread: https://forums.plex.tv/t/rel-srt2utf-8/54149/385?u=hmemon