Skip to content

Commit 5efba55

Browse files
initial commit
0 parents  commit 5efba55

File tree

13 files changed

+1659
-0
lines changed

13 files changed

+1659
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.swp
2+
*.swo
3+
*.*~
4+
*.bak
5+
*.pyc
6+
*.pyo
7+
build
8+
dist
9+
*.egg-info
10+
vim.session

AUTHORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
created by Stefan Talpalaru <[email protected]>
2+

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Description
2+
3+
This is a [Deluge][1] plugin that allows you to create a list of default trackers
4+
that will be added to new torrents (and old ones after restarting Deluge). The
5+
plugin will not duplicate existing trackers and does not care how the torrent
6+
was added so it works perfectly fine with infohashes.
7+
8+
Don't use this plugin if you have private torrents where the details are not
9+
supposed to reach public trackers.
10+
11+
## Installation
12+
13+
* create the egg with
14+
15+
`python setup.py bdist_egg`
16+
17+
* add it to Deluge from Preferences -> Plugins -> Install Plugin
18+
19+
## TODO:
20+
21+
* log the added trackers so we can remove them from torrents when they are deleted from the default list
22+
* WebUI version
23+
24+
[1]: http://deluge-torrent.org/

defaulttrackers/__init__.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#
2+
# __init__.py
3+
#
4+
# Copyright (C) 2013 Stefan Talpalaru <[email protected]>
5+
#
6+
# Basic plugin template created by:
7+
# Copyright (C) 2008 Martijn Voncken <[email protected]>
8+
# Copyright (C) 2007-2009 Andrew Resch <[email protected]>
9+
# Copyright (C) 2009 Damien Churchill <[email protected]>
10+
# Copyright (C) 2010 Pedro Algarvio <[email protected]>
11+
#
12+
# Deluge is free software.
13+
#
14+
# You may redistribute it and/or modify it under the terms of the
15+
# GNU General Public License, as published by the Free Software
16+
# Foundation; either version 3 of the License, or (at your option)
17+
# any later version.
18+
#
19+
# deluge is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22+
# See the GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with deluge. If not, write to:
26+
# The Free Software Foundation, Inc.,
27+
# 51 Franklin Street, Fifth Floor
28+
# Boston, MA 02110-1301, USA.
29+
#
30+
# In addition, as a special exception, the copyright holders give
31+
# permission to link the code of portions of this program with the OpenSSL
32+
# library.
33+
# You must obey the GNU General Public License in all respects for all of
34+
# the code used other than OpenSSL. If you modify file(s) with this
35+
# exception, you may extend this exception to your version of the file(s),
36+
# but you are not obligated to do so. If you do not wish to do so, delete
37+
# this exception statement from your version. If you delete this exception
38+
# statement from all source files in the program, then also delete it here.
39+
#
40+
41+
from deluge.plugins.init import PluginInitBase
42+
43+
class CorePlugin(PluginInitBase):
44+
def __init__(self, plugin_name):
45+
from core import Core as _plugin_cls
46+
self._plugin_cls = _plugin_cls
47+
super(CorePlugin, self).__init__(plugin_name)
48+
49+
class GtkUIPlugin(PluginInitBase):
50+
def __init__(self, plugin_name):
51+
from gtkui import GtkUI as _plugin_cls
52+
self._plugin_cls = _plugin_cls
53+
super(GtkUIPlugin, self).__init__(plugin_name)
54+
55+
class WebUIPlugin(PluginInitBase):
56+
def __init__(self, plugin_name):
57+
from webui import WebUI as _plugin_cls
58+
self._plugin_cls = _plugin_cls
59+
super(WebUIPlugin, self).__init__(plugin_name)

defaulttrackers/common.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#
2+
# common.py
3+
#
4+
# Copyright (C) 2013 Stefan Talpalaru <[email protected]>
5+
#
6+
# Basic plugin template created by:
7+
# Copyright (C) 2008 Martijn Voncken <[email protected]>
8+
# Copyright (C) 2007-2009 Andrew Resch <[email protected]>
9+
# Copyright (C) 2009 Damien Churchill <[email protected]>
10+
# Copyright (C) 2010 Pedro Algarvio <[email protected]>
11+
#
12+
# Deluge is free software.
13+
#
14+
# You may redistribute it and/or modify it under the terms of the
15+
# GNU General Public License, as published by the Free Software
16+
# Foundation; either version 3 of the License, or (at your option)
17+
# any later version.
18+
#
19+
# deluge is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22+
# See the GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with deluge. If not, write to:
26+
# The Free Software Foundation, Inc.,
27+
# 51 Franklin Street, Fifth Floor
28+
# Boston, MA 02110-1301, USA.
29+
#
30+
# In addition, as a special exception, the copyright holders give
31+
# permission to link the code of portions of this program with the OpenSSL
32+
# library.
33+
# You must obey the GNU General Public License in all respects for all of
34+
# the code used other than OpenSSL. If you modify file(s) with this
35+
# exception, you may extend this exception to your version of the file(s),
36+
# but you are not obligated to do so. If you do not wish to do so, delete
37+
# this exception statement from your version. If you delete this exception
38+
# statement from all source files in the program, then also delete it here.
39+
#
40+
41+
42+
def get_resource(filename):
43+
import pkg_resources, os
44+
return pkg_resources.resource_filename("defaulttrackers",
45+
os.path.join("data", filename))

defaulttrackers/core.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#
2+
# core.py
3+
#
4+
# Copyright (C) 2013 Stefan Talpalaru <[email protected]>
5+
#
6+
# Basic plugin template created by:
7+
# Copyright (C) 2008 Martijn Voncken <[email protected]>
8+
# Copyright (C) 2007-2009 Andrew Resch <[email protected]>
9+
# Copyright (C) 2009 Damien Churchill <[email protected]>
10+
# Copyright (C) 2010 Pedro Algarvio <[email protected]>
11+
#
12+
# Deluge is free software.
13+
#
14+
# You may redistribute it and/or modify it under the terms of the
15+
# GNU General Public License, as published by the Free Software
16+
# Foundation; either version 3 of the License, or (at your option)
17+
# any later version.
18+
#
19+
# deluge is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22+
# See the GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with deluge. If not, write to:
26+
# The Free Software Foundation, Inc.,
27+
# 51 Franklin Street, Fifth Floor
28+
# Boston, MA 02110-1301, USA.
29+
#
30+
# In addition, as a special exception, the copyright holders give
31+
# permission to link the code of portions of this program with the OpenSSL
32+
# library.
33+
# You must obey the GNU General Public License in all respects for all of
34+
# the code used other than OpenSSL. If you modify file(s) with this
35+
# exception, you may extend this exception to your version of the file(s),
36+
# but you are not obligated to do so. If you do not wish to do so, delete
37+
# this exception statement from your version. If you delete this exception
38+
# statement from all source files in the program, then also delete it here.
39+
#
40+
41+
import logging
42+
from deluge.plugins.pluginbase import CorePluginBase
43+
import deluge.component as component
44+
import deluge.configmanager
45+
from deluge.core.rpcserver import export
46+
from pprint import pprint
47+
48+
DEFAULT_PREFS = {
49+
"trackers": [
50+
#{"url": "test"},
51+
],
52+
}
53+
54+
log = logging.getLogger(__name__)
55+
56+
class Core(CorePluginBase):
57+
def enable(self):
58+
self.config = deluge.configmanager.ConfigManager("defaulttrackers.conf", DEFAULT_PREFS)
59+
component.get("EventManager").register_event_handler(
60+
"TorrentAddedEvent", self.on_torrent_added
61+
)
62+
63+
def disable(self):
64+
component.get("EventManager").deregister_event_handler(
65+
"TorrentAddedEvent", self.on_torrent_added
66+
)
67+
68+
def update(self):
69+
pass
70+
71+
def on_torrent_added(self, torrent_id):
72+
torrent = component.get("TorrentManager")[torrent_id]
73+
trackers = torrent.get_status(["trackers"])["trackers"]
74+
existing_urls = [tracker["url"] for tracker in trackers]
75+
got_new_trackers = False
76+
for new_tracker in self.config["trackers"]:
77+
if new_tracker["url"] not in existing_urls:
78+
got_new_trackers = True
79+
trackers.append({
80+
"tier": 0,
81+
"url": str(new_tracker["url"]),
82+
})
83+
if got_new_trackers:
84+
torrent.set_trackers(trackers)
85+
log.debug("added new trackers for %s" % torrent.filename)
86+
87+
@export
88+
def set_config(self, config):
89+
"""Sets the config dictionary"""
90+
for key in config.keys():
91+
self.config[key] = config[key]
92+
self.config.save()
93+
94+
@export
95+
def get_config(self):
96+
"""Returns the config dictionary"""
97+
return self.config.config
98+

0 commit comments

Comments
 (0)