2
# Jason Gerard DeRose <jderose@novacut.com>
4
# dmedia: distributed media library
5
# Copyright (C) 2011 Jason Gerard DeRose <jderose@novacut.com>
7
# This file is part of `dmedia`.
9
# `dmedia` is free software: you can redistribute it and/or modify it under the
10
# terms of the GNU Affero General Public License as published by the Free
11
# Software Foundation, either version 3 of the License, or (at your option) any
14
# `dmedia` is distributed in the hope that it will be useful, but WITHOUT ANY
15
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19
# You should have received a copy of the GNU Affero General Public License along
20
# with `dmedia`. If not, see <http://www.gnu.org/licenses/>.
23
Download with BitTorrent.
32
from dmedia.constants import LEAF_SIZE
33
from dmedia.transfers import HTTPBaseBackend, register_downloader, http_conn
36
log = logging.getLogger()
39
class TorrentBackend(HTTPBaseBackend):
41
Backend for BitTorrent downloads using `libtorrent`.
44
def download(self, doc, leaves, fs):
47
url = self.basepath + self.key(chash, ext) + '?torrent'
50
tmp = fs.tmp(chash, ext, create=True)
51
session = libtorrent.session()
52
session.listen_on(6881, 6891)
54
info = libtorrent.torrent_info(libtorrent.bdecode(data))
56
torrent = session.add_torrent({
58
'save_path': path.dirname(tmp),
61
while not torrent.is_seed():
63
self.progress(s.total_payload_download)
66
session.remove_torrent(torrent)
70
register_downloader('torrent', TorrentBackend)