-
Notifications
You must be signed in to change notification settings - Fork 2
Append language to subtitle name if missing, handle arbitrary extensions #24
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
base: subtitle-name-lang
Are you sure you want to change the base?
Append language to subtitle name if missing, handle arbitrary extensions #24
Conversation
- May add the putio api language code. - Ignored if the language code is not a valid language. - Only included if the filename does not already include the same language code, as detectable by Kodi. - Appends the language code to the file's _name_, before the file's extension (putdotio#22). - Handles arbitrary subtitle extensions, including: - `.srt`/`application/x-subrip`: current default. - `.vtt`/`text/vtt`: available in the putio api. Based on original code in putdotio#23 by @berkanteber. Closes putdotio#22. See - putdotio#22 - https://app.swaggerhub.com/apis-docs/putio/putio/2.8.13#/files/get_files__id__subtitles__key_ - https://en.wikipedia.org/wiki/SubRip - https://en.wikipedia.org/wiki/WebVTT - putdotio#23 - putdotio@8efb911
|
@berkanteber: sorry, code got stuck in "testing" since last year. As mentioned, it's based on your code so you can see what I meant in my code review. (To be honest, I've forgotten most of the discussion from then.) Hope you find the code agreeable. Let me know if you would prefer a standalone pull request. Also tested to never include any language code in the filename, but as you said kodi's language detection isn't always working. Ended up checking if the filename is already included the language code (the way it would be detected by kodi), and appending it if not. |
|
Hey, sorry for late response. Just looked at what we've discussed earlier. Changed my mind in couple of things, but not all.
|
Deliberately choosing to duplicate the language identifier makes little sense: - Video.eng.srt
+ Video.eng.eng.srt-if subtitle_lang != None and subtitle_lang.lower() not in re.split(r"[. -]", subtitle_name.lower()):
+if subtitle_lang != None:
subtitle_parts.append(subtitle_lang)Guess this is the change you suggest. I'd say the logic is simple enough to keep, but sure, if you insist. |
|
Checked a sample from DB. Out of 108,678 subtitles:
So, duplicates would be < 10%.
Checked this and Kodi takes the last one, so Let's have it only for checking the last part then. |
| # NOTE: split subtitle name/extension while allowing multiple dots within the name -- both as word/part separator and as ellipsis. | ||
| (subtitle_name, subtitle_ext) = os.path.splitext(subtitle['name']) | ||
| subtitle_ext = subtitle_ext.lstrip('.') if subtitle_ext != '' else None | ||
| subtitle_parts = subtitle_name.split('.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do:
subtitle_parts = [subtitle_name]
if ...:
subtitle_parts.append(lang_code)
subtitle_parts.append(subtitle_ext)
subtitle_fullname = '.'.join(subtitle_parts)| # NOTE: append known subtitle language to subtitle name, if it is not already a (delimited) part of it | ||
| # NOTE: separators (dot, space, dash) found on kodi's wiki. | ||
| # https://kodi.wiki/view/Subtitles | ||
| if subtitle_lang != None and subtitle_lang.lower() not in re.split(r"[. -]", subtitle_name.lower()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's check only last part (if has parts).
Also, we can check subtitle['language'].
Does returning also the 2-letter code makes sense? If we do, what should it be called (without touching others) in your opinion?
.srt/application/x-subrip: current default..vtt/text/vtt: available in the putio api.Based on original code in #23 by @berkanteber.
Closes #22.
See