批量转换 epub 至 mobi 文件

Windows

# 下载 Calibre , 找到 ebook-convert.exe
# https://calibre-ebook.com/download

$app = ".\ebook-convert.exe" #  ebook-convert.exe 路径 
$root = ".\epub\" # 电子书路径 

Get-ChildItem "$root\*.epub" | %  FullName | % {

    $newPath = [System.IO.Path]::ChangeExtension($_, ".mobi")

    if (-not [System.IO.File]::Exists($newPath))
    {
        & $app $_ $newPath
        if (-not $?)
        {
            throw [System.ApplicationException]::new("文件 $_ 转换失败")
        }
    }
}

Ubuntu

# 安装 
sudo -v && wget --no-check-certificate -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin

$root = $(xdg-user-dir DOWNLOAD)

$bookRoot = Join-Path $root -ChildPath "epub"

if(-not (Test-Path $bookRoot)){
    throw [System.IO.FileNotFoundException]::new("电子书目录不存在")
}

$books = Get-ChildItem $bookRoot -Filter *.epub

$books | % {

    $path = $_.FullName
    $newPath = [System.IO.Path]::ChangeExtension($path, ".mobi")
    if (-not (Test-Path $newPath)) {
        & "ebook-convert" $path $newPath
        if (-not $?) {
            throw [System.ApplicationException]::new("文件 $path 转换失败")
        }
    }
}
上一篇
下一篇