Skip to content

Instantly share code, notes, and snippets.

@t1anchen
Last active September 29, 2019 08:45
Show Gist options
  • Save t1anchen/4652893 to your computer and use it in GitHub Desktop.
Save t1anchen/4652893 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os
import sys
import getopt
import re
import os.path
def main():
for dirpath, dirnames, filenames in os.walk(sys.argv[1]):
# for i in os.walk(sys.argv[1]):
# for i in filenames:
# new_filename = re.sub(r' ', r'.', filename)
# full_filename = os.path.join(dirpath, filename)
# if re.search(r' ', full_filename) != None:
# new_full_filename = re.sub(r' ',r'.',full_filename)
# os.rename(full_filename, new_full_filename)
# if full_filename != new_full_filename:
# print full_filename + " -> " + new_full_filename
for filename in filenames:
new_filename = re.sub(r' ', r'.', filename)
if new_filename != filename:
old_full_filename = os.path.join(dirpath, filename)
new_full_filename = os.path.join(dirpath, new_filename)
os.rename(old_full_filename, new_full_filename)
print 'File: ', old_full_filename, ' -> ', new_full_filename
for dirname in dirnames:
new_dirname = re.sub(r' ', r'.', dirname)
if new_dirname != dirname:
old_full_dirname = os.path.join(dirpath, dirname)
new_full_dirname = os.path.join(dirpath, new_dirname)
os.rename(old_full_dirname, new_full_dirname)
print 'Directory: ', old_full_dirname, ' -> ', new_full_dirname
if __name__ == "__main__":
main()
@JarosLucky
Copy link

thanks for it. i littly modifed and used that.

@t1anchen
Copy link
Author

t1anchen commented Aug 9, 2019

I've posted another version https://gist.github.com/t1anchen/7e03f2650b653d2f29ce60d92ca797aa . You might have a look if you're interested in.

@lukjod
Copy link

lukjod commented Sep 9, 2019

is this possible to use this script as postprocessing to copy and change name of name.pl.srt file to name.1.srt
variables for bazarr python subs downloader are:

{{directory}}
The full path of the episode file parent directory.
{{episode}}
The full path of the episode file.
{{episode_name}}
The filename of the episode without parent directory or extension.
{{subtitles}}
The full path of the subtitles file.
{{subtitles_language}}
The language of the subtitles file.
{{subtitles_language_code2}}
The 2-letter ISO-639 language code of the subtitles language.
{{subtitles_language_code3}}
The 3-letter ISO-639 language code of the subtitles language.
i want to get something like
bash command
for f in "{{subtitles}}"/*.pl.srt; do cp "$f" "${f%.pl.srt}.1.srt" ; done
but cant figure it out
any help please

@t1anchen
Copy link
Author

is this possible to use this script as postprocessing to copy and change name of name.pl.srt file to name.1.srt
variables for bazarr python subs downloader are:

{{directory}}
The full path of the episode file parent directory.
{{episode}}
The full path of the episode file.
{{episode_name}}
The filename of the episode without parent directory or extension.
{{subtitles}}
The full path of the subtitles file.
{{subtitles_language}}
The language of the subtitles file.
{{subtitles_language_code2}}
The 2-letter ISO-639 language code of the subtitles language.
{{subtitles_language_code3}}
The 3-letter ISO-639 language code of the subtitles language.
i want to get something like
bash command
for f in "{{subtitles}}"/*.pl.srt; do cp "$f" "${f%.pl.srt}.1.srt" ; done
but cant figure it out
any help please

Not sure if I understand it correctly. Do you mean you want to copy the file <directory>/<episode_name>.<ISO-639 2-letter>.srt to <directory>/<episode_name>.1.srt?

@lukjod
Copy link

lukjod commented Sep 29, 2019

Yes, thank You i finally used very similiar string to rename those files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment