Ejemplo n.º 1
0
    def test_get_files_details(self):
        """ Test getting the name, length and checksum of the files inside a valid torrent file. """
        import os

        for torrent_file in TORRENTS_INFO:
            tp = TorrentParser("test_data/%s" % torrent_file)
            self.assertItemsEqual(tp.get_files_details(), TORRENTS_INFO[torrent_file]["file_details"])
Ejemplo n.º 2
0
 def test_get_creation_date(self):
     """ Test getting creation date from a valid torrent file. """
     for torrent_file in TORRENTS_INFO:
         tp = TorrentParser("test_data/%s" % torrent_file)
         self.assertEqual(
             tp.get_creation_date(),
             datetime.utcfromtimestamp(TORRENTS_INFO[torrent_file]["creation_date"]).isoformat(),
         )
Ejemplo n.º 3
0
from torrentparser import TorrentParser

torrent_info = TorrentParser('test_torrents/rs.torrent')

x =  torrent_info.get_files_details()

print type(x)

for t in x:
    #print t
    print "Name: %s, Size: %d" %(t[0], t[1])
Ejemplo n.º 4
0
 def test_get_client_name(self):
     """ Test getting Client name from a valid torrent file. """
     for torrent_file in TORRENTS_INFO:
         tp = TorrentParser("test_data/%s" % torrent_file)
         self.assertEqual(tp.get_client_name(), TORRENTS_INFO[torrent_file]["client_name"])
Ejemplo n.º 5
0
 def test_get_tracker_url(self):
     """ Test getting Tracker URL from a valid torrent file. """
     for torrent_file in TORRENTS_INFO:
         tp = TorrentParser("test_data/%s" % torrent_file)
         self.assertEqual(tp.get_tracker_url(), TORRENTS_INFO[torrent_file]["tracker_url"])
Ejemplo n.º 6
0
import socket
from requests.exceptions import RequestException, Timeout
from pymongo import Connection

from config import MONGO, UPDATE_NUM, REQUEST_TIMEOUT
from torrentparser import TorrentParser, ParsingError
from log_manager import LogManager

# TOOD single file
mongo = Connection(host=MONGO['host'], port=MONGO['port'])
db = mongo[MONGO['db']]

logger = LogManager("application.log")

# TODO implement it in C
tp = TorrentParser.get_instance()


#parse torrent file
def parse_torrent_file(file):
    try:
        tp.parse_torrent(file)
        return {
            "name": tp.get_torrent_name(),
            "file_list": tp.get_files_details(),
            "creation_date": tp.get_creation_date(),
            "tracker_url": tp.get_tracker_url(),
            "client_name": tp.get_client_name(),
            # TODO how to get torrent description?
            "description": None,
            "parse_result": 'ok'