• j0_674945
  • 6.4KB
  • zip
  • 0
  • VIP专享
  • 0
  • 2022-05-28 05:46
超速驾驶 OverDrive很棒,可以分发不含DRM的MP3,而不是分发一些脆弱的DRM格式,这真是太棒了。 要走的路,乐天/ OverDrive,打男人! 他们针对macOS的“ OverDrive Media Console”应用程序非常简单……如此简单,我想,为什么要有一个应用程序? 因此,我编写了一个shell脚本 ,该脚本接受一个或多个.odm文件(只是XML),然后像应用程序一样在本地下载音频内容文件。 安装 下面将把独立脚本安装到~/.local/bin并将其标记为可执行: mkdir -p ~ /.local/bin curl https://chbrown.github.io/overdrive/overdrive.sh -o ~ /.local/bin/overdrive chmod +x ~ /.local/bin/overdrive 此时,如果调用overd
  • overdrive-master
  • README.md
  • overdrive.sh
# OverDrive OverDrive is great and distributes DRM-free MP3s instead of some fragile DRM-ridden format, which is awesome. Way to go, Rakuten / OverDrive, fight the man! Their "OverDrive Media Console" application for macOS is pretty simple... so simple, I'm like, why have an app? So I wrote a shell script, [`overdrive.sh`](overdrive.sh), which takes one or more `.odm` files (which are just XML), and downloads the audio content files locally, just like the app. ## Install The following will install the standalone script into `~/.local/bin` and mark it executable: ```sh mkdir -p ~/.local/bin curl https://chbrown.github.io/overdrive/overdrive.sh -o ~/.local/bin/overdrive chmod +x ~/.local/bin/overdrive ``` At this point, if calling `overdrive` produces the error message `-bash: overdrive: command not found`, you'll need to add `~/.local/bin` to your `PATH`. One way to do this: ```sh printf 'export PATH=$HOME/.local/bin:$PATH\n' >> ~/.bashrc source ~/.bashrc ``` **_N.b.:_ if you're using `zsh`** instead of `bash`, run this instead: ```sh printf 'export PATH=$HOME/.local/bin:$PATH\n' >> ~/.zshrc source ~/.zshrc ``` Now you should be able to run `overdrive --help` and use the commands described below... ## Instructions Download an OverDrive loan file from your library or wherever. I'll assume that yours is called `Novel.odm`. Assuming you've downloaded it to your `~/Downloads` folder, simply run the following command: cd ~/Downloads overdrive download Novel.odm When you run that, the script first checks if there is already a `Novel.odm.license` file alongside `Novel.odm`. If that file already exists, the script will not request a new license, since the OverDrive server will only grant one license per `.odm` loan. If not, it will request the license from the OverDrive server and write it to a new `Novel.odm.license` file, by performing the following actions: 1. Extract the `AcquisitionUrl` and `MediaID` from the `Novel.odm` file. 2. Compute a Base64-encoded SHA-1 hash from a few `|`-separated values and a suffix of `OVERDRIVE*MEDIA*CONSOLE`, but backwards. (Thanks to https://github.com/jvolkening/gloc for somehow figuring out how to construct that hash!) 3. Using those values and a randomly generated `ClientID` GUID, it submits a request to the OverDrive server to get the full license for this book, which is an XML file that has a `<License>` element at the root. That element contains a long Base64-encoded `<Signature>`, which is subsequently used to request the content files. Now, license in hand, the script downloads the audio content files by taking the following steps: 4. Extract the `Title` and `Author` values from the `CDATA` content nested in `Novel.odm`. 5. For each of the parts of the book listed in `Novel.odm`, make a request to another OverDrive endpoint, which will validate the request and redirect to the actual MP3 file on their CDN, and save the result into a folder in the current directory, named like `Author - Title/Part0N.mp3`. \ _N.b.:_ These "parts" don't necessarily correspond to actual chapters in the book; there may be multiple chapters in a single part, or a single chapter spread out over multiple parts. ### Returning The OverDrive format makes "returning" a loan extremely simple. All you have to do is request the URL specified by the `<EarlyReturnURL>` element in the loan file. The `return` command does exactly that, e.g.: overdrive return Novel.odm ### Debugging If you have trouble getting the script to run successfully, add the `--verbose` flag and retry, e.g.: overdrive download Novel.odm --verbose This will call `set -x` to turn bash's `xtrace` option on, which causes a trace of all commands to be printed to standard error, prefixed with one or more `+` signs. If that doesn't help you debug the problem, [open an issue](https://github.com/chbrown/overdrive/issues/new), including the full debug output (optimally as a [gist](https://gist.github.com/)), and I'll try to help you out. #### F.A.Q. - Q: I got an error message like `-bash: ~/.local/bin/overdrive: Permission denied` or `zsh: permission denied: overdrive`; what's wrong? \ A: You installed `overdrive` to the right place 👍, but didn't set the executable flag 😟. Try running the `chmod +x` command from the [Install](#install) steps again. #### Prerequisites This script is tested (i.e., developed and used) on macOS with bash 5.0. It depends on the following executables being available on your `PATH`: * `curl` * `uuidgen` * `xmllint` * `iconv` * `openssl` * `base64` * `tidy` Package manager one-liners (_please create a [PR](https://github.com/chbrown/overdrive/pulls) to contribute a new OS!_): | Command | OS | |:--------|:---| | `brew install openssl tidy-html5` | # macOS<sup>†</sup> | `apt-get install curl uuid-runtime libxml2-utils libc-bin openssl coreutils tidy` | # Debian / Ubuntu | `apk add bash curl util-linux libxml2-utils openssl tidyhtml` | # Alpine | `pacman -S curl util-linux libxml2 openssl coreutils tidy` | # Arch | `dnf install curl glibc-common util-linux libxml2 openssl coreutils tidy` | # Fedora <sup>†</sup>Though this is unnecessary; AFAICT, all required commands are installed by default on macOS 10.14 (Mojave). ## Post-processing The ID3(v2) tagging tool I use is [`mutagen`](https://mutagen.readthedocs.io/), which is used and maintained by the [Quod Libet](https://quodlibet.readthedocs.io/) audio player project. Alternatively, you can use [`ffmpeg`](https://ffmpeg.org/) with [the `-metadata` option](https://git.io/id3-ffmpeg). Unfortunately, it appears that iTunes always loads `.mp3`s as "Music" despite the Genre (there doesn't seem to be any way to import `.mp3`s into iTunes _as_ "Audiobooks"). You have to open iTunes, "Get Info" for the intended songs, and set the "Media Kind" to "Audiobook" manually. ## License Copyright © 2017–2020 Christopher Brown. [MIT Licensed](https://chbrown.github.io/licenses/MIT/#2017-2020).
    • 高级Bash 脚本编程指南
      NULL 博文链接:https://xiajs.iteye.com/blog/1025751
    • bash shell
      NULL 博文链接:https://detox.iteye.com/blog/1882849
    • bash shell
      NULL 博文链接:https://detox.iteye.com/blog/1882849
    • steps-bash-script:已弃用-使用https
      将其输入另存为bash文件并运行。 使用此Bitrise步骤滚动您自己的自定义bash脚本! 此步骤是“步骤库”的一部分,您可以找到其“步骤库”页面 输入: 检查step.yml文件。 笔记: 现在应该使用新的content输入而...
    • Git-bash
      Git-bash:- 安装Git:- 要下载Git: 1.Go to https://git-scm.com/downloads 2.download the software for Windows 3.install Git choosing all the default options 首次Git配置:- 用您的名字设置Git: >>...
    • bash shell
      NULL 博文链接:https://detox.iteye.com/blog/1882849
    • BASH 中的字符串处理
      NULL 博文链接:https://lujinan858.iteye.com/blog/437004
    • bashstyle_examples:Bash示例遵循https上的样式指南
      遵循样式指南的Bash示例,为 包括可重复使用的bash-boilerplate.sh 还通过shellcheck bash* : : (在OSX上brew install shellcheck ) 用法示例: ./bash-example ./bash-example -V ./bash-example bye ...
    • bash shell
      NULL 博文链接:https://detox.iteye.com/blog/1882849
    • bash shell
      NULL 博文链接:https://detox.iteye.com/blog/1882849