compare file

    0

    0

    KBC In

    #!/usr/bin/env python3

    def fixMySubtitles(mediaFolderPath):

    Lists all the files in the folder

    files = os.listdir(mediaFolderPath)

    Loops through every single file in the directory

    for file in files: # In the beginning we set both names to "" since we don't know what they are yet. movie = "" subtitle = ""

    # If searches the current file name to see if it ends in .ass
    if re.search(r'\.ass', file):
      # This removes the .ass part from the subtitle name
      subtitle = re.search(r'(.*).ass', file).group(1)
    
      # This chunk matches the subtitle file to the movie file
      movie = [movie for movie in files if subtitle in movie]
      movie = [movie for movie in movie if '.mkv' in movie]
      movie = "".join(movie)
    
    import os
    import re
    
    # taken from https://stackoverflow.com/a/54733386/13914534
    
    #!/usr/bin/env python3
    
    def fixMySubtitles(mediaFolderPath):
      # Lists all the files in the folder
      files = os.listdir(mediaFolderPath)
    
      # Loops through every single file in the directory
      for file in files:
        # In the beginning we set both names to "" since we don't know what they are yet.
        movie = ""
        subtitle = ""
    
        # If searches the current file name to see if it ends in .ass
        if re.search(r'\.ass', file):
          # This removes the .ass part from the subtitle name
          subtitle = re.search(r'(.*).ass', file).group(1)
    
          # This chunk matches the subtitle file to the movie file
          movie = [movie for movie in files if subtitle in movie]
          movie = [movie for movie in movie if '.mkv' in movie]
          movie = "".join(movie)
    
          # Now we try to get the movie without the .mkv part
          try:
            movie = re.search(r'(.*).mkv', movie).group(1)
          except:
            print("Movie not found error for subtitle '%s'" % (file))
            break
    
          # Lastly we can set the path of the new subtitle file
          newPath = os.path.join(mediaFolderPath, "%s.ass" % (movie))
    
          # And if the movie variable has a value then we can rename
          if movie:
            os.rename(os.path.join(mediaFolderPath, file), newPath)
    
      print("I have fixed your subtitles!")
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.