1919
2020
2121class RssEditorDialog (xbmcgui .WindowXMLDialog ):
22+ _TITLE = 5000
23+ _URLIST = 5110
24+ _ADDBTN = 5230
25+ _DELBTN = 5240
26+ _OKBTN = 5210
27+ _CANCEL = 5220
2228
2329 def __init__ (self , * args , ** kwargs ):
2430 self .setNum = 'set1'
@@ -30,29 +36,20 @@ def __init__(self, *args, **kwargs):
3036 def onInit (self ):
3137 self .setControls ()
3238 self .feedsList = self .parser .feedsList [self .setNum ]['feedslist' ]
33- if not self .feedsList :
34- xbmcgui .Dialog ().ok (commons .translate (32040 ) + 'RssFeeds.xml' , 'RssFeeds.xml ' + commons .translate (32041 ), commons .translate (32042 ), commons .translate (32043 ))
35- self .closeDialog ()
3639 self .showDialog ()
3740
3841
3942 def setControls (self ):
40- # ids that matters
41- self .__TITLE_LBL = 5000
42- self .__CH_LIST = 5110
43- self .__ADD_BTN = 5230
44- self .__REMOVE_BTN = 5240
45- self .__OK_BTN = 5210
46- self .__CANCEL_BTN = 5220
4743 # controls used for data manipulation
48- self .ListControl = self .getControl (self .__CH_LIST )
49- self .AddButtonControl = self .getControl (self .__ADD_BTN )
50- self .RemoveButtonControl = self .getControl (self .__REMOVE_BTN )
51- self .OkButtonControl = self .getControl (self .__OK_BTN )
52- self .CancelButtonControl = self .getControl (self .__CANCEL_BTN )
44+ self .ListControl = self .getControl (self ._URLIST )
45+ self .AddButtonControl = self .getControl (self ._ADDBTN )
46+ self .RemoveButtonControl = self .getControl (self ._DELBTN )
47+ self .OkButtonControl = self .getControl (self ._OKBTN )
48+ self .CancelButtonControl = self .getControl (self ._CANCEL )
49+
5350
5451 def showDialog (self ):
55- self .getControl (self .__TITLE_LBL ).setLabel (commons .translate (32000 ))
52+ self .getControl (self ._TITLE ).setLabel (commons .translate (32000 ))
5653 self .updateFeedsList ()
5754
5855
@@ -62,7 +59,7 @@ def closeDialog(self):
6259
6360 def onClick (self , controlId ):
6461 # edit existing feed
65- if controlId == self .__CH_LIST :
62+ if controlId == self ._URLIST :
6663 position = self .ListControl .getSelectedPosition ()
6764 oldUrl = self .feedsList [position ]['url' ]
6865 oldUpdateInterval = self .feedsList [position ]['updateinterval' ]
@@ -71,21 +68,21 @@ def onClick(self, controlId):
7168 self .feedsList [position ] = {'url' :newUrl , 'updateinterval' :newUpdateInterval }
7269 self .updateFeedsList ()
7370 #add new feed
74- elif controlId == self .__ADD_BTN :
71+ elif controlId == self ._ADDBTN :
7572 newUrl , newUpdateInterval = self .getNewFeed ()
7673 if newUrl :
7774 self .feedsList .append ({'url' :newUrl , 'updateinterval' :newUpdateInterval })
7875 self .updateFeedsList ()
7976 #remove existing feed
80- elif controlId == self .__REMOVE_BTN :
77+ elif controlId == self ._DELBTN :
8178 self .removeFeed ()
8279 self .updateFeedsList ()
8380 #save xml
84- elif controlId == self .__OK_BTN :
81+ elif controlId == self ._OKBTN :
8582 self .parser .writeXmlToFile ()
8683 self .closeDialog ()
8784 #cancel dialog
88- elif controlId == self .__CANCEL_BTN :
85+ elif controlId == self ._CANCEL :
8986 self .closeDialog ()
9087
9188
@@ -94,10 +91,6 @@ def onAction(self, action):
9491 self .closeDialog ()
9592
9693
97- def onFocus (self , controlId ):
98- pass
99-
100-
10194 def removeFeed (self ):
10295 position = self .ListControl .getSelectedPosition ()
10396 self .feedsList .remove (self .feedsList [position ])
@@ -121,46 +114,41 @@ def updateFeedsList(self):
121114 self .ListControl .reset ()
122115 for feed in self .feedsList :
123116 self .ListControl .addItem (feed ['url' ])
124- self .list_label .setLabel (commons .translate (32014 ) % ('' ))
125117
126118
127119
128120class XMLParser :
129121
130122 def __init__ (self ):
131123 self .RssFeedsPath = xbmc .translatePath ('special://userdata/RssFeeds.xml' ).decode ("utf-8" )
132- sane = self .checkRssFeedPathSanity ( )
124+ sane = os . path . isfile ( self .RssFeedsPath ) and os . path . getsize ( self . RssFeedsPath )
133125 if sane :
134126 try :
135127 self .feedsTree = parse (self .RssFeedsPath )
136128 except :
137- commons .debug ('Failed to parse ' + unicodedata .normalize ( 'NFKD' , self .RssFeedsPath ).encode ( 'ascii' , 'ignore' ))
138- regen = xbmcgui .Dialog ().yesno (commons .translate (40 ), commons .translate (51 ), commons .translate (52 ), commons .translate (53 ))
139- if regen :
140- commons .debug ('[script] RSS Editor --> Attempting to Regenerate RssFeeds.xml' )
141- xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n <rssfeeds>\n \
142- <!-- RSS feeds. To have multiple feeds, just add a feed to the set. You can also have multiple sets. !-->\n \
143- <!-- To use different sets in your skin, each must be called from skin with a unique id. !-->\n \
144- <set id="1">\n <feed updateinterval="30">http://feeds.feedburner.com/slashfilm</feed>\n </set>\n </rssfeeds>'
145- f = open (self .RssFeedsPath , 'w' )
146- f .write (xml )
147- f .close ()
148- self .__init__ ()
149- else :
150- commons .debug ('User opted to not regenerate RssFeeds.xml. Script Exiting..' )
151- self .feedsTree = False
129+ commons .debug ('Failed to parse %s, attempting to regenerate it..' % unicodedata .normalize ('NFKD' , self .RssFeedsPath ).encode ( 'ascii' , 'ignore' ))
130+ self .regenerate ()
131+ self .__init__ ()
152132 if self .feedsTree :
153133 self .feedsList = self .getCurrentRssFeeds ()
154134 else :
155- self .feedsTree = False
156- self .feedsList = False
157135 commons .debug ('Could not open ' + unicodedata .normalize ( 'NFKD' , self .RssFeedsPath ).encode ( 'ascii' , 'ignore' ) + '. Either the file does not exist, or its size is zero.' )
136+ self .regenerate ()
137+ self .__init__ ()
158138
159139
160- def checkRssFeedPathSanity (self ):
161- if os .path .isfile (self .RssFeedsPath ):
162- if os .path .getsize (self .RssFeedsPath ):
163- return True
140+ def regenerate (self ):
141+ xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n '
142+ xml += '<rssfeeds>\n '
143+ xml += '<!-- RSS feeds. To have multiple feeds, just add a feed to the set. You can also have multiple sets. !-->\n '
144+ xml += '<!-- To use different sets in your skin, each must be called from skin with a unique id. !-->\n '
145+ xml += '\t <set id="1">\n '
146+ xml += '\t \t <feed updateinterval="30">http://feeds.kodi.tv/xbmc</feed>\n '
147+ xml += '\t </set>\n '
148+ xml += '</rssfeeds>\n '
149+ f = open (self .RssFeedsPath , 'w' )
150+ f .write (xml )
151+ f .close ()
164152
165153
166154 def getCurrentRssFeeds (self ):
@@ -169,18 +157,18 @@ def getCurrentRssFeeds(self):
169157 for s in sets :
170158 setName = 'set' + s .attributes ["id" ].value
171159 feedsList [setName ] = {'feedslist' :list (), 'attrs' :dict ()}
172- #get attrs
160+ # get attrs
173161 for attrib in s .attributes .keys ():
174162 feedsList [setName ]['attrs' ][attrib ] = s .attributes [attrib ].value
175- #get feedslist
163+ # get feedslist
176164 feeds = s .getElementsByTagName ('feed' )
177165 for feed in feeds :
178166 feedsList [setName ]['feedslist' ].append ({'url' :feed .firstChild .toxml (), 'updateinterval' :feed .attributes ['updateinterval' ].value })
179167 return feedsList
180168
181169
182- def formXml (self ):
183- """Form the XML to be written to RssFeeds.xml"""
170+ def writeXmlToFile (self ):
171+ commons . debug ( 'Writing to %s' % ( unicodedata . normalize ( 'NFKD' , self . RssFeedsPath ). encode ( 'ascii' , 'ignore' )))
184172 # create the document
185173 doc = Document ()
186174 # create root element
@@ -207,12 +195,7 @@ def formXml(self):
207195 feedUrl = doc .createTextNode (feed ['url' ])
208196 feedTag .appendChild (feedUrl )
209197 setTag .appendChild (feedTag )
210- return doc .toprettyxml (indent = ' ' , encoding = 'UTF-8' )
211-
212-
213- def writeXmlToFile (self ):
214- commons .debug ('Writing to %s' % (unicodedata .normalize ( 'NFKD' , self .RssFeedsPath ).encode ( 'ascii' , 'ignore' )))
215- xml = self .formXml ()
198+ xml = doc .toprettyxml (indent = ' ' , encoding = 'UTF-8' )
216199 # hack for standalone attribute, minidom doesn't support DOM3
217200 xmlHeaderEnd = xml .find ('?>' )
218201 xml = xml [:xmlHeaderEnd ]+ ' standalone="yes"' + xml [xmlHeaderEnd :]
@@ -226,9 +209,7 @@ def writeXmlToFile(self):
226209
227210
228211 def refreshFeed (self ):
229- """
230- Refresh MCPi's rss feed so changes can be seen immediately
231- """
212+ """Refresh MCPi's rss feed so changes can be seen immediately"""
232213 xbmc .executebuiltin ('refreshrss()' )
233214
234215
0 commit comments