aria2-ps-cli
Check-in [82ed973cb1]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:initial set of files
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1:82ed973cb1e81ac88522cb084081acc4e6be8a9d
User & Date: jrtolle 2014-04-21 15:47:25
Context
2014-04-21
15:47
initial set of files Leaf check-in: 82ed973cb1 user: jrtolle tags: trunk
15:34
initial empty check-in check-in: 88937a9a68 user: jrtolle tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added Use-Aria2.psm1.

































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
function aria2_LoadVariables {
	[CmdletBinding(SupportsShouldProcess = $true)]
	param()
	begin {
		$script:aria2ConfigFile = split-path (get-module Use-Aria2).path
		$script:aria2ConfigFile = join-path $script:aria2ConfigFile "aria2.$env:COMPUTERNAME.cfg"
		write-verbose "aria2_LoadVariables : Info: gtasks config file located at '$script:aria2ConfigFile'"
	}
	process {
		write-verbose "aria2_LoadVariables : Info: Initiating global variables"
		$createFile = $false
		if (!(test-path $script:aria2ConfigFile)) {
			write-warning "aria2_LoadVariables : Warning: No file found at '$script:aria2ConfigFile'.  Creating default file"
			aria2_CreateDefaultSettingsFile
			write-host "File with default settings created at '$script:aria2ConfigFile'.  Edit to suit your environment." -foregroundColor Green -backgroundColor Black
			$createFile = $true
			return $createFile
		}
		[string] $configJson = cat (resolve-path $script:aria2ConfigFile)
		$aria2Config = ConvertFrom-Json $configJson
		#script-wide variables
		$aria2ConfigObject = @{}
		foreach ($setting in $aria2Config) {
			$setting | get-member -membertype *property | foreach-object {
				$aria2ConfigObject.($_.name) = $setting.($_.name)
			}
		}
		$aria2ConfigObject.GetEnumerator() | foreach { set-variable -name $_.key -value $_.value -scope script }
		write-verbose "aria2_LoadVariables : Info: variables loaded"
		if ($script:rpc_secret.Length -eq 0) {
			write-verbose "aria2_LoadVariables : Info: RPC Secret required.  Getting it to save as a secure string to the settings file."
			$rpc_secretSecure = read-host "Enter aria2 RPC Secret" -AsSecureString
			$script:rpc_secret = ConvertFrom-SecureString $rpc_secretSecure
			$aria2Config.rpc_secret = $script:rpc_secret
			$aria2ConfigJson = convertto-json $aria2Config -depth 5
			set-content $script:aria2ConfigFile -value $aria2ConfigJson
		}
		if ($http_auth) {
			write-verbose "aria2_LoadVariables : Info: HTTP Authorization required.  Checking for username and password and getting if necessary to save as a secure string to the settings file."
			if (($script:http_username.Length -eq 0) -or ($script:http_password.Length -eq 0)) {
				write-warning "aria2_LoadVariables : Warning: HTTP Authorization required.  Provide username and password."
				$script:http_username = read-host "Enter aria2 HTTP username"
				$http_passSecure = read-host "Enter aria2 HTTP password" -AsSecureString
				$script:http_password = ConvertFrom-SecureString $http_passSecure
				$aria2Config.http_username = $script:http_username
				$aria2Config.http_password = $script:http_password
				$aria2ConfigJson = convertto-json $aria2Config -depth 5
				set-content $script:aria2ConfigFile -value $aria2ConfigJson
			}
			$rpc_secretSecure = ConvertTo-SecureString $script:rpc_secret
			$rpc_cred = New-Object System.Management.Automation.PSCredential -ArgumentList "server\boo", $rpc_secretSecure
			$script:rpc_secret = $rpc_cred.GetNetworkCredential().Password
			$http_passSecure = ConvertTo-SecureString $script:http_password
			$script:http_cred = New-Object System.Management.Automation.PSCredential -ArgumentList $script:http_username, $http_passSecure
		}
		return $createFile
	}
	end { $rpc_cred = $null}
}

function aria2_CreateDefaultSettingsFile {
	[CmdletBinding(SupportsShouldProcess = $true)]
	param()
	begin {}
	process {
		if (!(test-path $script:aria2ConfigFile)) {
			$json = @{}
			$json.id = "ps-cli"
			$json.jsonrpc = "2.0"
			$json.jsonrpc_url = "http://aria2.server.com:port/jsonrpc"
			$json.rpc_secret = ""
			$json.http_auth = $false
			$json.http_username = ""
			$json.http_password = ""
			$json.http_timeout = 30
			$json = convertto-json $json -depth 5
			set-content $script:aria2ConfigFile -value $json
		}
		else {
			write-warning "aria2_CreateDefaultSettingsFile : Warning: Default config file already exists at '$script:aria2ConfigFile'.  Edit that file as necessary."
		}
	}
	end {}
}

function Get-Aria2TellActive {
	<#
	.SYNOPSIS
	Retrieves list of active downloads in a running aria2 instance.
	
	.DESCRIPTION
	Retrieves list of active downloads in a running aria2 instance.  By default, returns gid, dir, files, completedLength, uploadLength, downloadSpeed, uploadSpeed, connections, bittorrent, infoHash, numPieces, numSeeders, pieceLength, status, totalLength.  The return information varies based on download type (bittorent, http/ftp, metalink).  See -keys parameter to specify for details on available return information.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER keys
	Array of keywords used to return specific information.  This list is sorted by type, with @() representing a sub-array.  Key names are case-sensitive.
	gid, status, dir, files,
	totalLength, completedLength, uploadLength,
	bitfield, (hex of download progress)
	downloadSpeed, uploadSpeed,
	pieceLength,
	numPieces,
	connections,
	errorCode,
	followedBy, belongsTo,
	infoHash, numSeeders, - these are bittorent specific
	@(bittorent) - includes one or more of the following/bittorent is not an actual keyword
		announceList
		comment
		creationDate
		mode
		@(info) - info is not an actual keyword
			name
	
	.EXAMPLE
	Get-Aria2TellActive
	Retrieves all active downloads with default return information.
	
	.EXAMPLE
	Get-Aria2TellActive -keys @("gid", "status", "files", ("announceList", "mode"))
	Retrieve all active downloads with return information specified in 'keys'.
	
	.EXAMPLE
	$baseKeys = @("gid", "status", "files")
	$bittorentKeys = @("announceList", "mode")
	$keys = @(($baseKeys),($bittorentKeys))
	Get-Aria2TellActive -offset 0 -num 10 -keys $keys
	Retrieve first 10 waiting downloads with return information specified in 'keys'.  Uses command-line variables to populate 'keys' variable.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 - 01 Mar 2014 - Initial version of Get-Aria2TellActive

	.LINK
	Get-Aria2TellWaiting
	Get-Aria2TellStopped
	Get-Aria2TellStatus
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true)]
	param(
		[array] $keys
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		if ($pscmdlet.shouldprocess("$script:jsonrpc_url","Get active downloads")) {
			$json = @{}
			$json.method = "aria2.tellActive"
			$json.id = $script:id
			$json.jsonrpc = $script:jsonrpc
			$json.params = @(,("token:$script:rpc_secret"))
			if ($keys.Length -gt 0) {
				write-verbose "Get-Aria2TellActive : Info: 'keys' parameter not blank, adding to query"
				$json.params += @($keys)
			}
			$json = convertto-json $json -depth 5
			$active = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			$active = $active.result
			return $active
		}
	}
	end { }
}

function Get-Aria2TellWaiting {
	<#
	.SYNOPSIS
	Retrieves list of waiting downloads in a running aria2 instance.
	
	.DESCRIPTION
	Retrieves list of waiting downloads in a running aria2 instance.  By default, returns first 100 downloads and the following information: gid, dir, files, completedLength, uploadLength, downloadSpeed, uploadSpeed, connections, bittorrent, infoHash, numPieces, numSeeders, pieceLength, status, totalLength.  The return information varies based on download type (bittorent, http/ftp, metalink).  See -keys parameter for details on available return information.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER offset
	Position of download to start retrieving; starts at 0.  Defaults to 0, the first download.  Can be a negative number, which begins at the end of the list; results are in reverse order as well.
	
	.PARAMETER num
	Number of downloads to retrieve starting at 'offset'.  Defaults to 100.
	
	.PARAMETER keys
	Array of keywords used to return specific information.  This list is sorted by type, with @() representing a sub-array.  Key names are case-sensitive.
	gid, status, dir, files,
	totalLength, completedLength, uploadLength,
	bitfield, (hex of download progress)
	downloadSpeed, uploadSpeed,
	pieceLength,
	numPieces,
	connections,
	errorCode,
	followedBy, belongsTo,
	infoHash, numSeeders, - these are bittorent specific
	@(bittorent) - includes one or more of the following/bittorent is not an actual keyword
		announceList
		comment
		creationDate
		mode
		@(info) - info is not an actual keyword
			name
	
	.EXAMPLE
	Get-Aria2TellWaiting
	Retrieves first 100 waiting downloads with default return information.
	
	.EXAMPLE
	Get-Aria2TellWaiting -offset 10 -num 5
	Retrieves the first 5 waiting downloads starting at waiting download number 11 (due to the 0-index nature of 'offset') with default return information.
	
	.EXAMPLE
	Get-Aria2TellWaiting -keys @("gid", "status", "files", ("announceList", "mode"))
	Retrieve first 100 waiting downloads with return information specified in 'keys'.
	
	.EXAMPLE
	$baseKeys = @("gid", "status", "files")
	$bittorentKeys = @("announceList", "mode")
	$keys = @(($baseKeys),($bittorentKeys))
	Get-Aria2TellWaiting -offset 0 -num 10 -keys $keys
	Retrieve first 10 waiting downloads with return information specified in 'keys'.  Uses command-line variables to populate 'keys' variable.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 - 01 Mar 2014 - Initial version of Get-Aria2TellWaiting

	.LINK
	Get-Aria2TellActive
	Get-Aria2TellStopped
	Get-Aria2TellStatus
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true)]
	param(
		[int] $offset = 0,
		[ValidateScript({ $_ -gt 0 })]
		[int] $num = 100,
		[array] $keys
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		if ($pscmdlet.shouldprocess("$script:jsonrpc_url","Get waiting downloads")) {
			$json = @{}
			$json.method = "aria2.tellWaiting"
			$json.id = $script:id
			$json.jsonrpc = $script:jsonrpc
			$json.params = @(,("token:$script:rpc_secret"))
			if ($keys.Length -gt 0) {
				write-verbose "Get-Aria2TellWaiting : Info: 'keys' parameter not blank, adding to query"
				$json.params += @($offset, $num, ($keys))
			}
			else { $json.params += @($offset, $num) }
			$json = convertto-json $json -depth 5
			$global:j = $json
			$waiting = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			return $waiting
		}
	}
	end { }
}

function Get-Aria2TellStopped {
	<#
	.SYNOPSIS
	Retrieves list of stopped downloads in a running aria2 instance.
	
	.DESCRIPTION
	Retrieves list of stopped downloads in a running aria2 instance.  By default, returns first 100 downloads and the following information: gid, dir, files, completedLength, uploadLength, downloadSpeed, uploadSpeed, connections, bittorrent, infoHash, numPieces, numSeeders, pieceLength, status, totalLength.  The return information varies based on download type (bittorent, http/ftp, metalink).  See -keys parameter for details on available return information.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER offset
	Position of download to start retrieving; starts at 0.  Defaults to 0, the first download.  Can be a negative number, which begins at the end of the list; this causes results to be in reverse order.
	
	.PARAMETER num
	Number of downloads to retrieve starting at 'offset'.  Defaults to 100.
	
	.PARAMETER keys
	Array of keywords used to return specific information.  This list is sorted by type, with @() representing a sub-array.  Key names are case-sensitive.
	gid, status, dir, files,
	totalLength, completedLength, uploadLength,
	bitfield, (hex of download progress)
	downloadSpeed, uploadSpeed,
	pieceLength,
	numPieces,
	connections,
	errorCode,
	followedBy, belongsTo,
	infoHash, numSeeders, - these are bittorent specific
	@(bittorent) - includes one or more of the following/bittorent is not an actual keyword
		announceList
		comment
		creationDate
		mode
		@(info) - info is not an actual keyword
			name
	
	.EXAMPLE
	Get-Aria2TellStopped
	Retrieves first 100 stopped downloads with default return information.
	
	.EXAMPLE
	Get-Aria2TellStopped -offset 10 -num 5
	Retrieves the first 5 stopped downloads starting at stopped download number 11 (due to the 0-index nature of 'offset') with default return information.
	
	.EXAMPLE
	Get-Aria2TellStopped -keys @("gid", "status", "files", ("announceList", "mode"))
	Retrieve first 100 stopped downloads with return information specified in 'keys'.
	
	.EXAMPLE
	$baseKeys = @("gid", "status", "files")
	$bittorentKeys = @("announceList", "mode")
	$keys = @(($baseKeys),($bittorentKeys))
	Get-Aria2TellWaiting -offset 0 -num 10 -keys $keys
	Retrieve first 10 waiting downloads with return information specified in 'keys'.  Uses command-line variables to populate 'keys' variable.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 - 01 Mar 2014 - Initial version of Get-Aria2TellStopped

	.LINK
	Get-Aria2TellWaiting
	Get-Aria2TellActive
	Get-Aria2TellStatus
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true)]
	param(
		[int] $offset = 0,
		[ValidateScript({ $_ -gt 0 })]
		[int] $num = 100,
		[array] $keys
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		if ($pscmdlet.shouldprocess("$script:jsonrpc_url","Get stopped downloads")) {
			$json = @{}
			$json.method = "aria2.tellStopped"
			$json.id = $script:id
			$json.jsonrpc = $script:jsonrpc
			$json.params = @(,("token:$script:rpc_secret"))
			if ($keys.Length -gt 0) {
				write-verbose "Get-Aria2TellStopped : Info: 'keys' parameter not blank, adding to query"
				$json.params += @($offset, $num, ($keys))
			}
			else { $json.params += @($offset, $num) }
			$json = convertto-json $json -depth 5
			$stopped = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			return $stopped
		}
	}
	end { }
}

function Get-Aria2TellStatus {
	<#
	.SYNOPSIS
	Retrieves detailed status information about a single download in a running aria2 instance.
	
	.DESCRIPTION
	Retrieves detailed status information about a single download in a running aria2 instance.  By default returns gid, dir, files, completedLength, uploadLength, downloadSpeed, uploadSpeed, connections, bittorrent, infoHash, numPieces, numSeeders, pieceLength, status, totalLength.  The return information varies based on download type (bittorent, http/ftp, metalink).  See -keys parameter for details on available return information.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER gid
	GID of download.  Use Get-Aria2TellActive/Stopped/Waiting to lookup GID.
	
	.PARAMETER keys
	Array of keywords used to return specific information.  This list is sorted by type, with @() representing a sub-array.  Key names are case-sensitive.
	gid, status, dir, files,
	totalLength, completedLength, uploadLength,
	bitfield, (hex of download progress)
	downloadSpeed, uploadSpeed,
	pieceLength,
	numPieces,
	connections,
	errorCode,
	followedBy, belongsTo,
	infoHash, numSeeders, - these are bittorent specific
	@(bittorent) - includes one or more of the following/bittorent is not an actual keyword
		announceList
		comment
		creationDate
		mode
		@(info) - info is not an actual keyword
			name
	
	.EXAMPLE
	Get-Aria2TellStatus 275ec074baea91c0 // Get-Aria2TellStatus -gid 275ec074baea91c0
	Retrieves specific download with default return information.
	
	.EXAMPLE
	Get-Aria2TellStatus -gid 275ec074baea91c0 -keys @("gid", "status", "files", ("announceList", "mode"))
	Retrieves specific download with return information as specified in 'keys'.
	
	.EXAMPLE
	$baseKeys = @("gid", "status", "files")
	$bittorentKeys = @("announceList", "mode")
	$keys = @(($baseKeys),($bittorentKeys))
	Get-Aria2TellStatus -offset 0 -num 10 -keys $keys
	Retrieve first 10 waiting downloads with return information specified in 'keys'.  Uses command-line variables to populate 'keys' variable.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 - 01 Mar 2014 - Initial version of Get-Aria2TellStatus
	
	.LINK
	Get-Aria2TellWaiting
	Get-Aria2TellActive
	Get-Aria2TellStopped
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true)]
	param(
		[Parameter(Position = 0, Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
		[string] $gid,
		[array] $keys
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		if ($pscmdlet.shouldprocess("$gid","Get detailed information")) {
			$json = @{}
			$json.method = "aria2.tellStatus"
			$json.id = $script:id
			$json.jsonrpc = $script:jsonrpc
			$json.params = @(,("token:$script:rpc_secret"))
			if ($keys.Length -gt 0) {
				write-verbose "Get-Aria2TellStatus: Info: 'keys' parameter not blank, adding to query"
				$json.params += @($gid, ($keys))
			}
			else { $json.params += @($gid) }
			$json = convertto-json $json -depth 5
			$status = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			return $status
		}
	}
	end { }
}

function Start-Aria2AddUri {
	<#
	.SYNOPSIS
	Add URIs for download to a running aria2 instance.
	
	.DESCRIPTION
	Add URIs for download at the end of the queue to a running aria2 instance.  To download multiple different files, run function multiple times.  Supports HTTP/FTP file locations, as well as BitTorrent Magnet links and Metalinks.  Returns GID of download.  Does not currently support any options or specifying position in download queue.
	
	To upload a torrent, use Add-Aria2AddTorrent.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER Uri
	URI to download.  Supports HTTP/FTP file locations, as well as BitTorrent Magnet links and Metalinks.  Currently only supports a single URI.
	
	.EXAMPLE
	Start-Aria2AddUri "http://cachefly.cachefly.net/100mb.test"
	Adds single URI to download.  Best to enclose in quotes to avoid any parsing of the URI.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 - 01 Mar 2014 - Initial version of Start-Aria2AddUri
	
	.LINK
	Start-Aria2AddTorrent
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true)]
	param(
		[Parameter(Mandatory = $true, Position = 0)]
		[string] $Uri
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		if ($pscmdlet.shouldprocess("$Uri","Add download")) {
			$json = @{}
			$json.method = "aria2.addUri"
			$json.id = $script:id
			$json.jsonrpc = $script:jsonrpc
			$json.params = @(,("token:$script:rpc_secret"))
			$json.params += @($Uri)
			$json = convertto-json $json -depth 5
			$addUri = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			return $addUri
		}
	}
	end { }
}

function Start-Aria2AddTorrent {
	<#
	.SYNOPSIS
	Add torrent for download to a running aria2 instance.
	
	.DESCRIPTION
	Add torrent for download to a running aria2 instance.  Returns GID of download.  Does not currently support seeding, any options, or specifying position in download queue.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER Uri
	URI of torrent to upload for download.  Can be a local file or a HTTP link to a .torrent file.  Technically, this function Base64 encodes the contents of the file and sends that to the running aria2 instance.
	
	.EXAMPLE
	Start-Aria2AddUri "http://download.documentfoundation.org/libreoffice/stable/4.2.2/win/x86/LibreOffice_4.2.2_Win_x86.msi.torrent"
	Adds the specified torrent for download.  Best to enclose in quotes to avoid any parsing of the URI.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 - 01 Mar 2014 - Initial version of Start-Aria2AddTorrent
	
	.LINK
	Start-Aria2AddUri
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true)]
	param(
		[Parameter(Mandatory = $true, Position = 0)]
		[string] $Uri
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		if ($pscmdlet.shouldprocess("$Uri","Add torrent")) {
			if (($Uri.StartsWith("http://")) -or ($Uri.StartsWith("ftp://"))) {
				write-verbose "Start-Aria2AddTorrent : Info: '$Uri' is web-based; downloading and getting contents as binary."
				$webclient = New-Object System.Net.WebClient
				$webclient.DownloadFile($Uri,"$env:temp\temp.torrent")
				$tempFile = get-content "$env:temp\temp.torrent" -encoding byte
			}
			elseif (($Uri.SubString(0,3) -match "[a-zA-Z]\:\\") -or ($Uri.StartsWith("\\"))) {
				write-verbose "Start-Aria2AddTorrent : Info: '$Uri' is a local/network file; getting contents as binary."
				$tempFile = get-content $Uri -encoding byte
			}
			else {
				write-warning "Start-Aria2AddTorrent : Warning: Unable to determine if '$Uri' is a local file or http/ftp based file."
				return
			}
			$base64 = [System.Convert]::ToBase64String($tempFile)
			$json = @{}
			$json.method = "aria2.addTorrent"
			$json.id = $script:id
			$json.jsonrpc = $script:jsonrpc
			$json.params = @(,("token:$script:rpc_secret"))
			$json.params += @($base64)
			$json = convertto-json $json -depth 5
			$addUri = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			return $addUri
		}
	}
	end { }
}

function Suspend-Aria2Pause {
	<#
	.SYNOPSIS
	Pause specified download in a running aria2 instance.
	
	.DESCRIPTION
	Pause specified download in a running aria2 instance.  Returns GID of download or "OK" if 'all' is specified.  Use Suspend-Aria2UnPause to restart a paused download.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER gid
	GID of download to pause.  Use Get-Aria2TellActive/Stopped/Waiting to lookup GID.
	
	.PARAMETER force
	Forces pause.  Skips any actions that take time, including contacting BitTorrent trackers.
	
	.PARAMETER all
	Pauses all downloads.  Can be used in conjunction with 'force'.
	
	.EXAMPLE
	Suspend-Aria2Pause -gid 275ec074baea91c0
	Pauses specified download.
	
	.EXAMPLE
	Suspend-Aria2Pause -gid 275ec074baea91c0 -force
	Force pauses specified download.
	
	.EXAMPLE
	Suspend-Aria2Pause -force -all
	Force pauses all downloads.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 - 01 Mar 2014 - Initial version of Suspend-Aria2Pause
	
	.LINK
	Resume-Aria2UnPause
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = "Single")]
	param(
		[Parameter(Position = 0, Mandatory = $true, ParameterSetName = "Single", ValueFromPipelineByPropertyName = $true)]
		[string] $gid,
		[Parameter(ParameterSetName = "All")]
		[switch] $all,
		[switch] $force
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		$json = @{}
		$json.id = $script:id
		$json.jsonrpc = $script:jsonrpc
		$json.params = @(,("token:$script:rpc_secret"))
		switch ($PsCmdlet.ParameterSetName) {
			"All" {
				$target = "All downloads"
				$action = "Pause downloads"
				if ($force) { $json.method = "aria2.forcePauseAll" }
				else { $json.method = "aria2.pauseAll" }
			}
			"Single" {
				$target = $gid
				$action = "Pause download"
				if ($force) { $json.method = "aria2.forcePause"; $json.params += @($gid) }
				else { $json.method = "aria2.pause"; $json.params += @($gid) }
			}
		}
		if ($pscmdlet.shouldprocess("$target","$action")) {
			$json = convertto-json $json -depth 5
			$status = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			return $status
		}
	}
	end { }
}

function Resume-Aria2UnPause {
	<#
	.SYNOPSIS
	Unpauses/resumes downloads in a running aria2 instance.
	
	.DESCRIPTION
	Unpauses/resumes downloads in a running aria2 instance.  Returns GID of download or "OK" if 'all' is specified.  Use Suspend-Aria2Pause to pause a download.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER gid
	GID of download to pause.  Use Get-Aria2TellActive/Stopped/Waiting to lookup GID.
	
	.PARAMETER all
	Pauses all downloads.  Can be used in conjunction with 'force'.
	
	.EXAMPLE
	Resume-Aria2UnPause -gid 275ec074baea91c0
	Pauses specified download.
	
	.EXAMPLE
	Resume-Aria2UnPause -all
	Unpauses/Resumes all downloads currently paused.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 - 01 Mar 2014 - Initial version of Resume-Aria2UnPause
	
	.LINK
	Suspend-Aria2Pause
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = "Single")]
	param(
		[Parameter(Position = 0, Mandatory = $true, ParameterSetName = "Single", ValueFromPipelineByPropertyName = $true)]
		[string] $gid,
		[Parameter(ParameterSetName = "All")]
		[switch] $all
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		$json = @{}
		$json.id = $script:id
		$json.jsonrpc = $script:jsonrpc
		$json.params = @(,("token:$script:rpc_secret"))
		switch ($PsCmdlet.ParameterSetName) {
			"All" {
				$target = "All downloads"
				$action = "Resume downloads"
				$json.method = "aria2.pauseAll"
			}
			"Single" {
				$target = $gid
				$action = "Resume download"
				$json.method = "aria2.pause"
				$json.params += @($gid)
			}
		}
		if ($pscmdlet.shouldprocess("$target","$action")) {
			$json = convertto-json $json -depth 5
			$status = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			$status = $status.result
			return $status
		}
	}
	end { }
}

function Remove-Aria2Remove {
	<#
	.SYNOPSIS
	Removes downloads in a running aria2 instance.
	
	.DESCRIPTION
	Removes downloads in a running aria2 instance.  Returns GID of download.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER gid
	GID of download to remove.  Use Get-Aria2TellActive/Stopped/Waiting to lookup GID.
	
	.PARAMETER force
	Forces removal of download.  Skips any actions that take time, including contacting BitTorrent trackers.
	
	.EXAMPLE
	Remove-Aria2Remove -gid 275ec074baea91c0
	Removes specified download.
	
	.EXAMPLE
	Remove-Aria2Remove -gid 275ec074baea91c0 -force
	Removes specified download immediately without waiting for any actions.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 - 01 Mar 2014 - Initial version of Remove-Aria2Remove
	
	.LINK
	Start-Aria2AddTorrent
	Start-Aria2AddUri
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true)]
	param(
		[Parameter(Position = 0, Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
		[string] $gid,
		[switch] $force
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		if ($pscmdlet.shouldprocess("$gid","Remove download")) {
			$json = @{}
			if ($force) { $json.method = "aria2.forceRemove" }
			else { $json.method = "aria2.remove" }
			$json.id = $script:id
			$json.jsonrpc = $script:jsonrpc
			$json.params = @(,("token:$script:rpc_secret"))
			$json.params += @($gid)
			$json = convertto-json $json -depth 5
			$remove = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			$remove = $remove.result
			return $remove
		}
	}
	end { }
}

function Get-Aria2DownloadDetails {
	<#
	.SYNOPSIS
	Retrieves detailed information on specified download in a running aria2 instance.
	
	.DESCRIPTION
	Retrieves detailed information on specified download in a running aria2 instance.  Use parameter switches to choose return information; defaults to returning 'files'.  Returns an array of the requested information.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER gid
	GID of download to retrieve information about.  Use Get-Aria2TellActive/Stopped/Waiting to lookup GID.
	
	.PARAMETER uris
	Retrieves URIs used for download including status ("used" or "waiting").
	
	.PARAMETER files
	Retrieves list of files including path, length, completedLength, and URIs for each file.  Only option to default to 'true'.
	
	.PARAMETER peers
	Retrieves details of peers in BitTorrent downloads including peerId, ip, port, bitfield, amChoking, peerChoking, downloadSpeed, uploadSpeed, and seeder.  Returns empty if selected for non-BitTorrent downloads.
	
	.PARAMETER servers
	Retrieves currently connected servers in HTTP/FTP downloads including URI for server, currentUri, and downloadSpeed.  Returns empty if selected for BitTorrent downloadSpeed
	
	.PARAMETER options
	Retrieves download-specific options.  Options with no default value or that have not been set by CLI options, configuration files, or RPC methods will not be returned.
	
	.PARAMETER all
	Retrieves all information for the download including URIs, files, peers, servers, and options.
	
	.EXAMPLE
	Get-Aria2DownloadDetails -gid 275ec074baea91c0
	Retrieves list
	
	.EXAMPLE
	Get-Aria2DownloadDetails -gid 275ec074baea91c0 -all
	Retrieve all details about specified download.
	
	.EXAMPLE
	Get-Aria2DownloadDetails -gid 275ec074baea91c0 -files -peers
	Retrieves details about local files and peers for a BitTorrent download.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 - 01 Mar 2014 - Initial version of Get-Aria2DownloadDetails
	
	.LINK
	Get-Aria2TellActive
	Get-Aria2TellStopped
	Get-Aria2TellStatus
	Get-Aria2TellWaiting
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = "Select")]
	param(
		[Parameter(Position = 0, Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
		[string] $gid,
		[Parameter(ParameterSetName = "Select")]
		[switch] $files = $true,
		[Parameter(ParameterSetName = "Select")]
		[switch] $uris,
		[Parameter(ParameterSetName = "Select")]
		[switch] $peers,
		[Parameter(ParameterSetName = "Select")]
		[switch] $servers,
		[Parameter(ParameterSetName = "Select")]
		[switch] $options,
		[Parameter(ParameterSetName = "All")]
		[switch] $all
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		switch ($PsCmdlet.ParameterSetName) {
			"All" {
				write-verbose "Get-Aria2DownloadDetails : Info: 'all' selected, setting all select options to true"
				$uris = $true
				$files = $true
				$peers = $true
				$servers = $true
				$options = $true
			}
		}
		if ($pscmdlet.shouldprocess("$gid","Get details")) {
			$json = @{}
			$json.id = $script:id
			$json.jsonrpc = $script:jsonrpc
			$json.method = "system.multicall"
			$json.params = @(,@())
			if ($uris) {
				$p = @{}
				$p.methodName = "aria2.getUris"
				$p.params = @(,("token:$script:rpc_secret"))
				$p.params += @($gid)
				$json.params[0] += $p
			}
			if ($files) {
				$p = @{}
				$p.methodName = "aria2.getFiles"
				$p.params = @(,("token:$script:rpc_secret"))
				$p.params += @($gid)
				$json.params[0] += $p
			}
			if ($peers) {
				$p = @{}
				$p.methodName = "aria2.getPeers"
				$p.params = @(,("token:$script:rpc_secret"))
				$p.params += @($gid)
				$json.params[0] += $p
			}
			if ($servers) {
				$p = @{}
				$p.methodName = "aria2.getServers"
				$p.params = @(,("token:$script:rpc_secret"))
				$p.params += @($gid)
				$json.params[0] += $p
			}
			if ($options) {
				$p = @{}
				$p.methodName = "aria2.getOption"
				$p.params = @(,("token:$script:rpc_secret"))
				$p.params += @($gid)
				$json.params[0] += $p
			}
			$json = convertto-json $json -depth 5
			$details = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			$details = $details.result
			$dets = @{}
			$i = 0
			if ($uris) { $dets.uris = $details[$i]; $i++ }
			if ($files) { $dets.files = $details[$i]; $i++ }
			if ($peers) { $dets.peers = $details[$i]; $i++ }
			if ($servers) { $dets.servers = $details[$i]; $i++ }
			if ($options) { $dets.options = $details[$i]; $i++ }
			return $dets
		}
	}
	end { }
}

function Set-Aria2ChangePosition {
	<#
	.SYNOPSIS
	Change position in queue of specified download in a running aria2 instance.
	
	.DESCRIPTION
	Change position in queue of specified download in a running aria2 instance.  Returns integer of new position.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER gid
	GID of download to change position.  Use Get-Aria2TellActive/Stopped/Waiting to lookup GID.
	
	.PARAMETER position
	Integer representing new position.  Can be positive, negative, or zero.  If new position exceeds length of queue, download is moved to the end.  If new position is zero or a negative number relative to the start of the queue, the download will be moved to the beginning of the queue.  See 'fromWhere' for setting relative starting point for this number.
	
	.PARAMETER fromWhere
	Determines relative starting point for 'position'.  Must be one of the following; defaults to POS_SET.  "relative" is an alias for this parameter.
	POS_SET, begin, beginning, start - new position relative to beginning of queue
	POS_CUR, current - new position relative to current position
	POS_END, end - new position relative to end of queue
	
	.EXAMPLE
	Set-Aria2ChangePosition -gid 275ec074baea91c0 -position 1
	Sets specified download to the beginning of the download queue (since 'fromWhere' was not specified).
	
	.EXAMPLE
	Set-Aria2ChangePosition -gid 275ec074baea91c0 -position -3 -fromWhere POS_CUR
	Moves the specified download 3 positions higher in the queue.
	
	.EXAMPLE
	Set-Aria2ChangePosition -gid 275ec074baea91c0 -position -2 -fromWhere POS_END
	Moves the specified download to 2 positions from the end of the queue.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 (v1.5) - 01 Mar 2014 - Initial version of Set-Aria2ChangePosition
	
	.LINK
	Set-Aria2ChangeOption
	Set-Aria2ChangeUri
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true)]
	param(
		[Parameter(Position = 0, Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
		[string] $gid,
		[Parameter(Mandatory = $true)]
		[int] $position,
		[ValidateSet("POS_SET","POS_CUR","POS_END","begin","beginning","start","current","end")]
		[alias("relative")]
		[string] $fromWhere = "POS_SET"
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
		if ($fromWhere -contains "begin","beginning","start") { $fromWhere = "POS_SET" }
		elseif ($fromWhere -contains "current") { $fromWhere = "POS_CUR" }
		elseif ($fromWhere -contains "end") { $fromWhere = "POS_END" }
	}
	process {
		if ($blankFile) { return }
		if ($pscmdlet.shouldprocess("$gid","Change position to '$position' in relation to '$fromWhere'")) {
			$json = @{}
			$json.method = "aria2.changePosition"
			$json.id = $script:id
			$json.jsonrpc = $script:jsonrpc
			$json.params = @(,("token:$script:rpc_secret"))
			$json.params += @($gid, $position, $fromWhere)
			$json = convertto-json $json -depth 5
			$changePosition = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			return $changePosition
		}
	}
	end { }
}

function Set-Aria2ChangeUri {
	<#
	.SYNOPSIS
	Change by deleting or adding URIs of specified download in a running aria2 instance.
	
	.DESCRIPTION
	Change by deleting or adding URIs of specified download in a running aria2 instance.  Deletes URIs before adding any new ones.  Returns list of integers; 1st is the number of URIs deleted and the 2nd is the number of URIs added.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER gid
	GID of download to change URIs of.  Use Get-Aria2TellActive/Stopped/Waiting to lookup GID.
	
	.PARAMETER fileIndex
	1-based index of which file to delete/add URIs to.
	
	.PARAMETER delUris
	Array or space separated list of files (space separated surrounded by quotes) to delete from the list of files for the specific download.
	
	.PARAMETER addUris
	Array or space separated list of files (space separated surrounded by quotes) to add to the list of files for the specific download.
	
	.PARAMETER position
	0-based index to specify where URIs are inserted into list.  As this method deletes URIs first, new position is determined after the 'delUris' (if any) are deleted.
	
	.EXAMPLE
	Set-Aria2ChangeUri -gid 275ec074baea91c0 -fileIndex 1 -addUris http://example.org/file.iso
	Adds http://example.org/file.iso as an additional file for download to the specified download.
	
	.EXAMPLE
	Set-Aria2ChangeUri -gid 275ec074baea91c0 -fileIndex 3 -delUris http://mirror1.example.org/file.iso -addUris http://mirror2.example.org/file.iso -position 3
	Removes mirror1 download and adds mirror2 download 4th in the list for the 3rd file to download in the specified download.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 (v1.5) - 01 Mar 2014 - Initial version of Set-Aria2ChangeUri
	
	.LINK
	Set-Aria2ChangeOption
	Set-Aria2ChangePosition
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true)]
	param(
		[Parameter(Position = 0, Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
		[string] $gid,
		[Parameter(Mandatory = $true)]
		[alias("index")]
		[int] $fileIndex,
		[AllowEmptyCollection()]
		[array] $delUris,
		[AllowEmptyCollection()]
		[array] $addUris,
		[int] $position
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		if ($pscmdlet.shouldprocess("$gid","Change URI")) {
			$json = @{}
			$json.method = "aria2.changeUri"
			$json.id = $script:id
			$json.jsonrpc = $script:jsonrpc
			$json.params = @(,("token:$script:rpc_secret"))
			if ($delUris[0].Contains(" ")) { $delUris = $delUris.Split(" ") }
			if ($addUris[0].Contains(" ")) { $addUris = $addUris.Split(" ") }
			$json.params += @($gid, $fileIndex, @(,($delUris)), @(,($addUris)), $position)
			$json = convertto-json $json -depth 5
			$changeUri = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			return $changeUri
		}
	}
	end { }
}

function Set-Aria2ChangeOption {
	<#
	.SYNOPSIS
	Change options of specified download in a running aria2 instance.
	
	.DESCRIPTION
	Change options of specified download in a running aria2 instance.  Returns OK if successful.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER gid
	GID of download to change options of.  Use Get-Aria2TellActive/Stopped/Waiting to lookup GID.
	
	.PARAMETER options
	Array of options.
	For active downloads:
		bt-max-peers
		bt-request-peer-speed-limit
		bt-remove-unselected-file
		force-save
		max-download-limit
		max-upload-limit
	Waiting/Paused downloads:
		All options available in Input File (http://aria2.sourceforge.net/manual/en/html/aria2c.html#id2) except
			dry-run
			metalink-base-uri
			parameterized-uri
			pause
			piece-length
			rpc-save-upload-metadata
	
	.EXAMPLE
	Set-Aria2ChangeOption -gid 275ec074baea91c0 -options @(,(force-save=true, max-download-limit=1M))
	Uses Powershell CLI syntax for arrays to set max download limit for specified download to 1MB/s and sets option to save download with --save-session even if download is completed or removed.
	
	.EXAMPLE
	$options = @()
	$options += (max-upload-limit=100K, max-download-limit=500K)
	Set-Aria2ChangeOption -gid 275ec074baea91c0 -options $options
	Creates a variable for storing options in and applies them to specified download.  In this case, max download and upload speed are to to 500KB/s and 100KB/s respectively.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 (v1.5) - 01 Mar 2014 - Initial version of Set-Aria2ChangeOption
	
	.LINK
	Set-Aria2ChangeUri
	Set-Aria2ChangePosition
	Use-Aria2
	http://aria2.sourceforge.net
	http://aria2.sourceforge.net/manual/en/html/aria2c.html#id2
	#>
	[CmdletBinding(SupportsShouldProcess = $true)]
	param(
		[Parameter(Position = 0, Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
		[string] $gid,
		[Parameter(Mandatory = $true)]
		[array] $options
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		if ($pscmdlet.shouldprocess("$gid","Change URI")) {
			$json = @{}
			$json.method = "aria2.changeOption"
			$json.id = $script:id
			$json.jsonrpc = $script:jsonrpc
			$json.params = @(,("token:$script:rpc_secret"))
			$json.params += @(,($options))
			$json = convertto-json $json -depth 5
			$changeOption = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			return $changeOption
		}
	}
	end { }
}

function Get-Aria2GetGlobal {
	<#
	.SYNOPSIS
	Retrieves global information in a running aria2 instance.
	
	.DESCRIPTION
	Retrieves global information in a running aria2 instance.  By default and always returns version number and enabled features of running aria2 instance.  Can also return sessionId, global statistics, and global options.  Does not returns options which have no default value and have not been set by command-line options, configuration files, or RPC methods.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER version
	Retrieves version number and enabled features.
	
	.PARAMETER sessionInfo
	Retrieves sessionId which is randomly generated each time aria2 is started. 'sessionId' is an alias for this parameter as that is the aria2 internal name of the value returned.
	
	.PARAMETER stat
	Retrieves global statistics which includes downloadSpeed, uploadSpeed, numActive, numWaiting, numStopped, and numStoppedTotal.
	
	.PARAMETER options
	Retrieves options that have default values or have been set.
	
	.PARAMETER all
	Retrieves all available global information.
	
	.EXAMPLE
	Get-Aria2GetGlobal -all
	Retrieves all available global information including version number, enabled features, sessionId, downloadSpeed, uploadSpeed, numActive, numWaiting, numStopped, numStoppedTotal, and all default and/or set options.
	
	Get-Aria2GetGlobal -stat
	Retrieves version number, enabled features, and global statistics.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 (v1.5)- 14 Apr 2014 - Initial version of Get-Aria2GetGlobal

	.LINK
	Set-Aria2ChangeGlobalOption
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = "Select")]
	param(
		[Parameter(ParameterSetName = "Select")]
		[switch] $version = $true,
		[Parameter(ParameterSetName = "Select")]
		[alias("sessionId")]
		[switch] $sessionInfo,
		[Parameter(ParameterSetName = "Select")]
		[switch] $stat,
		[Parameter(ParameterSetName = "Select")]
		[switch] $options,
		[Parameter(ParameterSetName = "All")]
		[switch] $all
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		switch ($PsCmdlet.ParameterSetName) {
			"All" {
				write-verbose "Get-Aria2GetGlobal : Info: 'all' selected, setting all select options to true"
				$version = $true
				$sessionInfo = $true
				$stat = $true
				$options = $true
			}
		}
		if ($pscmdlet.shouldprocess("$script:jsonrpc_url","Get global information")) {
			$json = @{}
			$json.id = $script:id
			$json.jsonrpc = $script:jsonrpc
			$json.method = "system.multicall"
			$json.params = @(,@())
			if ($version) {
				$p = @{}
				$p.methodName = "aria2.getVersion"
				$p.params = @(,("token:$script:rpc_secret"))
				$json.params[0] += $p
			}
			if ($sessionInfo) {
				$p = @{}
				$p.methodName = "aria2.getSessionInfo"
				$p.params = @(,("token:$script:rpc_secret"))
				$json.params[0] += $p
			}
			if ($stat) {
				$p = @{}
				$p.methodName = "aria2.getGlobalStat"
				$p.params = @(,("token:$script:rpc_secret"))
				$json.params[0] += $p
			}
			if ($options) {
				$p = @{}
				$p.methodName = "aria2.getGlobalOption"
				$p.params = @(,("token:$script:rpc_secret"))
				$json.params[0] += $p
			}
			$json = convertto-json $json -depth 5
			$global = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			$global = $global.result
			$globe = @{}
			$i = 0
			if ($version) { $globe.version = $global[$i]; $i++ }
			if ($sessionInfo) { $globe.sessionInfo = $global[$i]; $i++ }
			if ($stat) { $globe.stat = $global[$i]; $i++ }
			if ($options) { $globe.options = $global[$i]; $i++ }
			return $globe
		}
	}
	end { }
}

function Set-Aria2ChangeGlobalOption {
	<#
	.SYNOPSIS
	Set global options in a running aria2 instance.
	
	.DESCRIPTION
	Set global options in a running aria2 instance.  Requires options to be sent.  See options parameter for details.  Returns OK is successful.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER options
	Hashtable of options.  Available options:
		bt-max-open-files
		download-result
		log
		log-level
		max-concurrent-downloads
		max-download,result
		max-overall-download-limit
		max-overall-upload-limit
		save-cookies
		save-session
		server-stat-of
	Lll options in Input File (http://aria2.sourceforge.net/manual/en/html/aria2c.html#id2) are also available except:
		checksum
		index-out
		out
		pause
		select-file
	For details on each option, read aria2 help file at http://aria2.sourceforge.net/manual/en/html/aria2c.html.
	
	.EXAMPLE
	Set-Aria2ChangeGlobalOption -options @{"max-overall-download-limit"="1M"; "max-overall-upload-limit"="512K"}
	Sets global download and upload limits.
	
	.EXAMPLE
	$options = @{}
	$options.max-overall-download-limit = "1M"
	$options.max-overall-upload-limit = "1024K"
	Creates hashtable with entries one at a time.  Sets global download and upload limits.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 - 01 Mar 2014 - Initial version of Get-Aria2TellActive

	.LINK
	Get-Aria2GetGlobal
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true)]
	param(
		[Parameter(Position = 0, Mandatory = $true)]
		[hashtable] $options
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		if ($pscmdlet.shouldprocess("$script:jsonrpc_url","Set global options")) {
			$json = @{}
			$json.method = "aria2.changeGlobalOption"
			$json.id = $script:id
			$json.jsonrpc = $script:jsonrpc
			$json.params = @(,("token:$script:rpc_secret"))
			$json.params += @($options)
			$json = convertto-json $json -depth 5
			$global = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			$global = $global.result
			return $global
		}
	}
	end { }
}

function Remove-Aria2DownloadResult {
	<#
	.SYNOPSIS
	Removes specified or all download(s) if they are in a completed, error, or removed state from memory in a running aria2 instance.
	
	.DESCRIPTION
	Removes specified download if it is in a completed, error, or removed state from memory in a running aria2 instance.  Can also remove all downloads in those states if '-all' is used.  Returns OK if successful.  Use Remove-Aria2Remove to remove a download from the list.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER gid
	GID of download to remove.  Use Get-Aria2TellStopped to lookup GIDs that are in a state to be removed from memory.
	
	.PARAMETER all
	Removes all downloads eligible to removed from memory.
	
	.EXAMPLE
	Remove-Aria2DownloadResult -gid 275ec074baea91c0
	Removes specified download from memory.
	
	.EXAMPLE
	Remove-Aria2DownloadResult -all
	Removes all downloads from memory that are in a completed, error, or removed state.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 (v1.5)- 16 Apr 2014 - Initial version of Remove-Aria2DownloadResult
	
	.LINK
	Remove-Aria2Remove
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = "Single")]
	param(
		[Parameter(Position = 0, Mandatory = $true, ParameterSetName = "Single", ValueFromPipelineByPropertyName = $true)]
		[string] $gid,
		[Parameter(ParameterSetName = "All")]
		[switch] $all
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		$json = @{}
		$json.id = $script:id
		$json.jsonrpc = $script:jsonrpc
		$json.params = @(,("token:$script:rpc_secret"))
		switch ($PsCmdlet.ParameterSetName) {
			"All" {
				$target = "All completed/error/removed downloads"
				$action = "Remove downloads from memory"
				$json.method = "aria2.purgeDownloadResult"
			}
			"Single" {
				$target = $gid
				$action = "Remove download from memory"
				$json.method = "aria2.removeDownloadResult"; $json.params += @($gid)
			}
		}
		if ($pscmdlet.shouldprocess("$target","$action")) {
			$json = convertto-json $json -depth 5
			$status = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			return $status
		}
	}
	end { }
}

function Save-Aria2SaveSession {
	<#
	.SYNOPSIS
	Immediately saves session information in a running aria2 instance.
	
	.DESCRIPTION
	Immediately saves session information in a running aria2 instance.  Checks for save-session setting and prompts to set if it does not exist.  Use Set-Aria2ChangeGlobalOption to change setting if not blank.  Returns OK.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER force
	If --save-session does not exist, error out instead of prompting to set setting.
	
	.EXAMPLE
	Save-Aria2SaveSession
	Saves session information immediately.  Prompts to change if setting does not exist.
	
	Save-Aria2SaveSession -force
	Saves session information immediately.  Exits with warning if --save-setting is blank.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 (v1.5)- 16 Apr 2014 - Initial version of Save-Aria2SaveSession

	.LINK
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true)]
	param(
		[switch] $force
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		$t = Get-Aria2GetGlobal -options -whatif:$false
		$t = $t[1]
		$tt = $a."save-session"
		if ($tt.length -eq 0) {
			if ($force) {
				$ParamError = new-object System.FormatException "Save-Aria2SaveSession : Error: --save-session setting not set"
				throw $ParamError
			}
			else {
				$confirm = read-host "--save-session not set.  Set to what?  Relative path recommended.  Use 'no' to exit"
				if ($confirm -match "(n|no)") {
					write-warning "Save-Aria2SaveSession : Warning: Exiting without setting --save-session"
					exit
				}
				else {
					$opt = @{}
					$opt."save-session" = "$confirm"
					Set-Aria2ChangeGlobalOption -options $opt
					$tt = $confirm
				}
			}
		}
		$json = @{}
		$json.id = $script:id
		$json.jsonrpc = $script:jsonrpc
		$json.params = @(,("token:$script:rpc_secret"))
		if ($pscmdlet.shouldprocess("$tt","Save session information")) {
			$json.method = "aria2.saveSession"
			$json = convertto-json $json -depth 5
			$save = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			return $save
		}
	}
	end { }
}

function Exit-Aria2Shutdown {
	<#
	.SYNOPSIS
	Shutdown remote aria2 instance.
	
	.DESCRIPTION
	Shutdown remote aria2 instance.  Use -save to allow aria2 to resume with the same information when it is started next.  Returns OK.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER save
	Saves session file before shutdown.
	
	.PARAMETER force
	Speeds up shutdown by skipping actions that take time (i.e. contacting BitTorrent trackers) and skips confirmation if save fails.
	
	.EXAMPLE
	Exit-Aria2Shutdown
	Shutdown remote aria2 instance without saving session information.
	
	Exit-Aria2Shutdown -save -force
	Saves session information and shuts down remote aria2 instance immediately without taking any actions that are time-consuming.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 (v1.5)- 16 Apr 2014 - Initial version of Exit-Aria2Shutdown

	.LINK
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true)]
	param(
		[switch] $save,
		[switch] $force
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		if ($save) {
			$t = Save-Aria2SaveSession
			if (!($t.result -eq "OK")) {
				write-warning "Exit-Aria2Shutdown : Warning: Save-Aria2SaveSession failed"
				if (!($force)) {
					$confirm = read-host "Continue with shutdown?"
					if ($confirm -notmatch "(y|yes)") { exit }
				}
			}
		}
		$json = @{}
		$json.id = $script:id
		$json.jsonrpc = $script:jsonrpc
		$json.params = @(,("token:$script:rpc_secret"))
		if ($pscmdlet.shouldprocess("$script:jsonrpc_url","Shutdown aria2 instance")) {
			if ($shutdown) { $json.method = "aria2.forceShutdown" }
			else { $json.method = "aria2.shutdown" }
			$json = convertto-json $json -depth 5
			$save = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			return $save
		}
	}
	end { }
}

function Search-Aria2Downloads {
	<#
	.SYNOPSIS
	Search download file paths (i.e. filenames) in remote aria2 instance.
	
	.DESCRIPTION
	Search download file paths (i.e. filenames) in remote aria2 instance.  Can specify active/waiting/stopped/all downloads, specific return information using -keys, and offset and number of downloads in each category by using -offset and -num.  By default searches first 100 downloads in each category and returns this information: gid, dir, files, completedLength, uploadLength, downloadSpeed, uploadSpeed, connections, bittorrent, infoHash, numPieces, numSeeders, pieceLength, status, totalLength.  The return information varies based on download type (bittorent, http/ftp, metalink).
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER active
	Search list of active downloads.
	
	.PARAMETER waiting
	Search list of waiting (paused) downloads.
	
	.PARAMETER stopped
	Search list of stopped downloads.
	
	.PARAMETER offset
	Position of download to start retrieving; starts at 0.  Defaults to 0, the first download.  Can be a negative number, which begins at the end of the list; results are in reverse order as well.
	
	.PARAMETER num
	Number of downloads to retrieve starting at 'offset'.  Defaults to 100.
	
	.PARAMETER all
	Search all of active, waiting, and stopped downloads.
	
	.PARAMETER keys
	Array of keywords used to return specific information.  This list is sorted by type, with @() representing a sub-array.  Key names are case-sensitive.
	gid, status, dir, files,
	totalLength, completedLength, uploadLength,
	bitfield, (hex of download progress)
	downloadSpeed, uploadSpeed,
	pieceLength,
	numPieces,
	connections,
	errorCode,
	followedBy, belongsTo,
	infoHash, numSeeders, - these are bittorent specific
	@(bittorent) - includes one or more of the following/bittorent is not an actual keyword
		announceList
		comment
		creationDate
		mode
		@(info) - info is not an actual keyword
			name
	
	.EXAMPLE
	Search-Aria2Downloads -search iso -all
	Searches all downloads for files with the word iso in file path.
	
	Search-Aria2Downloads -search iso -active -keys @("gid","status","totalLength")
	Searches active downloads with iso in the file path and returns only gid, status, and totalLength.
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 (v1.5)- 18 Apr 2014 - Initial version of Search-Aria2Downloads

	.LINK
	Use-Aria2
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = "Select")]
	param(
		[Parameter(Position = 0, Mandatory = $true)]
		[string] $search,
		[Parameter(ParameterSetName = "Select")]
		[switch] $active = $true,
		[Parameter(ParameterSetName = "Select")]
		[switch] $waiting,
		[Parameter(ParameterSetName = "Select")]
		[switch] $stopped,
		[Parameter(ParameterSetName = "All")]
		[switch] $all,
		[int] $offset = 0,
		[ValidateScript({ $_ -gt 0 })]
		[int] $num = 100,
		[array] $keys
	)
	begin {
		#load variables if necessary
		if ($script:aria2ConfigFile.Length -eq 0) {
			$blankFile = aria2_LoadVariables -whatif:$false
		}
	}
	process {
		if ($blankFile) { return }
		switch ($PsCmdlet.ParameterSetName) {
			"All" {
				write-verbose "Search-Aria2Downloads : Info: 'all' selected, setting all select options to true"
				$active = $true
				$waiting = $true
				$stopped = $true
			}
		}
		if ($keys.length -gt 0) {
			if ($keys -notcontains "files") {
				$keys += "files"
				$added = $true
			}
		}
		if ($pscmdlet.shouldprocess("active:$active, waiting:$waiting, stopped:$stopped","Search downloads for '$search'")) {
			$json = @{}
			$json.id = $script:id
			$json.jsonrpc = $script:jsonrpc
			$json.method = "system.multicall"
			$json.params = @(,@())
			if ($active) {
				$p = @{}
				$p.methodName = "aria2.tellActive"
				$p.params = @("token:$script:rpc_secret")
				if ($keys.Length -gt 0) { $p.params += @(,($keys)) }
				$json.params[0] += $p
			}
			if ($waiting) {
				$p = @{}
				$p.methodName = "aria2.tellWaiting"
				$p.params = @("token:$script:rpc_secret")
				if ($keys.Length -gt 0) { $p.params += @($offset, $num, ($keys)) }
				else { $p.params += @($offset, $num) }
				$json.params[0] += $p
			}
			if ($stopped) {
				$p = @{}
				$p.methodName = "aria2.tellStopped"
				$p.params = @("token:$script:rpc_secret")
				if ($keys.Length -gt 0) { $p.params += @($offset, $num, ($keys)) }
				else { $p.params += @($offset, $num) }
				$json.params[0] += $p
			}
			$json = convertto-json $json -depth 5
			$download = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
			$download = $download.result
			$s = @()
			$download | foreach { $_ | foreach { $_ | foreach {
				if ($_.files | where-object -property path -like "*$search*") {
					if ($added) { $object = $_ | Select-Object -Property * -ExcludeProperty "files" }
					else { $object = $_ }
					$s += $object
				}
			}}}
			return $s
		}
	}
}

function Use-Aria2 {
	<#
	.SYNOPSIS
	Work with a running aria2 instance.  Add downloads, get downloads, details, status, pause/unpause, remove, save session, and shutdown the remote instance.
	
	.DESCRIPTION
	Work with a running aria2 instance.  Add downloads, get downloads, details, status, pause/unpause, remove, save session, and shutdown the remote instance.
	
	Requires a running aria2 instance with --rpc-enable=true and a aria2.HOSTNAME.cfg file.
	
	.PARAMETER downloads
	Retrieve list of ALL downloads.  Same as using -active -waiting -stopped.  Use with -offset and -num to narrow list and with -keys to specify return information.  Active download list only obeys -keys.
	
	.PARAMETER active
	Retrieve list of active downloads.  Use with -offset and -num to narrow list and with -keys to specify return information.
	
	Use with -search to search active downloads.
	
	.PARAMETER waiting
	Retrieve list of waiting (paused) downloads.  Use with -offset and -num to narrow list and with -keys to specify return information.
	
	Use with -search to search waiting downloads.
	
	.PARAMETER stopped
	Retrieve list of stopped downloads.  Use with -offset and -num to narrow list and with -keys to specify return information.
	
	Use with -search to search stopped downloads.
	
	.PARAMETER gid
	GID of download.  Use Use-Aria2 -downloads/active/waiting/stopped or Get-Aria2TellActive/Stopped/Waiting to lookup GID.
	
	.PARAMETER offset
	Position of download to start retrieving; starts at 0.  Defaults to 0, the first download.  Can be a negative number, which begins at the end of the list; results are in reverse order as well.
	
	.PARAMETER num
	Number of downloads to retrieve starting at 'offset'.  Defaults to 100.
	
	.PARAMETER add
	URI to download.  Supports HTTP/FTP file locations, as well as BitTorrent Magnet links, Metalinks, and BitTorrent files (.torrent).  Currently only supports a single URI.
	
	.PARAMETER status
	Retrieve detailed information about a specific download.  Use -gid to specify download and -keys to return only specific information.
	
	.PARAMETER details
	Retrieves all information for the download including URIs, files, peers, servers, and options.
	
	.PARAMETER uris
	Retrieves URIs used for download including status ("used" or "waiting").
	
	.PARAMETER files
	Retrieves list of files including path, length, completedLength, and URIs for each file.  Only option to default to 'true'.
	
	.PARAMETER peers
	Retrieves details of peers in BitTorrent downloads including peerId, ip, port, bitfield, amChoking, peerChoking, downloadSpeed, uploadSpeed, and seeder.  Returns empty if selected for non-BitTorrent downloads.
	
	.PARAMETER servers
	Retrieves currently connected servers in HTTP/FTP downloads including URI for server, currentUri, and downloadSpeed.  Returns empty if selected for BitTorrent downloadSpeed
	
	.PARAMETER options
	Retrieves options, either download-specific or global depending on the context of the rest of the options.  Options with no default value or that have not been set by CLI options, configuration files, or RPC methods will not be returned.
	
	.PARAMETER position
	Used for changing position: Integer representing new position.  Can be positive, negative, or zero.  If new position exceeds length of queue, download is moved to the end.  If new position is zero or a negative number relative to the start of the queue, the download will be moved to the beginning of the queue.  See 'fromWhere' for setting relative starting point for this number.
	
	Used for changing URIs: 0-based index to specify where URIs are inserted into list.  As this method deletes URIs first, new position is determined after the 'delUris' (if any) are deleted.
	
	.PARAMETER fromWhere
	Determines relative starting point for 'position'.  Must be one of the following; defaults to POS_SET.  "relative" is an alias for this parameter.
	POS_SET, begin, beginning, start - new position relative to beginning of queue
	POS_CUR, current - new position relative to current position
	POS_END, end - new position relative to end of queue
	
	.PARAMETER fileIndex
	1-based index of which file to delete/add URIs to.
	
	.PARAMETER delUris
	Array or space separated list of files (space separated surrounded by quotes) to delete from the list of files for the specific download.
	
	.PARAMETER addUris
	Array or space separated list of files (space separated surrounded by quotes) to add to the list of files for the specific download.
	
	.PARAMETER changeOptions
	Array of options.
	For active downloads:
		bt-max-peers
		bt-request-peer-speed-limit
		bt-remove-unselected-file
		force-save
		max-download-limit
		max-upload-limit
	Waiting/Paused downloads:
		All options available in Input File (http://aria2.sourceforge.net/manual/en/html/aria2c.html#id2) except
			dry-run
			metalink-base-uri
			parameterized-uri
			pause
			piece-length
			rpc-save-upload-metadata
	
	.PARAMETER global
	Retrieves all available global information.
	
	.PARAMETER version
	Retrieves version number and enabled features.
	
	.PARAMETER sessionInfo
	Retrieves sessionId which is randomly generated each time aria2 is started. 'sessionId' is an alias for this parameter as that is the aria2 internal name of the value returned.
	
	.PARAMETER stat
	Retrieves global statistics which includes downloadSpeed, uploadSpeed, numActive, numWaiting, numStopped, and numStoppedTotal.
	
	.PARAMETER purge
	Removes specified, or all, download(s) if they are in a completed, error, or removed state from memory.
	
	.PARAMETER save
	Immediately save session info.  If --save-session is not set, will prompt for location unless -force is used.  If -force is used, exits with error.
	
	.PARAMETER shutdown
	Shutdown remote aria2 instance.  Can be used with -saveSession and -force.
	
	.PARAMETER saveSession
	When used with -shutdown, session info is saved before shutdown of remote aria2 instance.
	
	.PARAMETER force
	Forces action, skipping any steps that take time, including contacting BitTorrent trackers.
	
	.PARAMETER all
	Affects all downloads.  Can be used in conjunction with 'force'.  Used with Suspend, Resume, and Purge/Remove methods.
	
	Also used with -search to search all of active, waiting, and stopped downloads.
	
	.PARAMETER keys
	Array of keywords used to return specific information.  This list is sorted by type, with @() representing a sub-array.  Key names are case-sensitive.
	gid, status, dir, files,
	totalLength, completedLength, uploadLength,
	bitfield, (hex of download progress)
	downloadSpeed, uploadSpeed,
	pieceLength,
	numPieces,
	connections,
	errorCode,
	followedBy, belongsTo,
	infoHash, numSeeders, - these are bittorent specific
	@(bittorent) - includes one or more of the following/bittorent is not an actual keyword
		announceList
		comment
		creationDate
		mode
		@(info) - info is not an actual keyword
			name
	
	.EXAMPLE
	
	.NOTES
	Requires aria2 running with --rpc-enable=true.  Run any function from this Use-Aria2 module once to create a default aria2.HOSTNAME.cfg file in the same directory as the module file.  Edit the aria2.HOSTNAME.cfg file as needed.
	NAME:		ps-cli for aria2
	AUTHOR:		JRT
	HISTORY:
		v1.0 - 01 Mar 2014 - Initial version of Use-Aria2
		
	.LINK
	http://aria2.sourceforge.net
	#>
	[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = "Downloads")]
	param(
		[Parameter(ParameterSetName = "Downloads")]
		[alias("dl")]
		[switch] $downloads,
		[Parameter(ParameterSetName = "Downloads")]
		[Parameter(ParameterSetName = "Search")]
		[switch] $active,
		[Parameter(ParameterSetName = "Downloads")]
		[Parameter(ParameterSetName = "Search")]
		[switch] $waiting,
		[Parameter(ParameterSetName = "Downloads")]
		[Parameter(ParameterSetName = "Search")]
		[switch] $stopped,
		[Parameter(ParameterSetName = "Downloads")]
		[Parameter(ParameterSetName = "Search")]
		[int] $offset = 0,
		[Parameter(ParameterSetName = "Downloads")]
		[Parameter(ParameterSetName = "Search")]
		[ValidateScript({ $_ -gt 0 })]
		[int] $num = 100,
		[Parameter(ParameterSetName = "Start")]
		[string] $add,
		[Parameter(ParameterSetName = "Status")]
		[string] $status,
		[Parameter(ParameterSetName = "Details")]
		[switch] $details,
		[Parameter(ParameterSetName = "Details")]
		[switch] $files,
		[Parameter(ParameterSetName = "Details")]
		[switch] $uris,
		[Parameter(ParameterSetName = "Details")]
		[switch] $peers,
		[Parameter(ParameterSetName = "Details")]
		[switch] $servers,
		[Parameter(ParameterSetName = "Details")]
		[Parameter(ParameterSetName = "GetGlobal")]
		[switch] $options,
		[Parameter(ParameterSetName = "Change")]
		[switch] $change,
		[Parameter(ParameterSetName = "Change")]
		[ValidateSet("POS_SET","POS_CUR","POS_END","begin","beginning","start","current","end")]
		[alias("relative")]
		[string] $fromWhere = "POS_SET",
		[Parameter(ParameterSetName = "Change")]
		[int] $position,
		[Parameter(ParameterSetName = "Change")]
		[alias("index")]
		[int] $fileIndex,
		[Parameter(ParameterSetName = "Change")]
		[array] $delUris,
		[Parameter(ParameterSetName = "Change")]
		[array] $addUris,
		[Parameter(ParameterSetName = "Change")]
		[alias("changeoptions","coptions","choptions")]
		[array] $gidOptions,
		[Parameter(ParameterSetName = "GetGlobal")]
		[switch] $global,
		[Parameter(ParameterSetName = "GetGlobal")]
		[switch] $version,
		[Parameter(ParameterSetName = "GetGlobal")]
		[switch] $sessionInfo,
		[Parameter(ParameterSetName = "GetGlobal")]
		[switch] $stat,
		[Parameter(ParameterSetName = "ChangeGlobal")]
		[switch] $changeGlobal,
		[Parameter(ParameterSetName = "Purge")]
		[switch] $purge,
		[Parameter(ParameterSetName = "SaveSession")]
		[switch] $save,
		[Parameter(ParameterSetName = "Shutdown")]
		[switch] $shutdown,
		[Parameter(ParameterSetName = "Shutdown")]
		[switch] $saveSession,
		[Parameter(ParameterSetName = "Search")]
		[string] $search,
		[Parameter(ParameterSetName = "Downloads")]
		[Parameter(ParameterSetName = "Status")]
		[array] $keys,
		[Parameter(ParameterSetName = "Suspend")]
		[Parameter(ParameterSetName = "Resume")]
		[Parameter(ParameterSetName = "Purge")]
		[Parameter(ParameterSetName = "Search")]
		[switch] $all,
		[Parameter(ParameterSetName = "Suspend")]
		[Parameter(ParameterSetName = "Remove")]
		[Parameter(ParameterSetName = "SaveSession")]
		[Parameter(ParameterSetName = "Shutdown")]
		[switch] $force,
		[Parameter(ParameterSetName = "Suspend")]
		[Parameter(ParameterSetName = "Resume")]
		[Parameter(ParameterSetName = "Remove")]
		[Parameter(ParameterSetName = "Status")]
		[Parameter(ParameterSetName = "Details")]
		[Parameter(ParameterSetName = "Change")]
		[Parameter(ParameterSetName = "Purge")]
		[string] $gid
	)
	begin {
		$blankFile = aria2_LoadVariables -whatif:$false
	}
	process {
		if ($blankFile) { return }
		switch ($PsCmdlet.ParameterSetName) {
			"Downloads" {
				$json = @{}
				$json.id = $script:id
				$json.jsonrpc = $script:jsonrpc
				$json.method = "system.multicall"
				$json.params = @(,@())
				if ($downloads) {
					$active = $true
					$waiting = $true
					$stopped = $true
				}
				if ($active) {
					$p = @{}
					$p.methodName = "aria2.tellActive"
					$p.params = @("token:$script:rpc_secret")
					if ($keys.Length -gt 0) { $p.params += @($keys) }
					$json.params[0] += $p
				}
				if ($waiting) {
					$p = @{}
					$p.methodName = "aria2.tellWaiting"
					$p.params = @("token:$script:rpc_secret")
					if ($keys.Length -gt 0) { $p.params += @($offset, $num, ($keys)) }
					else { $p.params += @($offset, $num) }
					$json.params[0] += $p
				}
				if ($stopped) {
					$p = @{}
					$p.methodName = "aria2.tellStopped"
					$p.params = @("token:$script:rpc_secret")
					if ($keys.Length -gt 0) { $p.params += @($offset, $num, ($keys)) }
					else { $p.params += @($offset, $num) }
					$json.params[0] += $p
				}
				$json = convertto-json $json -depth 5
				$download = Invoke-RestMethod -URI $script:jsonrpc_url -Method POST -body $json -credential $script:http_cred -timeout $script:http_timeout
				$download = $download.result
				$dl = @{}
				$i = 0
				if ($active) { $dl.active = $download[$i]; $i++ }
				if ($waiting) { $dl.waiting = $download[$i]; $i++ }
				if ($stopped) { $dl.stopped = $download[$i]; $i++ }
				return $dl
				break
			}
			"Start" {
				if ($add.Contains(".torrent")) { Start-Aria2AddTorrent -uri $add }
				else { Start-Aria2AddUri -uri $add }
				break
			}
			"Suspend" {
				if ($gid.Length -gt 0) { Suspend-Aria2Pause -gid $gid -force:$force }
				else { Suspend-Aria2Pause -all:$all -force:$force }
				break
			}
			"Resume" {
				if ($gid.Length -gt 0 ) { Resume-Aria2UnPause -gid $gid }
				else { Resume-Aria2UnPause -all:$all }
				break
			}
			"Remove" { Remove-Aria2Remove -gid $gid -force:$force; break }
			"Status" {
				if ($keys.Length -gt 0) { Get-Aria2TellStatus -gid $gid -keys $keys }
				else { Get-Aria2TellStatus -gid $gid }
				break
			}
			"Details" {
				if ($details) { Get-Aria2DownloadDetails -gid $gid -all }
				else { Get-Aria2DownloadDetails -gid $gid -files:$files -uris:$uris -peers:$peers -servers:$servers -options:$options }
				break
			}
			"Change" {
				if (($fileIndex -gt 0) -or ($delUris.Length -gt 0) -or ($addUris.Length -gt 0)) {
					Set-Aria2ChangeUri -gid $gid -fileIndex $fileIndex -delUris $delUris -addUris $addUris -position $position
				}
				elseif ($gidOptions.Length -gt 0) {
					Set-Aria2ChangeOption -gid $gid -options $gidOptions
				}
				else { Set-Aria2ChangePosition -gid $gid -position $position -fromWhere $fromWhere }
				break
			}
			"GetGlobal" {
				if ($global) { Get-Aria2GetGlobal -all }
				else { Get-Aria2GetGlobal -version:$version -sessionInfo:$sessionInfo -stat:$stat -options:$options }
				break
			}
			"ChangeGlobal" { Set-Aria2ChangeGlobalOption -options $changeGlobal; break }
			"Purge" {
				if ($all) { Remove-Aria2DownloadResult -all }
				else { Remove-Aria2DownloadResult -gid $gid }
				break
			}
			"SaveSession" { Save-Aria2SaveSession -force:$force; break }
			"Shutdown" { Exit-Aria2Shutdown -save:$saveSession -force:$force; break }
			"Search" {
				if ($all) {
					if ($keys.length -gt 0) { Search-Aria2Downloads -search $search -offset $offset -num $num -all -keys $keys }
					else { Search-Aria2Downloads -search $search -offset $offset -num $num -all }
				}
				else {
					if ($keys.length -gt 0) { Search-Aria2Downloads -search $search -offset $offset -num $num -active:$active -waiting:$waiting -stopped:$stopped -keys $keys }
					else { Search-Aria2Downloads -search $search -offset $offset -num $num -active:$active -waiting:$waiting -stopped:$stopped }
				}
				break
			}
		}
	}
	end { }
}


#export alias and specific modules
Export-ModuleMember -function Use-Aria2 -alias aria2
Export-ModuleMember -function Get-Aria2TellActive
Export-ModuleMember -function Get-Aria2TellWaiting
Export-ModuleMember -function Get-Aria2TellStopped
Export-ModuleMember -function Get-Aria2TellStatus
Export-ModuleMember -function Start-Aria2AddUri
Export-ModuleMember -function Start-Aria2AddTorrent
Export-ModuleMember -function Suspend-Aria2Pause
Export-ModuleMember -function Resume-Aria2UnPause
Export-ModuleMember -function Remove-Aria2Remove
Export-ModuleMember -function Get-Aria2DownloadDetails
Export-ModuleMember -function Set-Aria2ChangePosition
Export-ModuleMember -function Set-Aria2ChangeUri
Export-ModuleMember -function Set-Aria2ChangeOption
Export-ModuleMember -function Get-Aria2GetGlobal
Export-ModuleMember -function Set-Aria2ChangeGlobalOption
Export-ModuleMember -function Remove-Aria2DownloadResult
Export-ModuleMember -function Save-Aria2SaveSession
Export-ModuleMember -function Exit-Aria2Shutdown
Export-ModuleMember -function Search-Aria2Downloads
New-Alias -name aria2 -value Use-Aria2
Export-ModuleMember -alias aria2
#Export-ModuleMember -function aria2_CreateDefaultSettingsFile
#Export-ModuleMember -function aria2_LoadVariables

Added aria2.HOSTNAME.cfg.





















>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
{
    "jsonrpc_url":  "http://server.com:6800/jsonrpc",
    "rpc_secret":  "",
    "id":  "ps-cli",
    "jsonrpc":  "2.0",
    "http_auth":  true,
    "http_username":  "username",
    "http_password":  "",
    "http_timeout":  30
}