mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-11 12:04:10 +00:00
file filtering
This commit is contained in:
parent
cbd8f6bad2
commit
9e36eb21f5
@ -85,7 +85,7 @@ class torrent_info:
|
|||||||
self.user_paused = False # start out unpaused
|
self.user_paused = False # start out unpaused
|
||||||
self.uploaded_memory = 0
|
self.uploaded_memory = 0
|
||||||
|
|
||||||
self.filter_out = []
|
self.file_filter = []
|
||||||
|
|
||||||
self.delete_me = False # set this to true, to delete it on next sync
|
self.delete_me = False # set this to true, to delete it on next sync
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ class manager:
|
|||||||
self.constants = pytorrent_core.constants()
|
self.constants = pytorrent_core.constants()
|
||||||
|
|
||||||
# Unique IDs are NOT in the state, since they are temporary for each session
|
# Unique IDs are NOT in the state, since they are temporary for each session
|
||||||
self.unique_IDs = {} # unique_ID -> a torrent object, i.e. persistent data
|
self.unique_IDs = {} # unique_ID -> a torrent_info object, i.e. persistent data
|
||||||
|
|
||||||
# Saved torrent core_states. We do not poll the core in a costly manner, necessarily
|
# Saved torrent core_states. We do not poll the core in a costly manner, necessarily
|
||||||
self.saved_torrent_core_states = {} # unique_ID -> torrent_state
|
self.saved_torrent_core_states = {} # unique_ID -> torrent_state
|
||||||
@ -163,6 +163,9 @@ class manager:
|
|||||||
|
|
||||||
# Sync with the core: tell core about torrents, and get unique_IDs
|
# Sync with the core: tell core about torrents, and get unique_IDs
|
||||||
self.sync()
|
self.sync()
|
||||||
|
|
||||||
|
# Apply all the file filters, right after adding the torrents
|
||||||
|
self.apply_all_file_filters()
|
||||||
except IOError:
|
except IOError:
|
||||||
self.state = persistent_state()
|
self.state = persistent_state()
|
||||||
else:
|
else:
|
||||||
@ -360,6 +363,30 @@ class manager:
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
# Filtering functions
|
||||||
|
|
||||||
|
def set_file_filter(self, unique_ID, file_filter):
|
||||||
|
assert(len(file_filter) == self.get_torrent_core_state(unique_ID, True))
|
||||||
|
|
||||||
|
self.unique_IDs[unique_ID].file_filter = file_filter[:]
|
||||||
|
|
||||||
|
pytorrent_core.set_filter_out(file_filter)
|
||||||
|
|
||||||
|
def get_file_filter(self, unique_ID):
|
||||||
|
try:
|
||||||
|
return self.unique_IDs[unique_ID].file_filter[:]
|
||||||
|
except AttributeError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Call this when a session starts, to apply existing filters
|
||||||
|
def apply_all_file_filters(self):
|
||||||
|
for unique_ID in unique_IDs.keys():
|
||||||
|
try:
|
||||||
|
self.set_file_filter(self.unique_IDs[unique_ID].file_filter)
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Miscellaneous minor functions
|
# Miscellaneous minor functions
|
||||||
|
|
||||||
def set_user_pause(self, unique_ID, new_value):
|
def set_user_pause(self, unique_ID, new_value):
|
||||||
|
@ -549,24 +549,6 @@ static PyObject *torrent_resume(PyObject *self, PyObject *args)
|
|||||||
Py_INCREF(Py_None); return Py_None;
|
Py_INCREF(Py_None); return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *torrent_get_torrent_info(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
python_long unique_ID;
|
|
||||||
if (!PyArg_ParseTuple(args, "i", &unique_ID))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
long index = get_index_from_unique_ID(unique_ID);
|
|
||||||
if (PyErr_Occurred())
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
torrent_t &t = M_torrents->at(index);
|
|
||||||
|
|
||||||
return Py_BuildValue("{s:s,s:l}",
|
|
||||||
"name", t.handle.get_torrent_info().name().c_str(),
|
|
||||||
"num_files", t.handle.get_torrent_info().num_files()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *torrent_get_torrent_state(PyObject *self, PyObject *args)
|
static PyObject *torrent_get_torrent_state(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
python_long unique_ID;
|
python_long unique_ID;
|
||||||
@ -593,7 +575,9 @@ static PyObject *torrent_get_torrent_state(PyObject *self, PyObject *args)
|
|||||||
else
|
else
|
||||||
total_peers++;
|
total_peers++;
|
||||||
|
|
||||||
return Py_BuildValue("{s:l,s:l,s:l,s:f,s:f,s:d,s:f,s:l,s:l,s:s,s:s,s:f,s:d,s:l,s:l,s:l,s:d,s:l,s:l,s:l,s:l,s:l,s:l,s:d,s:d,s:l,s:l}",
|
return Py_BuildValue("{s:s,s:l,s:l,s:l,s:l,s:f,s:f,s:d,s:f,s:l,s:l,s:s,s:s,s:f,s:d,s:l,s:l,s:l,s:d,s:l,s:l,s:l,s:l,s:l,s:l,s:d,s:d,s:l,s:l}",
|
||||||
|
"name", t.handle.get_torrent_info().name().c_str(),
|
||||||
|
"num_files", t.handle.get_torrent_info().num_files()
|
||||||
"state", s.state,
|
"state", s.state,
|
||||||
"num_peers", s.num_peers,
|
"num_peers", s.num_peers,
|
||||||
"num_seeds", s.num_seeds,
|
"num_seeds", s.num_seeds,
|
||||||
@ -1184,7 +1168,6 @@ static PyMethodDef pytorrent_core_methods[] = {
|
|||||||
{"reannounce", torrent_reannounce, METH_VARARGS, "."},
|
{"reannounce", torrent_reannounce, METH_VARARGS, "."},
|
||||||
{"pause", torrent_pause, METH_VARARGS, "."},
|
{"pause", torrent_pause, METH_VARARGS, "."},
|
||||||
{"resume", torrent_resume, METH_VARARGS, "."},
|
{"resume", torrent_resume, METH_VARARGS, "."},
|
||||||
{"get_torrent_info", torrent_get_torrent_info, METH_VARARGS, "."},
|
|
||||||
{"get_torrent_state", torrent_get_torrent_state, METH_VARARGS, "."},
|
{"get_torrent_state", torrent_get_torrent_state, METH_VARARGS, "."},
|
||||||
{"pop_event", torrent_pop_event, METH_VARARGS, "."},
|
{"pop_event", torrent_pop_event, METH_VARARGS, "."},
|
||||||
{"get_session_info", torrent_get_session_info, METH_VARARGS, "."},
|
{"get_session_info", torrent_get_session_info, METH_VARARGS, "."},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user