Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

python/batch- getting size of torrent files

Name: gC 2005-03-27 8:51

winxp / python240

Took me like 2 hours to get through this, and since I couldn't find anything to do this with tools I already had or on the net, I made a script up.

Basically, running the batch by itself scans the dir the script&batch is in for torrent files, then for each file it reads the files and rips out the proper filesize values of the files, adds them together and prints it. The batch file does the output redirection and per file stuff. 'nix people can probably do their own version of this batch file maybe, you leet haxors you.

why do this?: I do not want (whinge) to open my bt program just to open a file and choose a place to store the contents of the torrent. and then get to see the filesize of whetever is in the torrent.
I just want to see how big it will be.

the .py file by itself can accept multiple arguments, but, you need to enclose the names in quotes, otherwise python will split up the (filenames that have spaces in them) you give it into multiple arguments you didnt want and then fuck up grandly.

edit it whatever I don't really care, since youre probably going to remove the /b references and all the other shit ha :D oh and obfuscation is great for multiple regexps

also theres a commented out part at the end to get the .py script to halt and wait for someone to press [enter], thats just to make it a blocking script if you want, that line would need to be copied to just before the other exit point of the script as well.

I think that was all hey, torrentsize.py, size.bat follows:

Name: Anonymous 2005-03-27 8:52

#! c:\develop\python240\python.exe
import sys, os, string, re

def lionstigersandbears(text): #oh my!
    p = re.compile('hi\d+e') #only the one length value in file ie a single file torrent
    m = p.search(text)
    o = m.group()
    o = o.lstrip('hi')
    o = o.rstrip('e')
    o = int(o)
    PRINTSHIT2(o)

def PRINTSHIT(o):
    x = 0.00
    for i in range(len(o)):
        x += o[i]
    print int(x), 'bytes total'
    print '=', int(x/1024), 'KB'

    print '=', int((x/1024)/1024), 'MB'
    print '=', round((((x/1024)/1024)/1024), 2), 'GB'

def PRINTSHIT2(o):
    x = 0.00
    x = o
    print int(x), 'bytes total'
    print '=', int(x/1024), 'KB'

    print '=', int((x/1024)/1024), 'MB'
    print '=', round((((x/1024)/1024)/1024), 2), 'GB'
    print "thrustvectoring just kicked in yo"
    sys.exit(0)

args = sys.argv[1:] #all the param filnames a durr
for arg in args:
    print arg
    f = open(arg, 'r')
    text = f.read()
    p = re.compile('ld[\w\W]*eee') #want ld,big chunk of text,eee
    m = p.search(text)
    #print m.group() #m.group() = megatextchunk for a multifile torrent
    try:
        n = m.group()
    except AttributeError:
        lionstigersandbears(text)
    q = re.compile('i\d+e')
    o = q.findall(n)
    #print o
    for i in range(len(o)):
        o[i] = o[i].lstrip('i')
        o[i] = o[i].rstrip('e')
        o[i] = int(o[i])
    #print o
    PRINTSHIT(o)

#a = raw_input( "Type something to exit: ")
print "thrustvectoring just kicked in yo"

Name: Anonymous 2005-03-27 8:53

@echo on
@lfnfor on
cd c:\downloads
REM for %%x in (*.torrent) do python torrentsize.py "%%x" > %%x.txt
for %%x in (*.torrent) do python torrentsize.py "%%x" >> SIZES.txt

Name: Anonymous 2005-06-03 22:53

This is basically just a warped version of "btshowmetainfo.py" that comes from the site.
You will need python and bt source to run this.

Use: ./btshowprog.py torrent.torrent

#!/usr/bin/env python

from sys import *

path.append('/home/joe/BitTorrent-3.4.2/')
path.append('/home/joe/code/python/')



from BitTorrent.bencode import *
import os, os.path
import PB

if len(argv) == 1:
    print '%s file.torrent' % argv[0]
    print
    exit(2)
for metainfo_name in argv[1:]:
    metainfo_file = open(metainfo_name, 'rb')
    metainfo = bdecode(metainfo_file.read())
    metainfo_file.close()
    info = metainfo['info']

    piece_length = info['piece length']
    if info.has_key('length'):
        # let's assume we just have a file
        print 'file name.....: %s' % info['name']
        file_length = info['length']
        name = info['name'] + "..:" #'file size.....:'
        done_length = os.path.getsize(info['name'])
    else:
        # let's assume we have a directory structure
        length_list = {}
        tdir = info['name'] + '/'
        file_length = 0; done_length = 0;
        for file in info['files']:
            path = ''
            for item in file['path']:
                if (path != ''):
                   path = path + "/"
                path = path + item

            file['cur_length'] = os.path.getsize(tdir + path)
            file['path'] = path

            prog = PB.progressBar(0, file['length'], 17)
            prog.updateAmount(int(file['cur_length']))
            file_length += file['length']
            done_length += int(file['cur_length'])
            if len(path) > 20:
                p_path = path[0:21] + "..."
            else: p_path = path
            print '%s (%i of %i bytes) %s' \
                 % (p_path, file['cur_length'], file['length'],  prog)


        name = info['name'] + "..:"

    prog = PB.progressBar(0, file_length, 30)
    prog.updateAmount(int(done_length))
    print
    print ' >> %s %i of %i MegaBytes completed' \
         % (name,done_length / 1024**2, file_length / 1024**2)
    print ' >> %s' %prog


Name: Anonymous 2007-12-20 2:04

Read SICP.

Name: Anonymous 2007-12-20 4:38

What the fuck.

This is the worst code i've ever seen.

It's a good thing you commented raw_input( "Type something to exit: ") out, otherwise you might of looked like a fucking idiot.

Read SICP, faggot.

Name: Anonymous 2009-03-18 3:01

I wants lots and lots of some delectable pot!

Marijuana MUST be legalized.

Name: Trollbot9000 2009-07-01 10:57

Done is learning more Buy or borrow  some books that  other people bought.

Name: Anonymous 2010-12-09 21:12

Name: Anonymous 2011-03-02 21:32

I AM THE MOST FUCKING NGGER MATURE

Name: Anonymous 2012-05-05 22:14

CHECK MY FUCKING DOUBLES

Name: Anonymous 2012-05-07 1:31

python2.4 were dark days

Name: Anonymous 2012-05-07 6:33

>>12
I still have to test my software against it because it is included in older releases of certain lunix distros with ongoing or recently expired support.  Which means that I'm restricted from using all nice things that appeared  since then.  I write Python and I still hate my job, all because of Python 2.4.

Name: Anonymous 2012-05-07 13:15

>>13
Which distros are those? Even Debian oldstable (which lost support in February) was on 2.5.

Name: Anonymous 2013-07-25 0:02

Lisp

Name: Anonymous 2013-07-25 0:03

>>15
Fuck you again:
2005-03-27 08:51

Name: Anonymous 2013-07-25 0:19

>>16
Yes.

Name: Anonymous 2013-07-25 0:30

>>19
see >>17

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-07-25 0:39

ittakea less bytse to dotthis in Asm than yours ource code

Don't change these.
Name: Email:
Entire Thread Thread List