Example #1
0
 def fetch_tpb_details(self, link, index):
     """
     Fetch TPB torrent details and save it in custom HTML file.
     
     The file is stored in hard-drive with link printed and copied to clipboard
     automatically.
     """
     import torrench.modules.tpb_details as tpb_details
     self.logger.debug("fetching torrent details...")
     file_url = tpb_details.get_details(link, str(index))
     self.logger.debug("details fetched. saved in %s" % (file_url))
     return file_url
Example #2
0
def get_torrent(url):
    index = 999
    while (index != 0):
        try:
            index = int(input("\n(0=exit)\nindex > "))
            if index == 0:
                print("\nBye!")
                sys.exit(2)
            selected_torrent, req_magnetic_link, torrent_link = mapper[index]
        except ValueError:
            print("\nBad Input!")
            continue
        except IndexError:
            print("\nBad Input!")
            continue

        print("Selected index [%d] - %s\n" % (index, selected_torrent))
        option2 = input(
            "1. Print magnetic link [m]\n2. Get torrent details [g]\n\nOption [m/g]: "
        )
        if option2 == 'm' or option2 == 'g':
            if option2 == 'm':
                print("\nMagnetic link - %s" %
                      (RED + req_magnetic_link + RESET))
                uip = input("\nLoad to torrent client? [y/n]: ")
                if uip == 'y' or uip == 'Y':
                    try:
                        webbrowser.open_new_tab(req_magnetic_link)
                    except Exception as e:
                        print(e)
                        continue
            elif option2 == 'g' or option2 == 'G':
                print("Fetching details for torrent index [%d] : %s" %
                      (index, selected_torrent))
                file_url = get_details(torrent_link, str(index))
                file_url = YELLOW + file_url + RESET
                print("File URL: " + file_url + "\n")
Example #3
0
    def select_torrent(self):
        """
        To select required torrent.

        Torrent is selected through index value.
        Two options are present:
        1. To print magnetic link and upstream link to console.
        Further, torrent can be added directly to client (Note: May not work everytime.)
        2. To fetch torrent details (saved in dynamically generated .html file)
        """
        self.logger.debug("Selecting torrent...")
        temp = 9999
        while (temp != 0):
            try:
                temp = int(input("\n(0=exit)\nindex > "))
                self.logger.debug("selected index %d" % (temp))
                if temp == 0:
                    print("\nBye!")
                    self.logger.debug("Torrench quit!")
                    break
                elif temp < 0:
                    print("\nBad Input!")
                    continue
                else:
                    selected_torrent, req_magnetic_link, torrent_link = self.mapper[
                        temp - 1]
                    print("Selected index [%d] - %s\n" %
                          (temp, selected_torrent))
                    self.logger.debug("selected torrent: %s ; index: %d" %
                                      (self.non_color_name, temp))
                    temp2 = input(
                        "1. Print magnetic link [p]\n2. Load magnetic link to client [l]\n3. Get torrent details [g]\n\nOption [p/l/g]: "
                    )
                    temp2 = temp2.lower()
                    self.logger.debug("selected option: [%c]" % (temp2))
                    if temp2 == 'p':
                        self.logger.debug(
                            "printing magnetic link and upstream link")
                        print("\nMagnetic link - %s" %
                              (self.colorify("red", req_magnetic_link)))
                        self.copy_magnet(req_magnetic_link)
                        print("\n\nUpstream link - %s\n" %
                              (self.colorify("yellow", torrent_link)))
                    elif temp2 == 'l':
                        try:
                            self.logger.debug(
                                "Loading magnetic link to client")
                            self.load_torrent(req_magnetic_link)
                        except Exception as e:
                            self.logger.exception(e)
                            continue
                    elif temp2 == 'g':
                        print("Fetching details for torrent index [%d] : %s" %
                              (temp, selected_torrent))
                        self.logger.debug("fetching torrent details...")
                        file_url = tpb_details.get_details(
                            torrent_link, str(temp))
                        self.logger.debug("details fetched. saved in %s" %
                                          (file_url))
                        file_url = self.colorify("yellow", file_url)
                        print("File URL: %s \n" % (file_url))
                    else:
                        self.logger.debug(
                            "Inappropriate input! Should be [p/l/g] only!")
                        print("Bad input!")
                        continue
            except (ValueError, IndexError, TypeError) as e:
                print("\nBad Input!")
                self.logger.exception(e)
                continue