當前位置: 首頁>>代碼示例>>Python>>正文


Python Status.add_episode方法代碼示例

本文整理匯總了Python中status.Status.add_episode方法的典型用法代碼示例。如果您正苦於以下問題:Python Status.add_episode方法的具體用法?Python Status.add_episode怎麽用?Python Status.add_episode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在status.Status的用法示例。


在下文中一共展示了Status.add_episode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from status import Status [as 別名]
# 或者: from status.Status import add_episode [as 別名]
class FileAdapter:
    __dir_path = ""
    __plex_path = "/home/matteo/TV Shows/"
    __title_pattern = "(.)*.(s|S)([0-9]+)(e|E)([0-9]+)"
    __file_type_pattern = "(.avi\Z)|(.mkv\Z)|(.mp4\Z)|(.mpg\Z)"
    __series_pattern = "(([a-zA-Z]|\s)+)\s"
    __season_pattern = "((s|S)([0-9]+))"
    __episode_pattern = "((e|E)([0-9]+))"
    __files = []
    __status = None

    def __init__(self, dir_path):
        self.__dir_path = dir_path
        self.__status = Status()

    def set_path(self, dir_path):
        self.__dir_path = dir_path

    def get_path(self):
        return self.__dir_path

    def discover_list_file(self):
        for (dir_path, dir_names, file_names) in os.walk(self.__dir_path):
            for f in file_names:
                or_name, file_name, series, season, episode = self.match_file_name(f)
                if file_name:
                    self.__files.append((dir_path, or_name, file_name, series, season, episode))
        print self.__files

    def match_file_name(self, name):
        file_name = re.search(self.__title_pattern, name)
        file_type = re.search(self.__file_type_pattern, name)
        season = re.search(self.__season_pattern, name)
        episode = re.search(self.__episode_pattern, name)
        if file_name and file_type:
            return name, \
                   string.replace(file_name.group(0), '.', ' ') + file_type.group(0), \
                   (re.search(self.__series_pattern, string.replace(file_name.group(0), '.', ' ')).group(0).rstrip()), \
                   season.group(0), \
                   episode.group(0)
        else:
            return None, None, None, None, None

    def move_file(self):
        current_status = self.__status.get_status()
        if current_status:
            # there is a status file!I need to check if the file are already moved in the plex directory
            for item in self.__files:
                if item[3] in current_status and item[4] in current_status[item[3]] and item[5] in \
                        current_status[item[3]][item[4]]:
                    continue
                else:
                    self.__status.add_episode(item[3], item[4], item[5])
                    if not os.path.exists(self.__plex_path + item[3]):
                        os.makedirs(self.__plex_path + item[3])
                    if not os.path.exists(self.__plex_path + item[3] + "/Season " + item[4][-2:]):
                        os.makedirs(self.__plex_path + item[3] + "/Season " + item[4][-2:])
                    os.rename(item[0] +"/"+ item[1], self.__plex_path + item[3] + "/Season " + item[4][-2:] + "/" + item[2])
        else:
            # EmptyStatus
            for item in self.__files:
                self.__status.add_episode(item[3], item[4], item[5])
                if not os.path.exists(self.__plex_path + item[3]):
                    os.makedirs(self.__plex_path + item[3])
                if not os.path.exists(self.__plex_path + item[3] + "/Season " + item[4][-2:]):
                    os.makedirs(self.__plex_path + item[3] + "/Season " + item[4][-2:])
                os.rename(item[0] + "/" + item[1],
                          self.__plex_path + item[3] + "/Season " + item[4][-2:] + "/" + item[2])

        self.__status.write_status()
開發者ID:mcilibrizzi,項目名稱:FileUtilsRename,代碼行數:72,代碼來源:fileadapter.py


注:本文中的status.Status.add_episode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。