import re
import os

import pytvdbapi.api as tvdb


class Renamer:
    def __init__(self, api_key):
        self.tvdb = tvdb.TVDB(api_key)

    @staticmethod
    def flat_file_list(directory):
        directory = os.path.normpath(directory)

        for dirpath, dirnames, filenames in os.walk(directory):
            for filename in filenames:
                full_path = os.path.join(dirpath, filename)
                # remove directory from the start of the full path
                full_path = full_path[len(directory)+1:]
                yield full_path

    def rename_table(self, directory, input_regex, output_format):
        input_pattern = re.compile(input_regex)

        filenames = self.flat_file_list(directory)
        for filename in filenames:
            thing = input_pattern.search(filename)
            if thing is not None:
                params = thing.groupdict()
                output_filename = output_format.format(**params)
                yield filename, output_filename

import re
import os

import pytvdbapi.api as tvdb


class Renamer:
    def __init__(self, api_key):
        self.tvdb = tvdb.TVDB(api_key)

    @staticmethod
    def flat_file_list(directory):
        directory = os.path.normpath(directory)

        for dirpath, dirnames, filenames in os.walk(directory):
            for filename in filenames:
                full_path = os.path.join(dirpath, filename)
                # remove directory from the start of the full path
                full_path = full_path[len(directory)+1:]
                yield full_path

    @staticmethod
    def normalise_params(params):
        def normalise(key, value):
            if key == "show":
                return str(value)
            elif key in ["episode", "season"]:
                return int(value)
            else:
                raise ValueError("Unknown parameter: '{}'".format(key))

        return {key: normalise(key, value) for key, value in params.items()}

    def rename_table(self, directory, input_regex, output_format):
        input_pattern = re.compile(input_regex)

        filenames = self.flat_file_list(directory)
        for filename in filenames:
            thing = input_pattern.search(filename)
            if thing is not None:
                params = self.normalise_params(thing.groupdict())
                output_filename = output_format.format(**params)
                yield filename, output_filename

Add normalising params from the regex input
Add normalising params from the regex input

  import re
  import os
  
  import pytvdbapi.api as tvdb
  
  
  class Renamer:
      def __init__(self, api_key):
          self.tvdb = tvdb.TVDB(api_key)
  
      @staticmethod
      def flat_file_list(directory):
          directory = os.path.normpath(directory)
  
          for dirpath, dirnames, filenames in os.walk(directory):
              for filename in filenames:
                  full_path = os.path.join(dirpath, filename)
                  # remove directory from the start of the full path
                  full_path = full_path[len(directory)+1:]
                  yield full_path
  
+     @staticmethod
+     def normalise_params(params):
+         def normalise(key, value):
+             if key == "show":
+                 return str(value)
+             elif key in ["episode", "season"]:
+                 return int(value)
+             else:
+                 raise ValueError("Unknown parameter: '{}'".format(key))
+ 
+         return {key: normalise(key, value) for key, value in params.items()}
+ 
      def rename_table(self, directory, input_regex, output_format):
          input_pattern = re.compile(input_regex)
  
          filenames = self.flat_file_list(directory)
          for filename in filenames:
              thing = input_pattern.search(filename)
              if thing is not None:
-                 params = thing.groupdict()
+                 params = self.normalise_params(thing.groupdict())
                  output_filename = output_format.format(**params)
                  yield filename, output_filename
  
Add normalising params from the regex input
## Code Before:
import re
import os

import pytvdbapi.api as tvdb


class Renamer:
    def __init__(self, api_key):
        self.tvdb = tvdb.TVDB(api_key)

    @staticmethod
    def flat_file_list(directory):
        directory = os.path.normpath(directory)

        for dirpath, dirnames, filenames in os.walk(directory):
            for filename in filenames:
                full_path = os.path.join(dirpath, filename)
                # remove directory from the start of the full path
                full_path = full_path[len(directory)+1:]
                yield full_path

    def rename_table(self, directory, input_regex, output_format):
        input_pattern = re.compile(input_regex)

        filenames = self.flat_file_list(directory)
        for filename in filenames:
            thing = input_pattern.search(filename)
            if thing is not None:
                params = thing.groupdict()
                output_filename = output_format.format(**params)
                yield filename, output_filename

## Instruction:
Add normalising params from the regex input
## Code After:
import re
import os

import pytvdbapi.api as tvdb


class Renamer:
    def __init__(self, api_key):
        self.tvdb = tvdb.TVDB(api_key)

    @staticmethod
    def flat_file_list(directory):
        directory = os.path.normpath(directory)

        for dirpath, dirnames, filenames in os.walk(directory):
            for filename in filenames:
                full_path = os.path.join(dirpath, filename)
                # remove directory from the start of the full path
                full_path = full_path[len(directory)+1:]
                yield full_path

    @staticmethod
    def normalise_params(params):
        def normalise(key, value):
            if key == "show":
                return str(value)
            elif key in ["episode", "season"]:
                return int(value)
            else:
                raise ValueError("Unknown parameter: '{}'".format(key))

        return {key: normalise(key, value) for key, value in params.items()}

    def rename_table(self, directory, input_regex, output_format):
        input_pattern = re.compile(input_regex)

        filenames = self.flat_file_list(directory)
        for filename in filenames:
            thing = input_pattern.search(filename)
            if thing is not None:
                params = self.normalise_params(thing.groupdict())
                output_filename = output_format.format(**params)
                yield filename, output_filename
