1 # -*- coding: utf-8 -*-
3 from Plugins.Plugin import PluginDescriptor
4 from Components.config import config, ConfigSubsection, ConfigText, \
5 ConfigNumber, ConfigYesNo, ConfigSelection
7 from . import EmissionOverview
8 from EmissionOverview import LIST_TYPE_ALL, SORT_TYPE_ADDED
10 config.plugins.emission = ConfigSubsection()
11 config.plugins.emission.hostname = ConfigText(default = "localhost", fixed_size = False)
12 config.plugins.emission.username = ConfigText(default = "", fixed_size = False)
13 config.plugins.emission.password = ConfigText(default = "", fixed_size = False)
14 config.plugins.emission.port = ConfigNumber(default = 9091)
15 config.plugins.emission.autodownload_from_simplerss = ConfigYesNo(default = False)
16 # XXX: this is not compatible to the previous version and WILL break if not the default was used
17 config.plugins.emission.last_tab = ConfigNumber(default = LIST_TYPE_ALL)
18 config.plugins.emission.last_sort = ConfigNumber(default = SORT_TYPE_ADDED)
20 # by default sockets (and therefore urllib2 which transmissionrpc uses)
21 # block so we set a default timeout of 10s for all sockets...
22 # not nice, but does its job :-)
24 socket.setdefaulttimeout(10)
26 from transmissionrpc import Client, TransmissionError
28 NOTIFICATIONID = 'EmissionAutodownloadError'
30 def simplerss_update_callback(id = None):
32 from Plugins.Extensions.SimpleRSS.plugin import rssPoller
34 pass # should not happen since the poller has to be active for us to be called :-)
37 # we only check the "new items" feed currently since we do not keep track of the files we downloaded
40 for item in rssPoller.newItemFeed.history:
42 if file.mimetype == "application/x-bittorrent":
45 address = config.plugins.emission.hostname.value,
46 port = config.plugins.emission.port.value,
47 user = config.plugins.emission.username.value,
48 password = config.plugins.emission.password.value
51 # XXX: we might want to run this in the background cause this might block...
52 client.add_url(file.path)
53 except TransmissionError:
56 # Inform the user if an error occured
57 # XXX: we could also either open a notification per torrent (success/failure)
58 # or create a custom screen which gives this information in a
59 # more understandable and less annyoing way (e.g. a list of torrent
60 # names with an X or hook symbol next to it...)
62 from Tools.Notifications import AddPopup
63 from Screens.MessageBox import MessageBox
66 _("Failed to add %d torrents.") % (errors),
67 MessageBox.TYPE_WARNING,
72 def simplerss_handle_callback(el):
74 from Plugins.Extensions.SimpleRSS.RSSPoller import update_callbacks
76 # Notify the user about a too old or missing SimpleRSS instalation when
77 # enabling this feature
81 from Tools.Notifications import AddPopup
82 from Screens.MessageBox import MessageBox
84 import Plugins.Extensions.SimpleRSS.plugin
86 _("Your version if SimpleRSS is too old to support this feature.\nIf possible update your SimpleRSS installation."),
87 MessageBox.TYPE_ERROR,
92 _("This feature requires SimpleRSS to be installed.\nYou can do so with the Plugin Installer, see the User Manual for further explanation."),
93 MessageBox.TYPE_ERROR,
99 if simplerss_update_callback not in update_callbacks:
100 update_callbacks.append(simplerss_update_callback)
101 elif simplerss_update_callback in update_callbacks:
102 update_callbacks.remove(simplerss_update_callback)
104 config.plugins.emission.autodownload_from_simplerss.addNotifier(simplerss_handle_callback, immediate_feedback = False)
106 def main(session, **kwargs):
107 #reload(EmissionOverview)
109 EmissionOverview.EmissionOverview
112 def filescan_open(item, session, **kwargs):
114 address = config.plugins.emission.hostname.value,
115 port = config.plugins.emission.port.value,
116 user = config.plugins.emission.username.value,
117 password = config.plugins.emission.password.value
123 # XXX: a list of failed/added torrents would be nice, see comment in simplerss_update_callback
126 if client.add_url(each):
128 except TransmissionError:
131 from Screens.MessageBox import MessageBox
135 _("%d Torrents(s) were scheduled for download, %d failed.") % (added, errors),
136 type = MessageBox.TYPE_INFO,
140 from mimetypes import add_type
141 add_type("application/x-bittorrent", ".tor")
142 add_type("application/x-bittorrent", ".torrent")
144 def filescan(**kwargs):
145 from Components.Scanner import Scanner, ScanPath
149 mimetypes = ("application/x-bittorrent",),
152 ScanPath(path = "", with_subdirs = False),
154 name = "BitTorrrent Download",
155 description = _("Download torrent..."),
156 openfnc = filescan_open,
160 def Plugins(**kwargs):
162 PluginDescriptor(name = "eMission", description = _("enigma2 frontend to transmission-daemon"), where = PluginDescriptor.WHERE_PLUGINMENU, fnc = main, needsRestart = False),
163 PluginDescriptor(name = "eMission...", where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = main, needsRestart = False),
164 PluginDescriptor(where = PluginDescriptor.WHERE_FILESCAN, fnc = filescan, needsRestart = False),