News:

HOT TIP! Commands and groups can be copied and pasted directly from your command editor to the forum, and vice versa. This makes sharing command XML on the forum much easier!

Main Menu

Generic File downloader

Started by Haddood, March 02, 2016, 01:45:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Haddood

based on nime5ter reply in this topic http://voxcommando.com/forum/index.php?topic=1833.msg15942#msg15942
here is a command that can be used to download files ... it needs python plugin ... and takes four payloads

{1} Path, where file to be saved
{2} File name
{3} URL to download from
{4} Overwrite if file exists

Features:
- stores download history in map, there is a command you need enable it to create the map or create it manually.
              - since I use VC on 2 machine as well I store which machine downloaded the file. if you are using version older than 2.216 see http://voxcommando.com/forum/index.php?topic=2507.0
                use 2.216 new command System.GetVar MachineName and store it in a variable ... or you can skip this, just remove the {Var.MachineName} from the map.set
- check if the file exist before downloading it, if overwrite is false it won't download the file - kind of green / bandwidth / possible money saver feature :)

if you find bugs, or enhancement post a reply ...


<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.1.6-->
<command id="297" name="File Downloader" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="{1} Path&#xD;&#xA;{2} File name&#xD;&#xA;{3} URL&#xD;&#xA;{4} Overwrite">
  <action>
    <cmdType>Map.CreateTable</cmdType>
    <params>
      <param>DownloadHistory</param>
    </params>
    <cmdRepeat>0</cmdRepeat>
  </action>
  <action>
    <cmdType>File.Read</cmdType>
    <params>
      <param>{1}\{2}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>LastActionSuccess</ifType>
    <ifParams>&amp;&amp;</ifParams>
    <then>
      <action>
        <cmdType>VcAdvanced.Log</cmdType>
        <params>
          <param>{1}\{2} already exist</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>Map.Set</cmdType>
        <params>
          <param>DownloadHistory</param>
          <param>FileOverwrite</param>
          <param>True</param>
          <param>True</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)Contains(B)</ifType>
    <ifParams>{M:DownloadHistory.FileOverwrite}, {4}&amp;&amp;True</ifParams>
    <then>
      <action>
        <cmdType>PY.ExecString</cmdType>
        <params>
          <param>from System.Net import WebClient; WebClient().DownloadFile(r"{3}",r"{1}\{2}")</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else />
  </if>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>LastActionSuccess</ifType>
    <ifParams>&amp;&amp;</ifParams>
    <then>
      <action>
        <cmdType>Map.Set</cmdType>
        <params>
          <param>DownloadHistory</param>
          <param>{1}\{2}</param>
          <param>{3}, {1}, {2}, {ShortDate}, {LongTime}, {Var.MachineName}</param>
          <param>True</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>VcAdvanced.Log</cmdType>
        <params>
          <param>Error downloading {2} from {3}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <action>
    <cmdType>Map.Set</cmdType>
    <params>
      <param>DownloadHistory</param>
      <param>FileOverwrite</param>
      <param>False</param>
      <param>True</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>file.download</event>
</command>
When Voice command gets tough, use hand gestures

PegLegTV

#1
I'll have to check this out  ::hmm,

I just made a quick little command the other day using PowerShell to download the latest beta version of VC to my Desktop and I was going to ask jitterjames and nime5ter if they could setup a rss notification feed for new beta releases so that way using my command it would automatically download the latest beta to my desktop  when its released:D



PowerShell: Download Latest Betta (Not Automated)
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.1.6-->
<command id="1042" name="VC Beta Downloader" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <params>
      <param>http://voxcommando.com/home/downloads/</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>\shref="(.*?)"\starget.*?BETA</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>VCBeta</param>
      <param>{Match.2.1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>(VC.*?.exe)</param>
      <param />
      <param>{Var.VCBeta}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetLastResult</cmdType>
    <params>
      <param>{Match.1.1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.Replace</cmdType>
    <params>
      <param>%20</param>
      <param>-</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>VCDesk</param>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Launch.CMD</cmdType>
    <params>
      <param>powershell "Invoke-WebRequest {Var.VCBeta} -OutFile C:\Users\USERNAME\Desktop\{Var.VCDesk}"</param>
    </params>
    <cmdRepeat>0</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{Var.VCBeta}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.AddText</cmdType>
    <params>
      <param>{Var.VCDesk}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>

to use this command the download action is disabled, you will need to add your PC Username where it says USERNAME then enable that action

but with your command my command may not even be needed but I'll still post a feature request for the RSS feed  ;)

Haddood

there is an iffft notification, check http://voxcommando.com/forum/index.php?topic=2125.msg19361#msg19361

I love the idea of autodownload new VC version... would be great if we can make it autoinstall :) so VC will get autoupdate like the phone apps :)
When Voice command gets tough, use hand gestures

PegLegTV

from what I was seeing while researching how to download with PowerShell I saw a couple of commands that could also install the item, but I was thinking it would be better to do it manually just in case you get a bad download.

I keep nightly and weekly backups for all my VC Folders, but I didn't think the risk was worth it