Example #1
0
class Main:
    def __init__(self):
        self.soupHandler = SoupHandler(SystemInfo.initUri)
        self.downloader = Downloader()
        self.fileHandler = FileHandler()
        self.path = SystemInfo.path
        self.name = SystemInfo.name

    def introduce(self):
        print("kocw 다운로드 프로그램.")
        print("대학교 자체 cdn 전용입니다.")
        print("url 수정은 소스코드를 직접 수정하세요.")

    def end(self):
        print("다운로드 완료 되었습니다.")

    def run(self):
        self.introduce()

        self.fileHandler.safeMkdir("%s/output" % self.path)
        self.fileHandler.safeMkdir("%s/output/%s" % (self.path, self.name))

        table = self.soupHandler.findTable()
        parsedOnClickStrings = self.soupHandler.parseOnClick(table)
        self.downloader.startIteratingDownload(parsedOnClickStrings)

        self.end()
Example #2
0
class Downloader:
    def __init__(self):
        self.path = SystemInfo.path
        self.name = SystemInfo.name
        self.videoUriFormat = SystemInfo.videoUriFormat
        self.fileHandler = FileHandler()
        self.strParser = StrParser()

    def startIteratingDownload(self, parsedOnclicks):
        count = 0
        for line in parsedOnclicks:
            count += 1

            uri = self.strParser.findSubStr(line, "'", "'")
            print(uri)

            if not SystemInfo.pdfIncluded or count % 2 == 1:
                code = uri.split("/")[-1]
                self.fileHandler.safeMkdir("%s/output/%s/video" %
                                           (self.path, self.name))
                downloadUri = self.videoUriFormat % code
                print("%s 다운로드 중..." % (downloadUri))
                res = requests.get(downloadUri)
                if SystemInfo.pdfIncluded:
                    number = (count + 1) // 2
                self.fileHandler.saveBinaryFile(res.content, "video", number,
                                                "mp4")
            else:
                print("%s 다운로드 중..." % uri)
                res = requests.get(uri)
                self.fileHandler.safeMkdir("%s/output/%s/pdf" %
                                           (self.path, self.name))
                number = (count + 1) // 2
                self.fileHandler.saveBinaryFile(res.content, "pdf", number,
                                                "pdf")