Пример #1
0
def multipleDownload(driver, listFileName=""):
    num = 0
    total_download = 0
    while (1):
        [count, id] = count_file_lines_and_first_line(listFileName)
        if count == 0:
            break
        total_download = total_download + 1
        print("############# 다운로드 갯수 / 남은 갯수  [%d / %d] ###############" %
              (total_download, count))
        print("ID : %s" % (id))
        config = Config()
        comicsDownload(driver, id, config.getDownloadPath())
        saveListFile(listFileName, id)

    print("Done.....")
Пример #2
0
def chapterListParser(driver, mangaId):
    # 만화의 챕터 목록 가져 오기
    c = Config()
    url = c.getDomain() + base_url + mangaId
    publish_type = ""
    tags = []
    author = ""

    wait = WebDriverWait(driver, 10)
    try:
        driver.get(url)
        wait.until(
            EC.presence_of_element_located(
                (By.CSS_SELECTOR, '.control-sidebar-bg')))
        driver.execute_script("window.stop();")
    except Exception:
        reconnect(driver)
        return chapterListParser(driver, mangaId)

    chapterList = []
    valid = True
    chapterList, valid = parseChaterList(driver)
    if len(chapterList) == 0 and valid == True:
        retry_wait(6, "[도서 목록] ")
        chapterList, valid = parseChaterList(driver)
        if len(chapterList) == 0:
            return chapterListParser(driver, mangaId)

    if not valid:
        print("잘 못 된 URL입니다.")
        return [], publish_type, tags, author

    html = driver.page_source
    bs = BeautifulSoup(html, "html.parser")
    publish_type = publishType(bs)
    tags = publishTags(bs)
    author = publishAuthor(bs)
    title = publishTitle(bs)

    data = []
    for slot in reversed(chapterList):
        text = slot.getText().strip()
        text = pathName(text)
        data.append({"title": text, "href": slot["href"]})

    return data, publish_type, tags, author, title
Пример #3
0
def filterDownloadedList(folerList, driver, page):
    c = Config()
    wait = WebDriverWait(driver, 30)
    print(LIST_URL % (c.getDomain(), page))
    driver.get(LIST_URL % (c.getDomain(), page))
    wait.until(
        EC.presence_of_element_located((By.CSS_SELECTOR, '#thema_wrapper')))
    driver.execute_script("window.stop();")

    updateList = parseList(folerList, driver)

    # if len(updateList) == 0:
    #     retry_wait(7, "[업데이트목록] ")
    #     updateList = parseList(folerList, driver)
    #     if len(updateList) == 0:
    #         return filterDownloadedList(folerList, driver, page)

    return updateList
Пример #4
0
def arguments():
    # 외부 파라미터 받기
    isUpdate = False
    isUpdateAll = False
    updateSize = 3
    downloadFile = ""
    listSize = 0

    try:
        opts, _ = getopt.getopt(sys.argv[1:], "c:s:d:l:uh:ah", [
            "help", "all", "update", "config=", "size=", "download=", "list="
        ])
    except getopt.GetoptError as err:
        print(str(err))
        print("")
        usage()
        sys.exit(2)

    defaultIni = "manatoki.ini"
    if os.path.exists(defaultIni):
        config = Config()
        config.loadConfig(defaultIni)
    else:
        print("ERROR: Cant not find config.ini")
        exit()

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-u", "--update"):
            isUpdate = True
        elif opt in ("-a", "--all"):
            isUpdateAll = True
        elif opt in ("-s", "--size"):
            updateSize = int(arg)
        elif opt in ("-d", "--download"):
            downloadFile = arg
        elif opt in ("-l", "--list"):
            listSize = arg

    return isUpdate, isUpdateAll, updateSize, downloadFile, listSize
Пример #5
0
def addClipToText(str):
    global clip
    if (clip == str):
        return
    config = Config()
    if 'manatoki' not in str:
        return
    clip = str
    # q = parse_qs(urlparse(str).query).get('manga_id')
    a = clip.split('/')
    last = a[len(a) - 1].split('?')
    id = last[0]
    print("ID : " + id)
    f = open("list.txt", "a")
    f.write(id + "\r")
    f.close()
Пример #6
0
        saveListFile(listFileName, id)

    print("Done.....")


if __name__ == '__main__':
    multiprocessing.freeze_support()  # ! 꼭 바로 다음줄에 넣어 줘야 한다.

    isUpdate, isUpdateAll, updateSize, downloadFile, listSize = arguments()

    # if int(listSize) > 0:
    #   getComicsList(int(listSize))
    #   exit(1)

    driver = None
    config = Config()

    if isUpdate:
        # 업데이트 일 경우
        driver = driver_init()
        updatedList = getUpdateList(driver, updateSize)
        save_update_list(downloadFile, updatedList)
        multipleDownload(driver, downloadFile)
    elif isUpdateAll:
        driver = driver_init()
        # updatedList = checkAllDownload()
        # multipleDownload(driver, updatedList)
    elif downloadFile != "":
        # 파일에서 다운로드 목록 확인
        driver = driver_init()
        multipleDownload(driver, downloadFile)
Пример #7
0
def loadConfig():
    defaultIni = "manatoki.ini"
    if os.path.exists(defaultIni):
        config = Config()
        config.loadConfig(defaultIni)
        print(config.getDomain())
Пример #8
0
def comicsDownload(driver, mangaId, downloadFolder):
    # 만화책에서 이미지 목록을 가져 와서 다운로드 하기
    chaterList, public_type, tags, author, title = chapterListParser(
        driver, mangaId)
    global imageDownloadTryCount

    if len(chaterList) == 0:
        print("[Error] 이미지를 찾을 수 없습니다. 타이틀을 확인 해 주세요.")
        return

    titlePath = os.path.join(downloadFolder, pathName(title))

    pathlib.Path(titlePath).mkdir(parents=True, exist_ok=True)
    os.utime(pathlib.Path(titlePath), None)
    skip_num = 0
    saveData = loadJsonFile(os.path.join(titlePath, "data.json"))
    if saveData:
        skip_num = int(saveData["skip"])

    num = 1
    for d in chaterList:
        c = Config()
        url = d["href"]
        if skip_num >= num:
            print("[" + str(num) + "/" + str(len(chaterList)) + "] 패스 : " +
                  d["title"],
                  end="\r")
            num = num + 1
            continue
        savePath = saveFolderPath(titlePath, num)
        print(" " * 80, end="\r")
        print("[" + str(num) + "/" + str(len(chaterList)) + "] 다운로드 : " +
              d["title"])
        num = num + 1
        if os.path.exists(savePath + "." +
                          c.getFileExtension()) or os.path.exists(savePath +
                                                                  ".zip"):
            print("  이미 압축한 파일 :" + d["title"])
            continue
        print("  Get image list by url..", end="\r")

        imageDownloadTryCount = 0
        images, chapter, seed = getImageList(driver, url)
        print("  Download images..      ", end="\r")

        if len(images) == 0:
            print("  이미지를 찾을 수 없습니다. 패스")
            continue
        imagesDownload(d["title"], savePath, images, chapter, seed)

        # 최근 받은 파일을 JSON으로 저장하기
        json = {
            'author': author,
            'skip': num - 1,
            'title': title,
            'public_type': public_type,
            'tags': tags,
            'id': mangaId
        }
        saveJsonFile(os.path.join(titlePath, "data.json"), json)

    # 완결인 책자를 별도로 저장해 준다.
    if public_type == "완결" or public_type == "단편":
        print("#" * 80)
        print("#" * 2 + " 완결: " + title)
        print("#" * 80)
        title = pathName(title)
        tar = os.path.join("complete", title)
        pathlib.Path(os.path.join("complete")).mkdir(parents=True,
                                                     exist_ok=True)
        if os.path.exists(tar):
            shutil.rmtree(tar, ignore_errors=True)
        shutil.move(titlePath, tar)
        shutil.rmtree(titlePath, ignore_errors=True)

    print("[*] Download Complete")