Sunday, March 16, 2014

第一個shell script,批次用megadl下載MEGA免費空間資源

0

切換到全linux的作業環境後,很多應用程式都能找到替代方案,唯獨論壇上免空資源的 下載器,大多是為了廣大的windows用戶所撰寫,自己常下載的免空大老"MEGA"就是其中 一例,windows上可以利用MegaDownloader自動排程下載,linux下目前只有看到Megatools 這套cml界面的工具可用,而且裡面只有一個cmd是用來下載他人分享的內容,其餘都是用 來對自己的空間坐上傳,下載,查詢等等,與原來windows下的MegaDownloader功能相去甚遠。

Megatools裡頭用來下載remote file的manual大致如下:

megals(1) megatools manual megals(1)

name

megadl - download exported files and directories from mega.co.nz

synopsis

       megadl [--no-progress] [--path <path>] <links>...
       megadl --path - <filelink>

description

downloads exported files and folders from mega.co.nz. handles links like:

· https://mega.co.nz/#!7yvwhczz!baublakkkvv8him-8-qfmgoys289toqwn7rgfpzxb_w

· https://mega.co.nz/#f!hilfdajt!hlivvqqkse1d0ogxzuaojg

       when downloading individual files, these are placed into <path>. when downloading folders, the contents of the folder are placed into directory
       specified by <path>.

       to export files, you can use mega.co.nz web application, or megals(1)'s --export option.

options

       --path <path>
           local directory to download to. defaults to the current working directory.

           if <path> is -, remote file will be streamed to stdout.

       --no-progress
           disable download progress reporting. this is implied when streaming.

       --debug [<options>]
           Enable debugging of various aspects of the megatools operation. You may enable multiple debugging options separated by commas. (eg.  --debug
           api,fs)

           Available options are:

           ·    api: Dump Mega.co.nz API calls

           ·    fs: Dump Mega.co.nz filesystem (may require --reload to actually print something)

           ·    cache: Dump cache contents

       --version
           Show version information

       <links>
           File and folder links to download from.

       <filelink>
           Link to exported file to stream.

例如要下載一個連結為 https://mega.co.nz/#!7YVWhCzZ!bauBlAkKKvv8hIm-8-qFmGOYS289ToQWN7rGFPzXB_wf的檔案 megadl 'https://mega.co.nz/#!7YVWhCzZ!bauBlAkKKvv8hIm-8-qFmGOYS289ToQWN7rGFPzXB_w'

如果我有一連串的連結我就要手動作N次,很沒效率 剛好最近有接觸到shell script,就用他來批次化完成吧 先看code:

#! /bin/bash

cd /media/G;

filename="$1";
passcode="$2";
scriptname=${filename%.*}.sh;

cat $filename | sed 's/^/megadl /' | awk -v q="'" '{print $1 " " q$2q }' >$scriptname; echo "$scriptname" be created;

sh $scriptname;

echo Download finish remove "$scriptname"; rm $scriptname;

0 comments :

Post a Comment