Created
October 6, 2017 14:26
-
-
Save apocalyptech/3f9c3cc1b13ef8a400d2604d1c1da4b9 to your computer and use it in GitHub Desktop.
Python script to create necessary empty subtitle files for The Inner World
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# vim: set expandtab tabstop=4 shiftwidth=4: | |
# Creates empty subtitle files for The Inner World, a pretty great | |
# point-n-click adventure game: http://store.steampowered.com/app/251430 | |
# | |
# Unfortunately the Linux version is not a great port, and has various issues. | |
# The biggest one is that some cutscenes won't play, and some of them are | |
# rather important. Upon investigation, it turns out that the reason is that | |
# it's trying to use subtitle files which aren't there, and failing to play the | |
# whole video as a result. A "solution" is to just create empty files for the | |
# ones that it's trying to load. | |
# | |
# This isn't entirely straightforward, as the subtitle files are *usually* | |
# named identically to the video files, but not always. One notable difference | |
# is that MOV_195a.m4v uses the subtitle file MOV_195A_EN.srt - note the | |
# capital "A" in the subtitle file. Other videos use the same case for that | |
# letter as in the video filename. | |
# | |
# So, this script basically just loops through the video list and constructs | |
# every subtitle filename which I think is likely to be used. It's possible, | |
# of course, that this doesn't actually get all the files that it should -- | |
# perhaps there's a subtitle file which follows a completely different pattern. | |
# So far it's been all right, though. | |
# | |
# At the moment you'd run this from the media/movies/ dir, but you can change | |
# those parameters with video_dir and subtitle_dir, below. I'm also not sure | |
# if there are languages other than German and English, elsewhere... The "EN" | |
# language setting below should be harmless even if you're using the german. | |
# In cases where the cutscenes have english, the German version is the one | |
# without any language specified in the filename, and we create those subtitle | |
# files, too. | |
import os | |
import re | |
# Constants | |
language = 'EN' | |
video_dir = '.' | |
subtitle_dir = '../Data/Subtitles' | |
mov_re = re.compile('^MOV_([0-9_]+)([a-dA-D])?(_{})?\.m4v$'.format(language)) | |
def sub_file(filename): | |
global subtitle_dir | |
return os.path.join(subtitle_dir, filename) | |
for filename_movie in os.listdir(video_dir): | |
if filename_movie[-4:] == '.m4v': | |
match = mov_re.match(filename_movie) | |
if match: | |
number = match.group(1) | |
letter = match.group(2) | |
orig_language = match.group(3) | |
# Construct a list of possible subtitle files. Most of these | |
# are unnecessary, but hopefully it'll at least end up providing | |
# all the subtitle files which are required. | |
possibilities = [] | |
if letter: | |
possibilities.append(sub_file('MOV_{}{}.srt'.format( | |
number, letter.lower()))) | |
possibilities.append(sub_file('MOV_{}{}.srt'.format( | |
number, letter.upper()))) | |
possibilities.append(sub_file('MOV_{}{}_{}.srt'.format( | |
number, letter.lower(), language))) | |
possibilities.append(sub_file('MOV_{}{}_{}.srt'.format( | |
number, letter.upper(), language))) | |
else: | |
possibilities.append(sub_file('MOV_{}.srt'.format( | |
number))) | |
possibilities.append(sub_file('MOV_{}_{}.srt'.format( | |
number, language))) | |
# Now loop through and create | |
for filename_srt in possibilities: | |
if os.path.exists(filename_srt): | |
#print('{} already exists'.format(filename_srt)) | |
pass | |
else: | |
print('{}: Creating {}...'.format(filename_movie, os.path.basename(filename_srt))) | |
with open(filename_srt, 'w') as df: | |
pass | |
else: | |
print('Movie filename not matched: {}'.format(filename_movie)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot for creating these. ;)