My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 214 attachment: 0001-Redo-the-curlSize.pl-script-to-handle-the-current-ou.patch (2.1 KB)

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
From e0409db79bb654f97cbabbcf5405ec0452115c35 Mon Sep 17 00:00:00 2001
From: Drew Moseley <drew@moseleynet.net>
Date: Mon, 3 Sep 2012 17:49:44 -0400
Subject: [PATCH] Redo the curlSize.pl script to handle the current output
format of curl during downloads. Evidently the existing
code to parse the lines doesn't work. This is probably a
bit of a heavyweight solution but somebody more
knowledgable in perl will need to make the changes using
perl.

Signed-off-by: Drew Moseley <drew@moseleynet.net>
---
curlSize.pl | 54 ++++++++++++++----------------------------------------
1 file changed, 14 insertions(+), 40 deletions(-)

diff --git a/curlSize.pl b/curlSize.pl
index 8d22a77..02f25de 100755
--- a/curlSize.pl
+++ b/curlSize.pl
@@ -5,47 +5,21 @@ $TivoDir =~ tr/ :\//_../;
$TivoDir = "/tmp/iTiVo-$TivoDir";

$file = "$TivoDir/iTiVoDL";
-open (CURLFILE, $file);

-$line = "";
-$prevLine = "";
+my $downloadedSize = `cat $file | tr '\r' '\n' | awk 'NF > 0 {print \$4}' | tail -n 1`;
+chomp ($downloadedSize);
+my $unit = substr $downloadedSize,-1,1;
+my $base = chop($downloadedSize);

-<CURLFILE>;
-<CURLFILE>;
-$file = <CURLFILE>;
-
-close(CURLFILE);
-
-my @lines = split('\r', $file);
-
-$line = pop(@lines);
-$prevLine = pop(@lines);
-
-if ($line =~ /^\s*\S+\s+\S+\s+\S+\s+([0-9.]+)([kMG]?)\s+\S+\s+\S+\s+[0-9.]+[kMG]?\s+\d\s+[0-9\-:]+\s+[0-9\-:]+\s+[0-9\-:]+\s+[0-9.]+[kMG]?/) {
- if ($2 eq "k") {
- print $1 / 1024;
- }
- elsif ($2 eq "M") {
- print $1;
- }
- elsif ($2 eq "G") {
- print $1 * 1024;
- }
- else {
- print $1 / (1024 * 1024);
- }
+if ($unit eq "k") {
+ printf ("%.1f", $downloadedSize / 1024);
+}
+elsif ($unit eq "M") {
+ printf ("%.1f", $downloadedSize);
+}
+elsif ($unit eq "G") {
+ printf ("%.1f", $downloadedSize * 1024);
}
-elsif ($prevLine =~ /^\s*\S+\s+\S+\s+\S+\s+([0-9.]+)([kMG]?)\s+\S+\s+\S+\s+[0-9.]+[kMG]?\s+\d\s+[0-9\-:]+\s+[0-9\-:]+\s+[0-9\-:]+\s+[0-9.]+[kMG]?/) {
- if ($2 eq "k") {
- print $1 / 1024;
- }
- elsif ($2 eq "M") {
- print $1;
- }
- elsif ($2 eq "G") {
- print $1 * 1024;
- }
- else {
- print $1 / (1024 * 1024);
- }
+else {
+ printf ("%.1f", $downloadedSize / (1024 * 1024));
}
--
1.7.11.5

Powered by Google Project Hosting