1 | # 自動排程
|
2 |
|
3 | 寫一個搭配自動排程檢查並下載我要的字幕組是這個工具的初衷,下面介紹幾種搭配排程的方法。
|
4 |
|
5 | * [Linux cron/crontab](#Linux-croncrontab)
|
6 | * [Windows 10 排程](#Windows-10-排程)
|
7 | * [pm2](#pm2)
|
8 |
|
9 | ## Linux cron/crontab
|
10 |
|
11 | 確定 `dmhy-subscribe` 確實安裝完成:
|
12 |
|
13 | ```bash
|
14 | $ dmhy --version
|
15 | 0.6.0 # 有版本跳出來
|
16 | ```
|
17 |
|
18 | 加入到 crontab
|
19 |
|
20 | ```bash
|
21 | $ (crontab -l 2>/dev/null; echo "0 * * * * `which dmhy`") | crontab -
|
22 | ```
|
23 |
|
24 | 其中 `0 * * * *` 為 cron 語法,表示每小時 0 分時執行,語法詳細請參考[鳥哥](http://linux.vbird.org/linux_basic/0430cron.php#crontab)的介紹
|
25 |
|
26 | ## Windows 10 排程
|
27 |
|
28 | 到 PowerShell 執行並記住 Source 路徑
|
29 |
|
30 | ```powershell
|
31 | PS C:\> Get-Command dmhy
|
32 | ```
|
33 |
|
34 | 1. 執行 `taskschd.msc` 或是 Windows 10 的尋找功能打 `工作排程器` 即可開啟
|
35 | 2. 建立基本工作 {名稱: 隨便, 描述:隨便} → 下一步
|
36 | 3. 每天 (之後可以調整) → 下一步 → (開始時間之後可以調整) → 下一步
|
37 | 4. 動作:啟動程式 → 下一步
|
38 | 5. {程式路徑:剛剛的 Source 路徑} → 完成
|
39 | 6. 之後可到左邊側欄的 `工作排程器程式庫` 找到這個工作重新設定
|
40 |
|
41 | 測試是否成功
|
42 |
|
43 | 1. 到 PowerShell 隨便新增一筆訂閱
|
44 |
|
45 | ```powershell
|
46 | PS C:\> dmhy add "搖曳露營,喵萌,繁體"
|
47 | PS C:\> dmhy ls
|
48 | 訂閱識別碼 最新集數 標題
|
49 | --------- -------- ---------
|
50 | ALR -- 搖曳露營
|
51 | ```
|
52 |
|
53 | 2. 到 `工作排程器程式庫` 找到這個工作 → 右鍵[執行]
|
54 | 3. 在輸入一次 `dmhy ls`,有最新集數就成功了
|
55 |
|
56 | ```powershell
|
57 | PS C:\> dmhy ls
|
58 | 訂閱識別碼 最新集數 標題
|
59 | --------- -------- ---------
|
60 | ALR 12 搖曳露營
|
61 | ```
|
62 |
|
63 | ## pm2
|
64 |
|
65 | 這是個好東西,至少在 Linux 上很方便,Windows 10 就不推薦了,安裝跟指令都很麻煩 zzz
|
66 |
|
67 | (2018.08) 最近 pm2 有 3.x 版的更新,但實測後發現他的 cron 功能有點問題,故若要使用 pm2 者可指定 2.x 版
|
68 |
|
69 | Ubuntu:
|
70 |
|
71 | ```bash
|
72 | $ npm i -g pm2@2
|
73 | $ pm2 start `which dmhy` --cron="0 * * * *"
|
74 | 或
|
75 | $ pm2 start `which dmhy` --cron="0 * * * *" -- --no-dl # -- 之後的參數傳到 dmhy
|
76 | ```
|