MaxP2P Posted November 15, 2009 Report Share Posted November 15, 2009 Hi!One of the features I've been missing the mosts from the usual uT client, is the possibility to view some basic statistics (like how much has been downloaded totally over time).Seeing as how I'm yet to find anyone implementing these features into their UI / Application, I decided to atleast work out a simple php script that just outputs this information on a blank page.Now what I very much would your input on, is how do we solve the persistency problem? Seeing as how the information we get with the script is currently just fetched by iterating through all the added torrents, and then simply just summing up the amount download / uploaded on each of them.But what I want is being able to keep track of an "absolute total", meaning also all the bytes that have been download / uploaded by torrents, including those that have been removed from the client.Any ideas on how we solve that? Simple file storage? Or do some database interaction? =)Here is my script, which is utilizing the PHP API:<?phprequire_once 'api.php';function ByteCalc ($bytes) { $size = $bytes / 1024; if ($size < 1024) { $size = number_format($size, 2); $size .= ' KB'; } else { if ($size / 1024 < 1024) { $size = number_format($size / 1024, 2); $size .= ' MB'; } elseif ($size / 1024 / 1024 < 1024) { $size = number_format($size / 1024 / 1024, 2); $size .= ' GB'; } } return $size;}$client = new uTorrent('HOST', 'PORT', 'USERNAME', 'PASS');$torrents = $client->getTorrents();$downTotal = 0;$upTotal = 0;foreach ($torrents as $torrent) { $downTotal += $torrent[UTORRENT_TORRENT_DOWNLOADED]; $upTotal += $torrent[UTORRENT_TORRENT_UPLOADED];}echo "<b>Total downloaded:</b> " . ByteCalc($downTotal);echo "<br/>";echo "<b>Total uploaded:</b> " . ByteCalc($upTotal); Link to comment Share on other sites More sharing options...
Lord Alderaan Posted November 16, 2009 Report Share Posted November 16, 2009 Maybe use a PHP beencode library to read the values directly from the settings.dat? Link to comment Share on other sites More sharing options...
MaxP2P Posted November 16, 2009 Author Report Share Posted November 16, 2009 Could you elaborate on that a bit more? Seeing as how Google didn't turn up much (this thread came up first, and that's saying something xD)... Link to comment Share on other sites More sharing options...
Ultima Posted November 18, 2009 Report Share Posted November 18, 2009 Reading settings.dat would require that the PHP script runs on the same server as µTorrent, which may not always be the case. The best action would be for µTorrent to allow clients to request this data (or maybe just send the data with /gui/?action=getsettings, or something).There is no reliable way to determine total transfer counts via WebUI. Link to comment Share on other sites More sharing options...
Lord Alderaan Posted November 18, 2009 Report Share Posted November 18, 2009 Ultima is right. The php would have to run on the same machine as µtorrent or at least have physical access to the settings.dat file.Then you could use DeHackEd's beencode php class. Of which a slightly modified version is on the utorrent trac (as part of the Webui-Shell). I couldn't quickly find the original.Then you could use something like the following code (just an example):$settingsdat='full/path/to/settings.dat';require_once('bencode.php');if ( file_exists($settingsdat) ){ if ( is_readable($settingsdat) ) { $decode = new BDecode; $readfile = $decode->decodeDict(file_get_contents($settingsdat)); $td = bytes($readfile[0]["td"]); $tu = bytes($readfile[0]["tu"]); $getdate = date('Y.m.d. H:i:s'); echo '<b>Total Down:</b> '.$td.' <b>Total Up:</b> '.$tu.' <b>Date:</b> '.$getdate; }} Link to comment Share on other sites More sharing options...
MaxP2P Posted November 18, 2009 Author Report Share Posted November 18, 2009 Thanks guys.I'll try out the beencode approach, and see how it works. =)EDIT: Works great! Link to comment Share on other sites More sharing options...
joz Posted December 7, 2009 Report Share Posted December 7, 2009 Het MaxP2P,Could you maybe post some of your code for this?I'm curious myself implementing this in my server consolehttp://tinyurl.com/y9fxw9xI haven't really digged into the beencode source yet but it seems a bit scarcely documented (I like the program against an interface paradigm but I kinda need proper docs to make that work fast) Link to comment Share on other sites More sharing options...
Ultima Posted December 22, 2009 Report Share Posted December 22, 2009 Was Lord Alderaan's example insufficient...? The usage is pretty barebones, as there are really only two functions you need to care about in that library: BEncode(), and BDecode(). Link to comment Share on other sites More sharing options...
joz Posted December 28, 2009 Report Share Posted December 28, 2009 yeah it was, actually. I didn't really take much time to investigate this but it's like you said really easy and Lord Alderaan's example was more then enough. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.