def _parse_torrents_from_url(session, url):
    search_url = TORRENTLEECH_BASE_URL + url
    response = session.get(search_url)

    torrents = list()

    if response.status_code == 200:
        parsed_response = BeautifulSoup(response.content, 'html.parser')
        table = parsed_response.find(id='torrenttable').find("tbody")
        for single_torrent_dom in table.find_all('tr'):
            url = single_torrent_dom.find('td',
                                          'quickdownload').find('a')['href']
            size_str = single_torrent_dom.find_all('td')[4].get_text()
            seeders = int(single_torrent_dom.find('td', 'seeders').get_text())
            leechers = int(
                single_torrent_dom.find('td', 'leechers').get_text())

            logging.debug(
                "Creating torrent (url={url}, size={size}, seeders={seeders}, leechers={leechers})"
                .format(url=url,
                        size=size_str,
                        seeders=seeders,
                        leechers=leechers))
            torrents.append(torrent.Torrent(url, size_str, seeders, leechers))

    return torrents
예제 #2
0
 def __init__(self, meta_filename, temp_file='temp.bytes'):
     self.meta = metainfo.MetainfoFile(meta_filename)
     self.client = client.Client()
     self.sock = 0
     self.host, self.port = self.meta.announce_url_and_port
     self.temp_file = temp_file
     self.torrent_download = torrent.Torrent(self.meta, self.temp_file)
     open(temp_file, 'w').close()
예제 #3
0
 def __init__(self,torrent_file):
     self.torrent_file = torrent_file
     random.seed(datetime.datetime.now())
     self.peer_id = "".join([str(random.randint(0,9)) for i in range(20)])
     self.torrent = torrent.Torrent(self.torrent_file, self.peer_id)
     self.event = "started"
     self.tracker = tracker.Tracker(self.torrent, 6881, self.event)
     self.tracker.results()
예제 #4
0
    def __init__(self):
        self.torrent = torrent.Torrent().load_from_path("torrent.torrent")
        self.tracker = tracker.Tracker(self.torrent)

        self.pieces_manager = pieces_manager.PiecesManager(self.torrent)
        self.peers_manager = peers_manager.PeersManager(self.torrent, self.pieces_manager)

        self.peers_manager.start()
        logging.info("PeersManager Started")
        logging.info("PiecesManager Started")
예제 #5
0
    def __init__(self):
        movie = ''
        self.torrent = torrent.Torrent().open_from_file(movie)
        self.tracker = tracker.Tracker(self.torrent)

        self.pieces_manager = pieces_manager.PiecesManager(self.torrent)
        self.peers_manager = peers_manager.PeersManager(
            self.torrent, self.pieces_manager)

        self.peers_manager.start()
        logging.info("PeersManager Started")
        logging.info("PiecesManager Started")
예제 #6
0
    def __init__(self):
        if len(sys.argv) <= 2 and len(sys.argv) > 1:
            self.torrent = torrent.Torrent().load_from_path(sys.argv[1])
        else:
            print("Usage : python3 main.py <path_to_torrent_file> \n")
            sys.exit(1)

        self.tracker = tracker.Tracker(self.torrent)

        self.pieces_manager = pieces_manager.PiecesManager(self.torrent)
        self.peers_manager = peers_manager.PeersManager(
            self.torrent, self.pieces_manager)

        self.peers_manager.start()
        logging.info("PeersManager Started")
        logging.info("PiecesManager Started")
예제 #7
0
파일: main.py 프로젝트: FRNOmsk/myTorr
def main():
    loop = asyncio.get_event_loop()
    client = TorrentClient(torrent.Torrent('hunt.torrent'))
    task = loop.create_task(client.start())

    # print(client)

    def signal_handler(*_):
        logging.info('Exiting, please wait until everything is shutdown...')
        client.stop()
        task.cancel()

    signal.signal(signal.SIGINT, signal_handler)

    try:
        loop.run_until_complete(task)
    except CancelledError:
        logging.warning('Event loop was canceled')
예제 #8
0
    def start(self, torrent_path_or_content):
        meta = None
        if isinstance(torrent_path_or_content, bytes):
            meta = torrent.Torrent(torrent_path_or_content)
        else:
            meta = torrent.Torrent.from_file(torrent_path_or_content)
        
        store = storage.SynchronizedStorage(meta)

        coord = manager.PeerManager(\
            self._peer_id, self._acceptor, meta, store)
        tracker = tracker_client.AsyncTrackerManager(\
            coord, store.missing(), self._acceptor.port)
        coord.set_tracker(tracker)

        coord.start()

        if not self._started:
            self._started = True
            self._acceptor.start()
예제 #9
0
    def start_magnet_onclick(self, magnet):
        global magnets, notify
        if self.ListOfTorrents.count() == 0:
            self.TorrentInformation.setText("Torrent list empty")
            return
        self.TorrentInformation.setText("Retrieving torrent metadata")

        try:
            self.torrent_client = torrent.Torrent(path)
        except:
            self.TorrentInformation.setText("Could not open target folder")
            return

        torrent.set_notification(notify)
        self.EndTorrent.show()
        self.PauseTorrent.show()
        self.StartTorrent.hide()
        self.torrent_client.listChanged.connect(self.onListChanged)
        self.torrent_client.countChanged.connect(self.onCountChanged)
        self.torrent_client.statusChanged.connect(self.onStatusChanged)
        self.torrent_client.start()
예제 #10
0
    def get_files(self, link):
        try:
            http_client = httpclient.HTTPClient()
            request = tornado.httpclient.HTTPRequest(link,
                                                     method='GET',
                                                     validate_cert=0)
            response = http_client.fetch(request)

            folder_name = str(uuid.uuid4())
            folder_name = '/tmp/{}'.format(folder_name)
            z = zipfile.ZipFile(BytesIO(response.body))
            z.extractall(folder_name)
        except Exception as e:
            log.error('{},{}'.format(folder_name, e))
        else:
            http_client.close()
            try:
                files = listdir(folder_name)
                files_1080 = [x for x in files if '1080' in x]
                files_720 = [x for x in files if '720' in x]
                if files_1080:
                    files = files_1080
                elif files_720:
                    files = files_720
                files.sort()

                torrent_file = '{}/{}'.format(folder_name, files[1])
                subtitle_file = '{}/{}'.format(folder_name, files[0])
                new_subtitle_file = files[0]

                tor = torrent.Torrent()
                tor.start(torrent_file, subtitle_file, new_subtitle_file)

                shutil.rmtree(folder_name)

            except Exception as e:
                log.error(e)
예제 #11
0
파일: manager.py 프로젝트: kapetan/bitless
    import time
    import bitfield
    import random
    import peer
    import storage

    # Setup logging.
    logger = logging.getLogger('bittorrent')
    logger.setLevel(logging.INFO)
    sthl = logging.StreamHandler()
    formatter = logging.Formatter(\
        "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
    sthl.setFormatter(formatter)
    logger.addHandler(sthl)

    t = torrent.Torrent('trusted-computing.torrent')
    addr = ('localhost', 3000)
    peer_id = b'a1b2c3d4e5f6g7h8i9j0'
    sock = socket.socket()
    #sock.settimeout(10)
    sock.connect(addr)

    class StorageMock(object):
        def __init__(self, t):
            self._torrent = t

        def has(self, piece):
            return False

        def completed(self):
            return False
예제 #12
0
    def peers(self):
        return self._peers

    @property
    def tracker(self):
        return self._tracker

    def peers_enum(self):
        for peer in self._peers:
            yield peer[b'ip'], peer[b'port']


if __name__ == '__main__':
    import torrent

    torrent = torrent.Torrent("trusted-computing.torrent")
    tracker = TrackerManager(\
        torrent, torrent.length, "a1b2c3d4e5f6g7h8i9j0", 6881)
    response = tracker.request()

    print(response.interval)
    print(response.min_interval)
    print(response.peers)
    print(len(response.peers))
    print(response.complete)
    print(response.incomplete)
    print(response.tracker_id)
    print(response.tracker)

    for peer in response.peers_enum():
        print(peer)
예제 #13
0
파일: main.py 프로젝트: GurovNik/tor
import time
import peers_manager
import pieces_manager
import torrent
import tracker
import os
import message

torrent = torrent.Torrent().load_from_path("sintel.torrent")
tracker = tracker.Tracker(torrent)
pieces_manager = pieces_manager.PiecesManager(torrent)
peers_manager = peers_manager.PeersManager(torrent, pieces_manager)
peers_manager.start()

peers_dict = tracker.get_peers_from_trackers()
peers_manager.add_peers(peers_dict.values())

while not pieces_manager.all_pieces_completed():
    if not peers_manager.has_unchoked_peers():
        time.sleep(1)
        continue

    for piece in pieces_manager.pieces:
        index = piece.piece_index

        if pieces_manager.pieces[index].is_full:
            continue

        peer = peers_manager.get_random_peer_having_piece(index)
        if not peer:
            continue