def __file_created(self, filename, file_id):
        """ Callback for when the physical torrent file has been downloaded.
            Used when Transmission client is not running
        """

        log.msg('Saved file for torrent. ID: {}'.format(file_id))
        log.msg('Torrent saved at: {}'.format(filename))

        TorrentQueue.update_status(
            new_status=u'FOUND', id=file_id, async=False
        )
    def __error_finding_torrents(self, file_name, file_id):
        """ Error callback for when the physical torrent file has failed to
            downlaod. Used when Transmission client is not running
        """

        log.msg(
            'Problem with downloading torrent {}, going to set '
            'to NOT_FOUND and try again later'.format(file_name)
        )

        TorrentQueue.update_status(
            new_status=u'FOUND', id=file_id, async=False
        )
Beispiel #3
0
    def test_torrent_queue_with_when(self):
        queue = TorrentQueue()
        queue.media_type = u'MOVIE'
        queue.query = u'Titanic'
        queue.download_when = datetime.now()
        queue.status = u'PENDING'
        queue.date_added = datetime.now()
        queue.create()

        queue = TorrentQueue.load()
        self.assertEquals(1, len(queue))
Beispiel #4
0
    def on_torrents_found(self, torrents, db_id):
        """ Callback for reponse from pirate bay sites
            :param: list of torrents
            :param: the id refrencing the queue database table
        """

        if len(torrents) > 0:
            log.msg('Torrent found for queue with id of {}'.format(db_id))

            self.download_manager.download(torrents[0], db_id)
        else:
            log.msg('No Torrents found for queue with id of {}'.format(db_id))

            TorrentQueue.update_status(
                new_status='NOT_FOUND', id=db_id, async=False
            )
            self.error_finding_torrents()
    def _handle_transmission(self, torrent, queue_id):

        if torrent.magnet_link is not None:
            link = torrent.magnet_link
        elif torrent.torrent_link is not None:
            link = torrent.torrent_link
        else:
            self._handle_manual_download(torrent, queue_id)
            return

        directory = self._create_directory(queue_id)
        torrents = self.transmission.add_torrent(link, directory)

        torrent_queue = TorrentQueue(id=queue_id)
        torrent_queue.update_value(
            status=u'FOUND', torrent_hash=torrents.hashString
        )
    def _load_downloading_torrent_queue(self):
        """ Load torrents ready for downloading """

        return TorrentQueue.find(
            (TorrentQueue.status == u'FOUND') |
            (TorrentQueue.status == u'DELETED') |
            (TorrentQueue.status == u'DOWNLOADING'),
            async=False
        )
Beispiel #7
0
    def test_movie_with_when(self):
        movie = Movie()
        movie.name = u'Titanic'
        movie.dvd_release = datetime.strptime('1989-08-17', '%Y-%m-%d')
        movie.theater_release = datetime.strptime('1989-02-17', '%Y-%m-%d')
        movie.rating = 9
        movie.create()

        queue = TorrentQueue.load_pending_queue(async=False)
        self.assertEquals(1, len(queue))

        movie = Movie.load(id=1)
        self.assertEquals(1, len(movie))
Beispiel #8
0
    def test_tv_show_with_when_before_air_date(self):
        tv_show = TVShow()
        tv_show.name = u'The Walking Dead'
        tv_show.season_number = 4
        tv_show.episode_number = 10
        tv_show.air_date = datetime.strptime('2089-08-17', '%Y-%m-%d')
        tv_show.episode_name = u'TWD'
        tv_show.rating = 9
        tv_show.create()

        queue = TorrentQueue.load_pending_queue(async=False)
        self.assertEquals(0, len(queue))

        tv_show = TVShow.load(id=1)
        self.assertEquals(1, len(tv_show))
Beispiel #9
0
    def test_tv_show_no_when(self):
        tv_show = TVShow()
        tv_show.name = u'The Walking Dead'
        tv_show.season_number = 4
        tv_show.episode_number = 10
        tv_show.air_date = datetime.strptime('1989-08-17', '%Y-%m-%d')
        tv_show.episode_name = u'TWD'
        tv_show.rating = 9
        tv_show.create()

        queue = TorrentQueue.load()
        self.assertEquals(1, len(queue))

        tv_show = TVShow.load(id=1)
        self.assertEquals(1, len(tv_show))
Beispiel #10
0
    def search_for_torrents(self):
        log.msg('Searching for my torrents')

        queue = TorrentQueue.load_pending_queue(async=False)

        for torrent in queue:
            req = self.pirate_bay_client.search(
                query=torrent.query,
                optimize_query=True,
                order=ORDERS.SEEDERS.DES,
                category=CATEGORIES.VIDEO.ALL
            )

            req.load_torrents(
                callback=self.on_torrents_found,
                errback=self.error_finding_torrents,
                db_id=torrent.id
            )
Beispiel #11
0
    def update_status(self, request, **kwargs):
        check = self._check_args(kwargs, ('torrent_queue_id', 'status', ))
        if check is not None:
            defer.returnValue(Ok(check))

        queue_id = kwargs.get('torrent_queue_id')
        status = kwargs.get('status', '').upper()

        statuses = (
            'PENDING', 'FOUND', 'NOT_FOUND', 'FINISHED',
            'DOWNLOADING', 'WATCHED', 'DELETED'
        )

        if status not in statuses:
            defer.returnValue(
                Ok(self._generate_response(200, 'Invalid status'))
            )

        yield TorrentQueue.update_status(new_status=status, id=int(queue_id))

        defer.returnValue(Ok(self._generate_response(
            code=0,
            message='Updated status for ID {} to {}'.format(queue_id, status)))
        )
Beispiel #12
0
    def retry_download(self):
        log.msg('Going to reset the statuses of NOT_FOUND items in queue')

        TorrentQueue.update_status(
            new_status='PENDING', status='NOT_FOUND', async=False
        )