Example #1
0
def callback_info_answer(message):
    info = Torrent.getInfoTorrent(Torrent.getTorrentID(message.message.text))
    if (info):
        if (len(info) < 200):
            bot.answer_callback_query(message.id, info, True)
        else:
            bot.answer_callback_query(message.id, Dialog.textTooLarge)
            bot.send_message(message.from_user.id, info)
    else:
        bot.answer_callback_query(message.id, Dialog.genericError)
Example #2
0
def callback_prev_answer(message):
    prevTorrent = Torrent.getPreviousTorrent(
        Torrent.getTorrentID(message.message.text))
    if (prevTorrent):
        bot.edit_message_text(prevTorrent,
                              message.from_user.id,
                              message.message.message_id,
                              reply_markup=Keyboard.inlineTorrentKeyboard,
                              parse_mode="markdown")
    else:
        bot.answer_callback_query(message.id, Dialog.noPrevious)
Example #3
0
def callback_files_answer(message):
    files = Torrent.getFilesTorrent(Torrent.getTorrentID(message.message.text))
    if (files == -1):
        bot.answer_callback_query(message.id, Dialog.noFiles)
    elif (files):
        if (len(files) < 200):
            bot.answer_callback_query(message.id, files, True)
        else:
            bot.answer_callback_query(message.id, Dialog.textTooLarge)
            bot.send_message(message.from_user.id, files)
    else:
        bot.answer_callback_query(message.id, Dialog.genericError)
Example #4
0
def magnet_answer(message):
    if (Torrent.addTorrentFromMagnet(message.text)):
        bot.send_message(message.chat.id, Dialog.tAdded, parse_mode="markdown")
    else:
        bot.send_message(message.chat.id,
                         Dialog.genericError,
                         parse_mode="markdown")
Example #5
0
def listTorrent_answer(message):
    bot.send_message(message.chat.id,
                     Dialog.wait,
                     reply_markup=Keyboard.torrentMainKeyboard)
    firstTorrent = Torrent.getSingleTorrent(1)
    print firstTorrent
    if (firstTorrent == -1):
        bot.send_message(message.chat.id,
                         Dialog.noTorrent,
                         reply_markup=Keyboard.mainKeyboard,
                         parse_mode="markdown")
    elif (firstTorrent == -2):
        bot.send_message(message.chat.id,
                         Dialog.genericError,
                         reply_markup=Keyboard.mainKeyboard,
                         parse_mode="markdown")
    elif (firstTorrent == False):
        bot.send_message(message.chat.id,
                         Dialog.retrivingError,
                         reply_markup=Keyboard.mainKeyboard,
                         parse_mode="markdown")
    else:
        bot.send_message(message.chat.id,
                         firstTorrent,
                         reply_markup=Keyboard.inlineTorrentKeyboard,
                         parse_mode="markdown")
Example #6
0
def pauseAll_answer(message):
    if (Torrent.pauseAllTorrent()):
        bot.send_message(message.chat.id,
                         Dialog.pausedAll,
                         reply_markup=Keyboard.torrentMainKeyboard,
                         parse_mode="markdown")
    else:
        bot.send_message(message.chat.id,
                         Dialog.genericError,
                         reply_markup=Keyboard.torrentMainKeyboard,
                         parse_mode="markdown")
 def initAll(self):
     self.isMagnet = Magnet.isMagnetURI(self.torrent_link)
     Logger.info("Initializing Torrent Data")
     if (self.isMagnet == True):
         # Send MagnetURI To class and get torrent Data
         pass
     else:
         # Get Torrent Data From Net
         torrent_raw_data = self.downloadTorrentFile()
         self.torrent = Torrent.Torrent(reactor,
                                        raw_data=torrent_raw_data,
                                        peer_id=self.peerID,
                                        port=self.port)
     Logger.info("Initialization For Torrent Data Complete")
Example #8
0
def file_answer(message):
    if (message.document.mime_type == "application/x-bittorrent"):
        file_info = bot.get_file(message.document.file_id)
        file_name = file_info.file_path.split("/")
        file_name = file_name[1]
        file_path = file_info.file_path
        if (Torrent.addTorrentFromFile(file_path, file_name)):
            bot.send_message(message.chat.id,
                             Dialog.tAdded,
                             parse_mode="markdown")
        else:
            bot.send_message(message.chat.id,
                             Dialog.genericError,
                             parse_mode="markdown")
Example #9
0
    def __init__(self):
        newpeersQueue = Queue.Queue()

        self.torrent = Torrent.Torrent("b.torrent")
        self.tracker = Tracker.Tracker(self.torrent,newpeersQueue)

        self.peerSeeker = PeerSeeker.PeerSeeker(newpeersQueue, self.torrent)
        self.piecesManager = PiecesManager.PiecesManager(self.torrent)
        self.peersManager = PeersManager.PeersManager(self.torrent,self.piecesManager)

        self.peersManager.start()
        logging.info("Peers-manager Started")

        self.peerSeeker.start()
        logging.info("Peer-seeker Started")

        self.piecesManager.start()
        logging.info("Pieces-manager Started")
Example #10
0
 def thread_torrent(self, path, row):
     torrent_path = path
     print(torrent_path)
     loop = self.get_or_create_eventloop()
     self.tor = Torrent.Torrent(torrent_path)
     print(self.tor.get_torrent_data())
     print(self.tor.get_torrent_ind_size())
     print(self.tor.get_torrent_piece_length())
     print(self.tor.get_torrent_name().decode())
     self.tableWidget.setItem(row, 1, QtWidgets.QTableWidgetItem(str(0)))
     self.tableWidget.setItem(row, 2, QtWidgets.QTableWidgetItem(str(self.tor.get_torrent_size())))
     # loop.run_until_complete(asyncio.gather(*(test_peer_comm(Tracker.Tracker_udp(tor, tracker[0])) for tracker in tor.get_torrent_announce_list()))
     for tracker in self.tor.get_torrent_announce_list():
         test_tracker = Tracker.Tracker_udp(self.tor, tracker[0])
         try:
             #loop.run_until_complete(test_peer_comm(test_tracker))
             loop.run_until_complete(asyncio.gather(self.test_peer_comm(test_tracker), self.get_download_info(row)))
             break
         except Exception as e:
             print("tracker {0} did not work, exception was: {1}".format(tracker[0], e))
     loop.close()
     print("finishing")
Example #11
0
def callback_delete_answer(message):
    if (Torrent.deleteTorrent(Torrent.getTorrentID(message.message.text))):
        bot.answer_callback_query(message.id, Dialog.tRemoved)
        if (Torrent.getPreviousTorrent(
                Torrent.getTorrentID(message.message.text))):
            bot.edit_message_text(Torrent.getPreviousTorrent(
                Torrent.getTorrentID(message.message.text)),
                                  message.from_user.id,
                                  message.message.message_id,
                                  reply_markup=Keyboard.inlineTorrentKeyboard,
                                  parse_mode="markdown")
        else:
            bot.edit_message_text(Dialog.noTorrent + "\n\n" +
                                  Dialog.addNewTorrent,
                                  message.from_user.id,
                                  message.message.message_id,
                                  reply_markup='',
                                  parse_mode="markdown")
    else:
        bot.answer_callback_query(message.id, Dialog.genericError)
Example #12
0
                        type=int,
                        default=6891)
    parser.add_argument('--http',
                        help="file containing json list of urls",
                        type=argparse.FileType('r', encoding="utf-8"))
    parser.add_argument('--list_files',
                        help="Only list the files. do not download",
                        action="store_true")
    args = parser.parse_args()

    logging.basicConfig(filename="/tmp/dtoc_log",
                        filemode="w",
                        level=logging.DEBUG)

    if args.progress: args.verbose = -10000
    torrent = Torrent.Torrent(args.torrent, args.save_to, args.name, args.port,
                              args.verbose)

    if args.list_files:
        for f in torrent._open_files:
            f.close()
        for f in torrent.files:
            print(f.path)
        sys.exit(0)

    if args.progress:
        reactor.callLater(2, torrent.progress_printer)
    if args.http:
        json_list = json.load(args.http)
        if len(json_list) != len(torrent.files):
            raise ValueError("Invalid JSON file for --http")
        httpdownloaders = set()
Example #13
0
def add_torrent():
    print('torrent')
    url = request.args.get('url')
    Torrent.queueTorrent(url, 0)
    return 'Dope', 200
Example #14
0
def list_torrents():
    #    name = request.args.get('name')
    return flask.jsonify(Torrent.listTorrents()), 200
Example #15
0
# coding: utf-8
import PeerProtocol
import Torrent
th = Torrent.Torrent('test.torrent')
p1 = PeerProtocol.BTProtocol(th)
p1.state = PeerProtocol.BTProtocolStates.connected
Example #16
0
def callback_resume_answer(message):
    if (Torrent.resumeTorrent(Torrent.getTorrentID(message.message.text))):
        bot.answer_callback_query(message.id, Dialog.tResumed)
    else:
        bot.answer_callback_query(message.id, Dialog.genericError)
Example #17
0
def callback_pause_answer(message):
    if (Torrent.pauseTorrent(Torrent.getTorrentID(message.message.text))):
        bot.answer_callback_query(message.id, Dialog.tPaused)
    else:
        bot.answer_callback_query(message.id, Dialog.genericError)