Exemplo n.º 1
0
def add_torrent(torrent, category=None):
  try:
    c = get_client()
    dir = ensure_directory("holeio")
    # Transfer object
    if category:
      dir = ensure_directory(category, dir.id)
    result = c.Transfer.add_torrent(torrent, dir.id, extract=True)
    db.add_history("Uploaded torrent from %s" % str(torrent))
    return result
  except:
    logger.error("Problem adding torrent")
    db.add_history("Problem uploading torrent from %s" % str(torrent))
Exemplo n.º 2
0
def add_torrent(torrent, category=None):
    try:
        c = get_client()
        dir = ensure_directory("holeio")
        # Transfer object
        if category:
            dir = ensure_directory(category, dir.id)
        result = c.Transfer.add_torrent(torrent, dir.id, extract=True)
        db.add_history("Uploaded torrent from %s" % str(torrent))
        return result
    except:
        logger.error("Problem adding torrent")
        db.add_history("Problem uploading torrent from %s" % str(torrent))
Exemplo n.º 3
0
def add_torrent_uri(torrent_uri, category=None):
    try:
        c = get_client()
        dir = ensure_directory("holeio")
        # Transfer object
        if category:
            dir = ensure_directory(category, dir.id)
        # Bugged: Doesn't pass parent.
        # result = c.Transfer.add_url(torrent_uri, dir.id, extract=True)
        # result = c.Transfer.add_url(torrent_uri, dir.id, extract=True)
        c.request("/transfers/add", method="POST",
                  data={"url": torrent_uri,
                        "save_parent_id": dir.id,
                        "extract": True})
        db.add_history("Added magnet link %s" % str(torrent_uri))
        # return result
        return True
    except:
        logger.error("Problem adding torrent")
        db.add_history("Problem adding torrent %s" % str(torrent_uri))
Exemplo n.º 4
0
def add_torrent_uri(torrent_uri, category=None):
    try:
        c = get_client()
        dir = ensure_directory("holeio")
        # Transfer object
        if category:
            dir = ensure_directory(category, dir.id)
        # Bugged: Doesn't pass parent.
        # result = c.Transfer.add_url(torrent_uri, dir.id, extract=True)
        # result = c.Transfer.add_url(torrent_uri, dir.id, extract=True)
        c.request("/transfers/add",
                  method="POST",
                  data={
                      "url": torrent_uri,
                      "save_parent_id": dir.id,
                      "extract": True
                  })
        db.add_history("Added magnet link %s" % str(torrent_uri))
        # return result
        return True
    except:
        logger.error("Problem adding torrent")
        db.add_history("Problem adding torrent %s" % str(torrent_uri))
Exemplo n.º 5
0
def download_finished_transfers():
  c = get_client()
  config = ConfigParser.RawConfigParser()
  config.read("holeio.cfg")
  download_dir = config.get('directories', 'download')
  incomplete_dir = config.get('directories', 'incomplete')
  for transfer in c.Transfer.list():
    logger.info("looking at transfer %s" % transfer)
    logger.info("status is %s" % transfer.status)
    logger.info("downloaded is %s" % transfer.downloaded)
    if (transfer.status in ["COMPLETED", "SEEDING"]):
      logger.info("Need to download finished transfer: %s" % transfer)
      try:
        file = c.File.get(transfer.file_id)
      except Exception as e:
        logger.info("Skipping file, %s" % e)
        continue
      parent_dir = file.parent_id
      grandparent_dir = 0
      if parent_dir != 0:
        grandparent_dir = c.File.get(parent_dir).parent_id
      holeio_id = ensure_directory("holeio").id
      if holeio_id not in [parent_dir, grandparent_dir]:
        logger.info("Not under holeio directory.  Skipping")
        continue

      if parent_dir != holeio_id and parent_dir != 0:
        # Use directory as a category
        category = c.File.get(parent_dir).name
      else:
        category = ""
      local_dir = os.path.join(incomplete_dir, category)
      finished_dir = os.path.join(download_dir, category)
      local_path = os.path.join(local_dir, file.name)
      finished_path = os.path.join(finished_dir, file.name)
      if os.path.exists(local_path):
        logger.info("Have %s already, skipping" % local_path)
        continue
      if file.content_type == 'application/x-directory':
        # Mirror it locally
        os.makedirs(local_path)
      logger.info("Starting download to %s..." % local_dir)
      db.add_history("Starting download to %s" % local_path)
      file.download(local_dir, delete_after_download=True)
      logger.info("Finished downloading file to %s.", local_path)
      db.add_history("Finished download to %s" % local_path)
      os.makedirs(finished_dir)
      os.rename(local_path, finished_path)
      logger.info("Renamed from %s to %s", local_path, finished_path)
      db.add_history("Renamed from %s to %s" % (local_path, finished_path))
  logger.info("Done with all transfers, cleaning.")
  c.Transfer.clean()
Exemplo n.º 6
0
def wake():
    wakeup.acquire()
    wakeup.notify()
    logger.info("Waking Downloader...")
    db.add_history("Woke downloader")
    wakeup.release()
Exemplo n.º 7
0
Arquivo: app.py Projeto: KaSt/holeio
#from bottle import run
import os

from holeio import views  # noqa
from holeio import watcher, downloader, db

import logging
logger = logging.getLogger(__name__)

if os.path.isfile('holeio.cfg'):
  #config = ConfigParser.ConfigParser()
  #config.read('holeio.cfg')
  watcher.start_watching()
  downloader.start()

logging.debug("DEBUG logging visible")
logging.info("INFO logging visible")
logging.warning("WARNING logging visible")
db.add_history("Starting hole.io")
Exemplo n.º 8
0
def download_finished_transfers():
    c = get_client()
    config = ConfigParser.RawConfigParser()
    config.read("holeio.cfg")
    download_dir = config.get('directories', 'download')
    incomplete_dir = config.get('directories', 'incomplete')
    downloaded_transfers = []
    for transfer in c.Transfer.list():
        logger.info("looking at transfer %s" % transfer)
        logger.info("status is %s" % transfer.status)
        logger.info("downloaded is %s" % transfer.downloaded)
        if (transfer.status in ["COMPLETED", "SEEDING"]):
            logger.info("Need to download finished transfer: %s" % transfer)
            try:
                transfer_file = c.File.get(transfer.file_id)
            except Exception as e:
                logger.info("Skipping file, %s" % e)
                continue
            parent_dir = transfer_file.parent_id
            grandparent_dir = 0
            if parent_dir != 0:
                grandparent_dir = c.File.get(parent_dir).parent_id
            holeio_id = ensure_directory("holeio").id
            if holeio_id not in [parent_dir, grandparent_dir]:
                logger.info("Not under holeio directory.  Skipping")
                continue

            if parent_dir != holeio_id and parent_dir != 0:
                # Use directory as a category
                category = c.File.get(parent_dir).name
            else:
                category = ""
            local_dir = os.path.join(incomplete_dir, category)
            finished_dir = os.path.join(download_dir, category)
            local_path = os.path.join(local_dir, transfer_file.name)
            finished_path = os.path.join(finished_dir, transfer_file.name)
            if os.path.exists(local_path):
                logger.info("%s exists, deleting and trying over")
                shutil.rmtree(local_path)
            if transfer_file.content_type == 'application/x-directory':
                # Mirror it locally
                if not os.path.exists(local_dir):
                    try:
                        os.makedirs(local_dir)
                    except OSError:
                        pass
            logger.info("Starting download to %s..." % local_path)
            db.add_history("Starting download to %s" % local_path)
            transfer_file.download(local_dir, delete_after_download=True)
            logger.info(
                "Finished downloading file to %s. Changing permissions.",
                local_path)
            db.add_history("Finished download to %s. Changing permissions" %
                           local_path)
            downloaded_transfers.append(transfer)
            if os.path.isdir(local_path):
                os.chmod(local_path, 0o777)
                for root, dirs, files in os.walk(local_path):
                    for d in dirs:
                        os.chmod(os.path.join(root, d), 0o777)
                    for f in files:
                        os.chmod(os.path.join(root, f), 0o666)
            try:
                os.makedirs(finished_dir)
            except OSError:
                pass
            os.rename(local_path, finished_path)
            logger.info("Renamed from %s to %s", local_path, finished_path)
            db.add_history("Renamed from %s to %s" %
                           (local_path, finished_path))
    for transfer in downloaded_transfers:
        print transfer.name, transfer.status
        if transfer.status in ['DOWNLOADING', 'IN_QUEUE']:
            continue
        if transfer.is_private:
            # TODO: configurable ratio
            if transfer.status == 'SEEDING' or transfer.current_ratio < 1.99:
                continue
        print 'Removing transfer %s' % transfer.name
        transfer.cancel()
Exemplo n.º 9
0
import bottle

from bottle import run
import ConfigParser
import os

from holeio import views  # noqa
from holeio import watcher, downloader, db

import logging

logger = logging.getLogger(__name__)

if os.path.isfile('holeio.cfg'):
    config = ConfigParser.ConfigParser()
    config.read('holeio.cfg')
    if config.get('oauth', 'token'):
        watcher.start_watching()
        downloader.start()

logging.debug("DEBUG logging visible")
logging.info("INFO logging visible")
logging.warning("WARNING logging visible")
db.create_tables()
db.add_history("Starting hole.io")

if __name__ == "__main__":
    run(host='localhost', port=8080)

app = bottle.default_app()
Exemplo n.º 10
0
def download_finished_transfers():
    c = get_client()
    config = ConfigParser.RawConfigParser()
    config.read("holeio.cfg")
    download_dir = config.get('directories', 'download')
    incomplete_dir = config.get('directories', 'incomplete')
    downloaded_transfers = []
    for transfer in c.Transfer.list():
        logger.info("looking at transfer %s" % transfer)
        logger.info("status is %s" % transfer.status)
        logger.info("downloaded is %s" % transfer.downloaded)
        if (transfer.status in ["COMPLETED", "SEEDING"]):
            logger.info("Need to download finished transfer: %s" % transfer)
            try:
                transfer_file = c.File.get(transfer.file_id)
            except Exception as e:
                logger.info("Skipping file, %s" % e)
                continue
            parent_dir = transfer_file.parent_id
            grandparent_dir = 0
            if parent_dir != 0:
                grandparent_dir = c.File.get(parent_dir).parent_id
            holeio_id = ensure_directory("holeio").id
            if holeio_id not in [parent_dir, grandparent_dir]:
                logger.info("Not under holeio directory.  Skipping")
                continue

            if parent_dir != holeio_id and parent_dir != 0:
                # Use directory as a category
                category = c.File.get(parent_dir).name
            else:
                category = ""
            local_dir = os.path.join(incomplete_dir, category)
            finished_dir = os.path.join(download_dir, category)
            local_path = os.path.join(local_dir, transfer_file.name)
            finished_path = os.path.join(finished_dir, transfer_file.name)
            if os.path.exists(local_path):
                logger.info("%s exists, deleting and trying over")
                shutil.rmtree(local_path)
            if transfer_file.content_type == 'application/x-directory':
                # Mirror it locally
                if not os.path.exists(local_dir):
                    try:
                        os.makedirs(local_dir)
                    except OSError:
                        pass
            logger.info("Starting download to %s..." % local_path)
            db.add_history("Starting download to %s" % local_path)
            transfer_file.download(local_dir, delete_after_download=True)
            logger.info("Finished downloading file to %s. Changing permissions.",
                        local_path)
            db.add_history("Finished download to %s. Changing permissions" %
                           local_path)
            downloaded_transfers.append(transfer)
            if os.path.isdir(local_path):
                os.chmod(local_path, 0o777)
                for root, dirs, files in os.walk(local_path):
                    for d in dirs:
                        os.chmod(os.path.join(root, d), 0o777)
                    for f in files:
                        os.chmod(os.path.join(root, f), 0o666)
            try:
                os.makedirs(finished_dir)
            except OSError:
                pass
            os.rename(local_path, finished_path)
            logger.info("Renamed from %s to %s", local_path, finished_path)
            db.add_history("Renamed from %s to %s" % (local_path, finished_path))
    for transfer in downloaded_transfers:
        print transfer.name, transfer.status
        if transfer.status in ['DOWNLOADING', 'IN_QUEUE']:
            continue
        if transfer.is_private:
            # TODO: configurable ratio
            if transfer.status == 'SEEDING' or transfer.current_ratio < 1.99:
                continue
        print 'Removing transfer %s' % transfer.name
        transfer.cancel()