def move_media_file(media_file, video_dir): """ This function moves media_file to the required destination and finds the appropriate folder (dst) recursively. If this file cannot be found make_directory is called to create one. It returns True if media_file is moved appropriately or if media_file does not have a listed extension. It returns False if it is a appropriate extension but does move. string, string -> Bool :param video_dir: :param media_file: """ media_file_list = string.split(media_file, '/') if vou.is_required_format(media_file): print "Looking for a directory" dst = find_directory(media_file, video_dir) if dst is not None: print "Attempting to move " + media_file_list[-1] shutil.move(media_file, dst) return True else: print "Attempting to move " + media_file_list[-1] dst = make_directory(media_file, video_dir) subprocess.call(["cp", media_file, dst]) # shutil.move(media_file, dst) return True return False
def move_from_orig(start_path): """ Moves media files from original torrent directories to a season dir and then deletes the original torrent dir. Note this relies on the media file containing a substring in its name of the form S(x)E(y) or s(x)e(y). Files with other naming formats will be left alone. string -> None :param start_path: """ contents = os.listdir(start_path) # Find the dirs that are not season dirs. for item in contents: item_path = vou.get_new_path(start_path, item) if not vou.is_season_indicator(item) and os.path.isdir(item_path): item_contents = os.listdir(item_path) # Find the media files in the dirs. for item2 in item_contents: if vou.is_required_format(item2): item2_path = vou.get_new_path(item_path, item2) # Find the season the media file belongs to. item2_list = string.split(item2, '.') for i in item2_list: if vou.is_season_indicator(i): season = i[0:3] season_path = vou.get_new_path(start_path, season) # Make season dir if it doesn't exist. if not os.path.isdir(season_path): os.mkdir(season_path) # Move media file by renaming. new_item2_path = vou.get_new_path(season_path, item2) os.rename(item2_path, new_item2_path) break break return None
def move_actual_media(start_path): """ Moves a media file directly in a title dir to a season dir. Note this relies on the media file containing a substring in its name of the form S(x)E(y) or s(x)e(y). Files with other naming formats will be left alone. string -> None :param start_path: """ contents = os.listdir(start_path) for item in contents: # Find the media files in contents. if vou.is_required_format(item): item_path = vou.get_new_path(start_path, item) item_list = string.split(item, '.') # Determine the season this file belongs to. for i in item_list: if vou.is_season_indicator(i): season = i[0:3] season_path = vou.get_new_path(start_path, season) # Makes season dir if it doesn't exist. if not os.path.isdir(season_path): os.mkdir(season_path) # Move media file by renaming. new_item_path = vou.get_new_path(season_path, item) os.rename(item_path, new_item_path) break break return None