#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    15
    Rep Power
    0

    Torrent Downloader Scripts


    Hello guys in these 2-3 days i have been working on a torrent downloader scripts that allows me to download the best torrents from different websites ( i just got two for now ) with one click!.
    The script actually works, but not very elegant, i hope you guys can give me some tips on how to improve the code mainly with the regex part. The rar zip contains three files, two of the are simply "configuration" files used to store hexcharts and website regex. Do you think i should use another way to store this kind of information?

    Here is the anti-virus scan
    Anti-Virus Scan from VirusTotal

    here is the download from mediafire
    Download
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,843
    Rep Power
    480
    Looks good to me, leaving a few ideas. This post is so complicated to write that if I had other thoughts they are lost.

    html suggestions:
    Take this regular expression. As I recall, double quotes about a string that doesn't contain spaces is optional.
    h33t_torrent['seed_re'] = '<span style="color:[a-z]*">[0-9]*'
    Your regular expression works for the websites you've found, and writing the more general re is perhaps painful and certainly harder to comprehend.

    refactoring suggestions:

    You could learn more about lists. I haven't tested any of these replacements---I'll bet they're mostly correct and all conceptually correct.
    Code:
        # index stride
        self.leeches = self.seeds[1::2] # make leeches from the odd index entries of seeds
        self.seeds = self.seeds[::2]    # retain even entries
    
        # in place of
    
        i = 0
        self.leeches = list()
        for s in self.seeds :
            if i == 0 :
                i += 1
                continue
            elif i == 1 :
                self.leeches.append(s)
                self.seeds.remove(s)
                i == 0
    Code:
        # extend method
        self.all_downloads.extend(self.downloads)
    
        # in place of
    
        for d in self.downloads : self.all_downloads.append(d)
    Code:
        # list indexing for assignment
        self.all_links[1:1+len(self.all_names)] = self.all_names
    
        # in place of
    
        id = 1
        for name in self.all_names :
            self.all_links[id] = name
            id += 1
    reduce duplicate code
    Code:
        # reduce duplicate code
        # move the lower method call so you do it just once.
        action = raw_input(' T >>> ')  .  lower()  # stick the lower here
        if action == 'q' or action == 'quit':
    
        # in place of
    
        action = raw_input(' T >>> ')
        if action.lower() == 'q' or action.lower() == 'quit':
    Code:
        # reduce duplicate code
        # use the string index method
        # if website['seed_re'] is a string
    
        re_count = website['seed_re'].index('[')
    
        # in place of
    
        seed_re = ''
        re_count = 0
        while website['seed_re'][re_count] != '[' :
            seed_re += website['seed_re'][re_count]
            re_count += 1
    list comprehension
    Code:
        # consider list comprehensions.  Actually, everytime I've
        # timed a list comprehension versus a for loop the for loop
        # such as you have has always performed better.
    
        self.leeches = [leech[len(leech_re)] for leech in self.leeches]
    
        # in place of
    
        for i in range(len(self.leeches)):
            self.leeches[i] = self.leeches[i][len(leech_re):]
    Last edited by b49P23TIvg; July 29th, 2012 at 09:14 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    15
    Rep Power
    0
    Originally Posted by b49P23TIvg
    Looks good to me, leaving a few ideas. This post is so complicated to write that if I had other thoughts they are lost.

    html suggestions:
    Take this regular expression. As I recall, double quotes about a string that doesn't contain spaces is optional.
    h33t_torrent['seed_re'] = '<span style="color:[a-z]*">[0-9]*'
    Your regular expression works for the websites you've found, and writing the more general re is perhaps painful and certainly harder to comprehend.

    refactoring suggestions:

    You could learn more about lists. I haven't tested any of these replacements---I'll bet they're mostly correct and all conceptually correct.
    Code:
        # index stride
        self.leeches = self.seeds[1::2] # make leeches from the odd index entries of seeds
        self.seeds = self.seeds[::2]    # retain even entries
    
        # in place of
    
        i = 0
        self.leeches = list()
        for s in self.seeds :
            if i == 0 :
                i += 1
                continue
            elif i == 1 :
                self.leeches.append(s)
                self.seeds.remove(s)
                i == 0
    Code:
        # extend method
        self.all_downloads.extend(self.downloads)
    
        # in place of
    
        for d in self.downloads : self.all_downloads.append(d)
    Code:
        # list indexing for assignment
        self.all_links[1:1+len(self.all_names)] = self.all_names
    
        # in place of
    
        id = 1
        for name in self.all_names :
            self.all_links[id] = name
            id += 1
    reduce duplicate code
    Code:
        # reduce duplicate code
        # move the lower method call so you do it just once.
        action = raw_input(' T >>> ')  .  lower()  # stick the lower here
        if action == 'q' or action == 'quit':
    
        # in place of
    
        action = raw_input(' T >>> ')
        if action.lower() == 'q' or action.lower() == 'quit':
    Code:
        # reduce duplicate code
        # use the string index method
        # if website['seed_re'] is a string
    
        re_count = website['seed_re'].index('[')
    
        # in place of
    
        seed_re = ''
        re_count = 0
        while website['seed_re'][re_count] != '[' :
            seed_re += website['seed_re'][re_count]
            re_count += 1
    list comprehension
    Code:
        # consider list comprehensions.  Actually, everytime I've
        # timed a list comprehension versus a for loop the for loop
        # such as you have has always performed better.
    
        self.leeches = [leech[len(leech_re)] for leech in self.leeches]
    
        # in place of
    
        for i in range(len(self.leeches)):
            self.leeches[i] = self.leeches[i][len(leech_re):]
    Thanks for reading my program and writing this! about the HTML regex is true... the regex are ofcourse site specific, but to add another site you can simply analyze the page with firebug and add more links.

    this one is so ridiculos thanks for the tip :
    Code:
        i = 0
        self.leeches = list()
        for s in self.seeds :
            if i == 0 :
                i += 1
                continue
            elif i == 1 :
                self.leeches.append(s)
                self.seeds.remove(s)
                i == 0
    i don't know where to start i didn't even know the .index() method that definetly is faster than my for loop
    But if you say that the list comprehension is slower i think i'll stick with the 'for loop', because the search is already slow so i'm not gonna slow it down more!.
    Thanks a lot for the time, i'm gonna fix the thing you pointed, they are really helpful. But what do you think about the rest of the program?
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,843
    Rep Power
    480
    Originally Posted by b49P23TIvg
    Looks good to me
    The things you want to "fix" aren't "broken". I'm merely aware of python shorthand.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    15
    Rep Power
    0
    Ok :P

IMN logo majestic logo threadwatch logo seochat tools logo