From c142ee8e10e0d91ecc1dd16a657889f649443c36 Mon Sep 17 00:00:00 2001 From: mussonero Date: Tue, 20 Aug 2024 15:15:18 +0200 Subject: [PATCH 1/5] added ability to load multi subtitles directly from "Subs/" --- README.md | 2 + service.subsautoloader/addon.xml | 4 +- service.subsautoloader/resources/settings.xml | 30 ++++ service.subsautoloader/service.py | 156 +++++++++++++----- 4 files changed, 145 insertions(+), 47 deletions(-) create mode 100644 service.subsautoloader/resources/settings.xml diff --git a/README.md b/README.md index 6b0da7b..a823f65 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,5 @@ Auto-loads subtitles from location `Subs/[number]_[language].srt`(Movies) or `Su ### Installation and Usage Download latest release from [releases](https://github.com/recrof/kodi.service.subsautoloader/releases/), then [Use kodi guide to install the addon zip file](https://kodi.wiki/view/Archive:Install_add-ons_from_zip_files). Subs autoloader should work right after installation. + + diff --git a/service.subsautoloader/addon.xml b/service.subsautoloader/addon.xml index 8681a85..8b27eb2 100644 --- a/service.subsautoloader/addon.xml +++ b/service.subsautoloader/addon.xml @@ -1,5 +1,5 @@ - + @@ -10,4 +10,4 @@ all Apache License 2.0 - + \ No newline at end of file diff --git a/service.subsautoloader/resources/settings.xml b/service.subsautoloader/resources/settings.xml new file mode 100644 index 0000000..b68253e --- /dev/null +++ b/service.subsautoloader/resources/settings.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/service.subsautoloader/service.py b/service.subsautoloader/service.py index c399f4e..637d39f 100644 --- a/service.subsautoloader/service.py +++ b/service.subsautoloader/service.py @@ -1,62 +1,128 @@ -import xbmc, xbmcvfs, os, json +import xbmc, xbmcvfs, os, json, xbmcgui, xbmcaddon + +addon = xbmcaddon.Addon() def debug(msg): - xbmc.log('[service.subsautoloader] ' + msg, xbmc.LOGINFO) + xbmc.log('[service.subsautoloader] ' + msg, xbmc.LOGINFO) def execRPC(method, params): - rpcCallObject = { - 'jsonrpc': '2.0', - 'method': method, - 'params': params, - 'id': 1 - } - - resObject = json.loads(xbmc.executeJSONRPC(json.dumps(rpcCallObject))) - - return resObject['result'] + rpcCallObject = { + 'jsonrpc': '2.0', + 'method': method, + 'params': params, + 'id': 1 + } + resObject = json.loads(xbmc.executeJSONRPC(json.dumps(rpcCallObject))) + return resObject['result'] -def findSub(path, language): - dirs, files = xbmcvfs.listdir(path) +# Load user-configured language mappings +language_mapping = {} - if len(files) == 0: - return '' +# Loop through possible language slots in settings.xml +for i in range(1, 8): # Assuming you have 7 slots, adjust as needed + lang = addon.getSetting(f'language{i}').lower() + lang_code = addon.getSetting(f'langcode{i}').lower() + if lang and lang_code: # Only add if both fields are not empty + language_mapping[lang] = [lang_code] - for subFile in files[::-1]: - if language.lower() in subFile.lower(): - return subFile - return '' +debug(f'Loaded language mapping from settings: {language_mapping}') -def getSubFilePath(videoPath): - videoFile = os.path.basename(videoPath) - rootPath = os.path.dirname(videoPath) - subVideoName = '.'.join(videoFile.split('.')[0:-1]) - subPath = rootPath + '/Subs' +def getSubFilePaths(videoPath): + # Extract the video file name from the video path + videoFile = os.path.basename(videoPath) + # Extract the root path from the video path + rootPath = os.path.dirname(videoPath) + # Construct the subtitle path using the root path + subPath = os.path.join(rootPath, 'Subs') + # Get the user-configured subtitle language from Kodi settings + subLanguage = execRPC('Settings.GetSettingValue', {'setting': 'subtitles.languages'})['value'][0].lower() + # Print the subtitle language used + debug(f'Using subtitle language: {subLanguage}') + # Get the possible subtitle codes for the language + possible_sub_codes = language_mapping.get(subLanguage, [subLanguage]) + # Initialize lists to store main and other subtitles + main_subs, other_subs = [], [] - subLanguages = execRPC('Settings.GetSettingValue', { 'setting': 'subtitles.languages' })['value'] - debug('using subtitle language: ' + subLanguages[0]) + # Loop through two possible subtitle paths + for path in [subPath, os.path.join(subPath, os.path.splitext(videoFile)[0])]: + try: + # List the files in the subtitle path + for subFile in xbmcvfs.listdir(path)[1]: + # Convert the subtitle file name to lowercase + subFileLower = subFile.lower() + # Check if the subtitle file name contains any of the possible subtitle codes + if any(subCode.lower() in subFileLower for subCode in possible_sub_codes): + # If it does, add it to the main subtitle list + main_subs.append(os.path.join(path, subFile)) + else: + # Loop through the language mappings + for lang, codes in language_mapping.items(): + # Skip the language that was already checked + if lang == subLanguage: + continue + # Check if the subtitle file name contains any of the codes for the language + if any(subCode.lower() in subFileLower for subCode in codes): + # If it does, add it to the other subtitle list and break the loop + other_subs.append(os.path.join(path, subFile)) + break + # If an error occurs while listing the files or searching for subtitles, print the error + except Exception as e: + debug(f"Error while searching for subtitles: {str(e)}") + pass - for path in [subPath, subPath + '/' + subVideoName]: - foundSub = findSub(path, subLanguages[0]) - if foundSub: - return path + '/' + foundSub - - return '' + # Return the concatenated lists of main and other subtitles + return main_subs + other_subs class Player(xbmc.Player): - def onAVStarted(self): - if not self.isPlayingVideo(): - return - subtitles = self.getAvailableSubtitleStreams() - if subtitles: - return - - subFilePath = getSubFilePath(self.getPlayingFile()) - if subFilePath: - debug('loading subtitle: ' + subFilePath) - self.setSubtitles(subFilePath) + + # def onPlayBackStarted(self): + # """Called when playback starts.""" + def onAVStarted(self): + """ + Called when video is ready for playback. + Checks if subtitles are already available. + If not, it retrieves the video path and searches for subtitles. + If subtitles are found, it creates a new ListItem with the video path and sets the subtitles. + Then it restarts playback with the new ListItem and video path. + """ + # Check if the current playback is for a video + if not self.isPlayingVideo(): + return + + # Check if subtitles are already available + subtitles = self.getAvailableSubtitleStreams() + if subtitles: + # Print the available subtitles + debug(f'Subtitle streams already available: {subtitles}') + return + + # Get the path of the currently playing video + video_path = self.getPlayingFile() + + # Search for subtitles based on the video path + subFilePaths = getSubFilePaths(video_path) + + if subFilePaths: + # Print the found subtitles + debug('Found subtitles: ' + ', '.join(subFilePaths)) + + # Create a new ListItem with the video path + list_item = xbmcgui.ListItem(path=video_path) + + # Set the subtitles for the ListItem + list_item.setSubtitles(subFilePaths) + + # Print the subtitles set for the ListItem + debug(f'Subtitles set for ListItem before playback: {subFilePaths}') + + # Restart playback with the new ListItem and video path + self.play(video_path, list_item) + else: + # Print if no matching subtitles were found + debug('No matching subtitles found.') player = Player() monitor = xbmc.Monitor() while not monitor.abortRequested(): - monitor.waitForAbort(10) \ No newline at end of file + monitor.waitForAbort(10) From 0a85a9ded3c5113c95827b58f6298ccea7b46df2 Mon Sep 17 00:00:00 2001 From: mussonero Date: Tue, 20 Aug 2024 16:38:04 +0200 Subject: [PATCH 2/5] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index a823f65..f485844 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,10 @@ Auto-loads subtitles from location `Subs/[number]_[language].srt`(Movies) or `Su `Subs` subtitle folder structure is mostly used in torrent releases(eg. RARBG). +added ability to load multi subtitles directly from `Subs`. + +Added the ability to configure preferred languages. + ### Installation and Usage Download latest release from [releases](https://github.com/recrof/kodi.service.subsautoloader/releases/), then [Use kodi guide to install the addon zip file](https://kodi.wiki/view/Archive:Install_add-ons_from_zip_files). Subs autoloader should work right after installation. From 6bed021f375e16b16e3f59596c7a794fa694d40a Mon Sep 17 00:00:00 2001 From: mussonero Date: Tue, 20 Aug 2024 16:38:04 +0200 Subject: [PATCH 3/5] Update README.md --- README.md | 2 +- service.subsautoloader.zip | Bin 0 -> 8288 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 service.subsautoloader.zip diff --git a/README.md b/README.md index f485844..c7d10de 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,6 @@ added ability to load multi subtitles directly from `Subs`. Added the ability to configure preferred languages. ### Installation and Usage -Download latest release from [releases](https://github.com/recrof/kodi.service.subsautoloader/releases/), then [Use kodi guide to install the addon zip file](https://kodi.wiki/view/Archive:Install_add-ons_from_zip_files). Subs autoloader should work right after installation. +Download latest release from [releases](https://github.com/mussonero/kodi.service.subsautoloader/releases/), then [Use kodi guide to install the addon zip file](https://kodi.wiki/view/Archive:Install_add-ons_from_zip_files). Subs autoloader should work right after installation. diff --git a/service.subsautoloader.zip b/service.subsauto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h<<_QQ;T&T<6e(|am zSWLZw^BD8OHfPFC@aqJ#C>?RL?Fx{n#}MI#3B!jUt%j}4CPR@fE!4xm*aoa>Mgy(E4%Ag>irI$w^|>DF3Z8A!4~eJU_|Y5uGA`)Fk|? z9)Ajs{c z`y7X?IZd=PM0x}kzsYV7v=_6nU^UKhs0ZMge-vr%zacA$; zb<{j;a`py8X}%lPnC_`v+4nly+hHK9HK$eVtELX0PexW>j)(pK%p}CMyhl)&qe4}ndRhnd>nkSFG_fg3nm@+*T4jzdCqz83}16 z87_PCzk2wle;#(bC8|WPb7S`&UJ(Vo)SGcW5W$9#>xSKRb3>KiKXJ%=Qdpt&qzU?C zqB5)Cdrg(ji^H8AX5fl&9j<^q!~`d!cmrNfdz_;zf(cV(E^auc<%ezPZ{+E6kQ@bl zsS+;D2ME-TscsuQp8ckf@H)FD>DG3$gj}C#)P;0yC!n>`eJMCgUJ_e4PEEhXcMNSX4J{>s6IfcG1u zL}Vg*5-&_0S6-dopX&<@Zx{s^pD!(q`^%^6w2tw|G(dnX9>LaWiz5!7s5D1wxQ3Q? z@bL z8ibiUXdY|ylk0fEpid9$7M%DRu`0H*K0NWsqt(JSWOPfJs^Lwm>|nqf5Fc-FViZMe z@l&nJDr~;Nie-&j!+WTEy=Am@?l1A|4QjW(fMsZCBVNn;2%=@chteZlY7ty|CE*<^uga& zADH^Dg!^~Y!rz%b?CXPe_2)?L&rItB-F_+I|B&hL$NzsN>(6ixbG|?M<6+MC+v)=w xu>k+-)bCHH57hG~I3K9zx77!FQv&{VB2tB*{F+TZ%pcJJGr#uTh5F&we*p2yiSqye literal 0 HcmV?d00001 From 34cb58807133a1637f323a4a6264f2316a67f00f Mon Sep 17 00:00:00 2001 From: mussonero Date: Tue, 20 Aug 2024 18:06:19 +0200 Subject: [PATCH 4/5] Added Addon settings --- README.md | 4 ++-- service.subsautoloader.zip | Bin 8288 -> 0 bytes service.subsautoloader/resources/settings.xml | 6 +++--- service.subsautoloader/service.py | 19 +++++++++++++++++- 4 files changed, 23 insertions(+), 6 deletions(-) delete mode 100644 service.subsautoloader.zip diff --git a/README.md b/README.md index c7d10de..2ccb3e0 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ Auto-loads subtitles from location `Subs/[number]_[language].srt`(Movies) or `Su `Subs` subtitle folder structure is mostly used in torrent releases(eg. RARBG). -added ability to load multi subtitles directly from `Subs`. +added ability to load multi subtitles directly from `Subs` or from other Subs folder using the Addon settings. -Added the ability to configure preferred languages. +Added the ability to configure preferred languages using the Addon settings. ### Installation and Usage Download latest release from [releases](https://github.com/mussonero/kodi.service.subsautoloader/releases/), then [Use kodi guide to install the addon zip file](https://kodi.wiki/view/Archive:Install_add-ons_from_zip_files). Subs autoloader should work right after installation. diff --git a/service.subsautoloader.zip b/service.subsautoloader.zip deleted file mode 100644 index 6f280b9c0cd35ba70b1df9cc9dec41e60e797a0b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8288 zcmb7pWmKG7lXc@R!97TDX{4bc1lQ2G2MOA^(>TE$fF#H(u3B|!Kl_}jtqMUxCIUQIE{y2KUtj)fAqCI^T%j)R)@D#H zS2t5v6E~Qnoui34)CH)ei3318eBEOqThwFW`|H!q6AOTV{P4%W7S+F;q65$Yw4Q%E zZAJwAa`}%=P0Y<59k@L0?f&xqI;qDZCiQ>y?xqfLoae?CZTJ+lBBDM0GD^aIoO&AK zxcE8Ll&6|o#6aQmn!nf}oEJ&TfdGEksq$sCXk}GC(=dwD&$=F+=*HaeS?%R%|HTNQ zBo~w3x<&zs<>2MQqOF;I)QVkn+U2&l%}MQ$1sj~%Eb>tv2JcTUEzcJzU-d?ix(0T( z3qA^shO=5eS__Gvp*C1R-->UPDa@X@*UO%15KQL%R;fU3KwfA#QIzx9Z1+vs*h1Cx z;<9z&D4Yi>v}{e<*MpLprT6T+`BCe9 z_3D+8;(AP$w$7w|RId_YF_~>tXRlSZB)-5=p(tK&+*ik$DcG_(Up#*_dp7UB5Q=VI zLu_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qt(JSWOPfJs^Lwm>|nqf5Fc-FViZMe z@l&nJDr~;Nie-&j!+WTEy=Am@?l1A|4QjW(fMsZCBVNn;2%=@chteZlY7ty|CE*<^uga& zADH^Dg!^~Y!rz%b?CXPe_2)?L&rItB-F_+I|B&hL$NzsN>(6ixbG|?M<6+MC+v)=w xu>k+-)bCHH57hG~I3K9zx77!FQv&{VB2tB*{F+TZ%pcJJGr#uTh5F&we*p2yiSqye diff --git a/service.subsautoloader/resources/settings.xml b/service.subsautoloader/resources/settings.xml index b68253e..23f6e60 100644 --- a/service.subsautoloader/resources/settings.xml +++ b/service.subsautoloader/resources/settings.xml @@ -9,9 +9,6 @@ - - - @@ -27,4 +24,7 @@ + + + diff --git a/service.subsautoloader/service.py b/service.subsautoloader/service.py index 637d39f..1e6ba2a 100644 --- a/service.subsautoloader/service.py +++ b/service.subsautoloader/service.py @@ -27,13 +27,30 @@ def execRPC(method, params): debug(f'Loaded language mapping from settings: {language_mapping}') +def find_subs_folder(rootPath): + # Check default folder first + defaultsubsdir = addon.getSetting('defaultsubsdir') + debug(f'Checking for default subs folder: {defaultsubsdir}') + if defaultsubsdir and xbmcvfs.exists(os.path.join(rootPath, defaultsubsdir)): + return os.path.join(rootPath, defaultsubsdir) + # Check other possible folders + possible_folders = {'Subs', 'Sub', 'Subtitles', 'subs', 'sub', 'subtitles'} + for folder in xbmcvfs.listdir(rootPath)[0]: + if folder in possible_folders: + return os.path.join(rootPath, folder) + # Return None if none of the folders exist + return None + def getSubFilePaths(videoPath): # Extract the video file name from the video path videoFile = os.path.basename(videoPath) # Extract the root path from the video path rootPath = os.path.dirname(videoPath) # Construct the subtitle path using the root path - subPath = os.path.join(rootPath, 'Subs') + subPath = find_subs_folder(rootPath) + if subPath is None: + return None + debug(f'Checking for subtitles in: {subPath}') # Get the user-configured subtitle language from Kodi settings subLanguage = execRPC('Settings.GetSettingValue', {'setting': 'subtitles.languages'})['value'][0].lower() # Print the subtitle language used From 6e733019af343ffc34abddd1ec22dc1b5d4bfb50 Mon Sep 17 00:00:00 2001 From: mussonero Date: Tue, 20 Aug 2024 20:45:09 +0200 Subject: [PATCH 5/5] Update README.md --- README.md | 84 ++++++++++++++++++++++++++++---- service.subsautoloader/addon.xml | 24 ++++----- 2 files changed, 87 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 2ccb3e0..3e333fe 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,83 @@ -# Kodi Addon: Autoload subtitles from `Subs` folder +# Kodi Addon: Autoload Subtitles from `Subs` Folder -### Description and configuration -Auto-loads subtitles from location `Subs/[number]_[language].srt`(Movies) or `Subs/Name.of.the.video/[number]_[language].srt`(Series) on video playback. +## Overview -`[language]` is first language used from kodi settings(`Player > Subtitles > Preferred Subtitle Language`). +This Kodi addon automatically loads subtitles from a `Subs` folder when video playback begins. It supports both movies and TV series, using a folder structure common in most media libraries. -`Subs` subtitle folder structure is mostly used in torrent releases(eg. RARBG). +- **Movies:** `Subs/[number]_[language].srt` +- **Series:** `Subs/Name.of.the.video/[number]_[language].srt` -added ability to load multi subtitles directly from `Subs` or from other Subs folder using the Addon settings. +This addon is designed to enhance your viewing experience by seamlessly loading subtitles according to your preferred language settings in Kodi. -Added the ability to configure preferred languages using the Addon settings. +## Features -### Installation and Usage -Download latest release from [releases](https://github.com/mussonero/kodi.service.subsautoloader/releases/), then [Use kodi guide to install the addon zip file](https://kodi.wiki/view/Archive:Install_add-ons_from_zip_files). Subs autoloader should work right after installation. +- **Auto-Subtitle Loading:** Automatically loads subtitles for movies and TV series from the `Subs` folder, based on the Kodi preferred subtitle language setting. +- **Multi-Subtitle Support:** Supports loading multiple subtitle files directly from the `Subs` folder or from other configured directories. +- **Configurable Languages:** Ability to configure additional preferred languages using the addon settings, allowing for greater flexibility in subtitle selection. +- **Configurable Default Subs Folder:** Ability to configure the default `Subs` folder using the addon settings. +- **Common Structure Support:** Supports subtitle folder structures commonly used across different media types. +## Configuration + +### Folder Structure + +- **Movies:** The subtitles should be placed in the `Subs` folder, following this naming convention: + ``` + Subs/[number]_[language].srt + ``` + Example: `Subs/01_english.srt` + +- **TV Series:** Subtitles for episodes should be placed within the corresponding video folder, like this: + ``` + Subs/Name.of.the.video/[number]_[language].srt + ``` + Example: `Subs/Name.of.the.show.S01E01/01_english.srt` + +### Language Settings + +The `[language]` placeholder refers to the first language configured in Kodi's settings (`Player > Subtitles > Preferred Subtitle Language`). You can also set additional languages within the addon configuration. + +## Installation and Usage + +### Step 1: Download the Addon + +Head over to the [Releases](#) section of this repository and download the latest release of the addon as a `.zip` file. + +### Step 2: Install the Addon + +Once downloaded, follow the official [Kodi guide to install the addon from a zip file](https://kodi.wiki/view/Archive:Install_add-ons_from_zip_files). + +### Step 3: Enjoy Subtitles Autoload + +After installation, the subtitle autoload feature should work immediately upon video playback. No additional setup is required for basic functionality. + +## Customization + +### Multi-Subtitle Loading + +If you need to load multiple subtitle files, you can configure this within the addon settings. This allows you to select and load multiple subtitle tracks from either the default `Subs` folder or from other directories that you configure. + +### Preferred Languages + +The addon lets you configure additional preferred subtitle languages through its settings. This feature is useful for multilingual viewers who prefer subtitles in different languages for various content. + +## Troubleshooting + +If the addon is not working as expected: +- Ensure that the subtitle files are named and structured correctly. +- Double-check the configured language settings in Kodi (`Player > Subtitles > Preferred Subtitle Language`). +- Automatic scan for `Subs` folder and other possible folders = {`'Subs', 'Sub', 'Subtitles', 'subs', 'sub', 'subtitles'`} placed correctly in relation to your media files. + +## Contributing + +Contributions are welcome! If you would like to contribute to the development of this addon: +- Fork this repository. +- Make your changes in a new branch. +- Submit a pull request with a detailed description of your changes. + +Please ensure that your code adheres to the project's coding standards and that you test your changes thoroughly before submitting. + +## License + +This project is licensed under the Apache License. See the [LICENSE](LICENSE) file for more details. diff --git a/service.subsautoloader/addon.xml b/service.subsautoloader/addon.xml index 8b27eb2..e58a09f 100644 --- a/service.subsautoloader/addon.xml +++ b/service.subsautoloader/addon.xml @@ -1,13 +1,13 @@ - - - - - - - AutoLoad subtitles from Subs dir - Automatically load subtitles from Subs folder when video starts playing - all - Apache License 2.0 - - \ No newline at end of file + + + + + + + Auto-load subtitles from Subs folder + Automatically loads subtitles from the Subs folder when video starts playing. Supports movie and series subtitle structures, with multi-subtitle and language configuration options. + all + MIT License + +