Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- A small script used to organise downloaded anime episodes.
- Moves .mkv files from folderA to folderB such that folderB contains
- sub-folders where each sub-folder is the name of the anime series.
- """
- import os
- import shutil
- import anitopy
- def main():
- """
- Main method to run the script.
- return: Integer, the total number of episodes moved.
- """
- print("{:<55}" .format("EPISODES MOVED"))
- print("{:-<59}".format(""))
- numMoved = 0
- downloaded = [f for f in os.listdir(TARGET) if f.endswith(".mkv")]
- for episode in downloaded:
- # Parsing data using Anitopy library
- data = anitopy.parse(episode)
- title = data["anime_title"]
- num = data["episode_number"]
- # Creates an anime subfolder if it doesn't exist already
- animeDir = os.path.join(DESTINATION, title)
- if not os.path.exists(animeDir):
- os.makedirs(animeDir)
- # Moves anime episodes into the correct subfolder
- subFolders = os.listdir(DESTINATION)
- for sf in subFolders:
- if title.find(sf) != -1:
- move(episode, sf)
- numMoved += 1
- print("{:<55} {}" .format(title, num))
- print("\nTOTAL MOVED: {}".format(numMoved))
- def move(episode, animeDir):
- """
- Moves the episode file into the correct directory.
- :param episode: String, the name of the episode to move.
- :param animeDir: String, the name of the directory to move into.
- :return:
- """
- tPath = os.path.join(TARGET, episode)
- dPath = os.path.join(DESTINATION, animeDir, episode)
- shutil.move(tPath, dPath)
- if __name__ == "__main__":
- # CHANGE THESE PATHS AS NEEDED
- TARGET = "C:\\Users\\OzAli\\Desktop"
- DESTINATION = "D:\\Anime"
- print()
- main()
- print("TARGET PATH: {}".format(TARGET))
- print("DESTINATION PATH: {}".format(DESTINATION))
Add Comment
Please, Sign In to add comment