Exemplo n.º 1
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'