Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 411 lines (304 sloc) 16.183 kB
3ee4ab3 @midgetspy Added the GPL notice to a bunch of files that were missing it
authored
1 # Author: Nic Wolfe <nic@wolfeden.ca>
2 # URL: http://code.google.com/p/sickbeard/
3 #
4 # This file is part of Sick Beard.
5 #
6 # Sick Beard is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Sick Beard is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
18
0990bb2 @midgetspy - Added TVRage ID to DB, TVShow, tvrage, etc
authored
19 import time
20 import datetime
21 import sqlite3
22
23 import sickbeard
24
25 from sickbeard import db
1129103 @midgetspy Changed logging to use built in python logging (5x25MB rotating log f…
authored
26 from sickbeard import logger
a5eb46d @midgetspy Remove unused imports, remove all "from x import *" imports, add #@Ig…
authored
27 from sickbeard.common import Quality
0990bb2 @midgetspy - Added TVRage ID to DB, TVShow, tvrage, etc
authored
28
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
29 from sickbeard import helpers, show_name_helpers
0c36bf7 @midgetspy Refactored the scene name lookups to get cached in cache.db. Provides…
authored
30 from sickbeard import name_cache
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
31 from sickbeard.exceptions import ex, AuthException
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
32
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
33 try:
34 import xml.etree.cElementTree as etree
35 except ImportError:
36 import elementtree.ElementTree as etree
0db8e20 @midgetspy Initial commit for changing providers to be classes and completely re…
authored
37
f4a7240 @midgetspy Better daily/talk show support, which should:
authored
38 from lib.tvdb_api import tvdb_api, tvdb_exceptions
39
6b6bdc5 @midgetspy Initial commit of new name parser to replace tvnamer
authored
40 from name_parser.parser import NameParser, InvalidNameException
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
41
b79092e @midgetspy Added user agent and cleaned up a bunch of left over urllib2 stuff
authored
42
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
43 class CacheDBConnection(db.DBConnection):
44
45 def __init__(self, providerName):
46 db.DBConnection.__init__(self, "cache.db")
47
48 # Create the table if it's not already there
49 try:
f8aeaf1 @itofzo Fix provider ID starts with number, change to quoted table name
itofzo authored
50 sql = "CREATE TABLE [" + providerName + "] (name TEXT, season NUMERIC, episodes TEXT, tvrid NUMERIC, tvdbid NUMERIC, url TEXT, time NUMERIC, quality TEXT);"
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
51 self.connection.execute(sql)
52 self.connection.commit()
53 except sqlite3.OperationalError, e:
f8aeaf1 @itofzo Fix provider ID starts with number, change to quoted table name
itofzo authored
54 if str(e) != "table [" + providerName + "] already exists":
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
55 raise
56
57 # Create the table if it's not already there
58 try:
59 sql = "CREATE TABLE lastUpdate (provider TEXT, time NUMERIC);"
60 self.connection.execute(sql)
61 self.connection.commit()
62 except sqlite3.OperationalError, e:
64066a9 @midgetspy Fix deprecation warnings
authored
63 if str(e) != "table lastUpdate already exists":
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
64 raise
65
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
66
0990bb2 @midgetspy - Added TVRage ID to DB, TVShow, tvrage, etc
authored
67 class TVCache():
7aea0d3 @midgetspy Removed trailing whitespaces
authored
68
0db8e20 @midgetspy Initial commit for changing providers to be classes and completely re…
authored
69 def __init__(self, provider):
7aea0d3 @midgetspy Removed trailing whitespaces
authored
70
0db8e20 @midgetspy Initial commit for changing providers to be classes and completely re…
authored
71 self.provider = provider
5a2fe0e @midgetspy Did a bunch more work refactoring the providers, made a dummy Newznab…
authored
72 self.providerID = self.provider.getID()
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
73 self.minTime = 10
0990bb2 @midgetspy - Added TVRage ID to DB, TVShow, tvrage, etc
authored
74
75 def _getDB(self):
7aea0d3 @midgetspy Removed trailing whitespaces
authored
76
5a2fe0e @midgetspy Did a bunch more work refactoring the providers, made a dummy Newznab…
authored
77 return CacheDBConnection(self.providerID)
0990bb2 @midgetspy - Added TVRage ID to DB, TVShow, tvrage, etc
authored
78
79 def _clearCache(self):
7aea0d3 @midgetspy Removed trailing whitespaces
authored
80
0990bb2 @midgetspy - Added TVRage ID to DB, TVShow, tvrage, etc
authored
81 myDB = self._getDB()
7aea0d3 @midgetspy Removed trailing whitespaces
authored
82
f8aeaf1 @itofzo Fix provider ID starts with number, change to quoted table name
itofzo authored
83 myDB.action("DELETE FROM [" + self.providerID + "] WHERE 1")
7aea0d3 @midgetspy Removed trailing whitespaces
authored
84
0db8e20 @midgetspy Initial commit for changing providers to be classes and completely re…
authored
85 def _getRSSData(self):
7aea0d3 @midgetspy Removed trailing whitespaces
authored
86
0db8e20 @midgetspy Initial commit for changing providers to be classes and completely re…
authored
87 data = None
88
89 return data
7aea0d3 @midgetspy Removed trailing whitespaces
authored
90
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
91 def _checkAuth(self, parsedXML):
0db8e20 @midgetspy Initial commit for changing providers to be classes and completely re…
authored
92 return True
7aea0d3 @midgetspy Removed trailing whitespaces
authored
93
0db8e20 @midgetspy Initial commit for changing providers to be classes and completely re…
authored
94 def _checkItemAuth(self, title, url):
95 return True
7aea0d3 @midgetspy Removed trailing whitespaces
authored
96
0990bb2 @midgetspy - Added TVRage ID to DB, TVShow, tvrage, etc
authored
97 def updateCache(self):
7aea0d3 @midgetspy Removed trailing whitespaces
authored
98
0db8e20 @midgetspy Initial commit for changing providers to be classes and completely re…
authored
99 if not self.shouldUpdate():
100 return
7aea0d3 @midgetspy Removed trailing whitespaces
authored
101
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
102 if self._checkAuth(None):
7aea0d3 @midgetspy Removed trailing whitespaces
authored
103
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
104 data = self._getRSSData()
7aea0d3 @midgetspy Removed trailing whitespaces
authored
105
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
106 # as long as the http request worked we count this as an update
107 if data:
108 self.setLastUpdate()
109 else:
110 return []
7aea0d3 @midgetspy Removed trailing whitespaces
authored
111
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
112 # now that we've loaded the current RSS feed lets delete the old cache
4a122f3 @itofzo Remove obsolete providers
itofzo authored
113 logger.log(u"Clearing " + self.provider.name + " cache and updating with new information")
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
114 self._clearCache()
7aea0d3 @midgetspy Removed trailing whitespaces
authored
115
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
116 parsedXML = helpers.parse_xml(data)
117
118 if parsedXML is None:
119 logger.log(u"Error trying to load " + self.provider.name + " RSS feed", logger.ERROR)
120 return []
7aea0d3 @midgetspy Removed trailing whitespaces
authored
121
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
122 if self._checkAuth(parsedXML):
7aea0d3 @midgetspy Removed trailing whitespaces
authored
123
4a122f3 @itofzo Remove obsolete providers
itofzo authored
124 if parsedXML.tag == 'rss':
125 items = parsedXML.findall('.//item')
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
126
4a122f3 @itofzo Remove obsolete providers
itofzo authored
127 else:
128 logger.log(u"Resulting XML from " + self.provider.name + " isn't RSS, not parsing it", logger.ERROR)
129 return []
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
130
131 for item in items:
132 self._parseItem(item)
133
134 else:
135 raise AuthException(u"Your authentication credentials for " + self.provider.name + " are incorrect, check your config")
0db8e20 @midgetspy Initial commit for changing providers to be classes and completely re…
authored
136
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
137 return []
138
139 def _translateTitle(self, title):
140 return title.replace(' ', '.')
0db8e20 @midgetspy Initial commit for changing providers to be classes and completely re…
authored
141
142 def _translateLinkURL(self, url):
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
143 return url.replace('&amp;', '&')
0db8e20 @midgetspy Initial commit for changing providers to be classes and completely re…
authored
144
145 def _parseItem(self, item):
146
4a122f3 @itofzo Remove obsolete providers
itofzo authored
147 title = helpers.get_xml_text(item.find('title'))
148 url = helpers.get_xml_text(item.find('link'))
0db8e20 @midgetspy Initial commit for changing providers to be classes and completely re…
authored
149
150 self._checkItemAuth(title, url)
151
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
152 if title and url:
153 title = self._translateTitle(title)
154 url = self._translateLinkURL(url)
7aea0d3 @midgetspy Removed trailing whitespaces
authored
155
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
156 logger.log(u"Adding item from RSS to cache: " + title, logger.DEBUG)
157 self._addCacheEntry(title, url)
0db8e20 @midgetspy Initial commit for changing providers to be classes and completely re…
authored
158
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
159 else:
160 logger.log(u"The XML returned from the " + self.provider.name + " feed is incomplete, this result is unusable", logger.DEBUG)
161 return
0990bb2 @midgetspy - Added TVRage ID to DB, TVShow, tvrage, etc
authored
162
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
163 def _getLastUpdate(self):
164 myDB = self._getDB()
5a2fe0e @midgetspy Did a bunch more work refactoring the providers, made a dummy Newznab…
authored
165 sqlResults = myDB.select("SELECT time FROM lastUpdate WHERE provider = ?", [self.providerID])
7aea0d3 @midgetspy Removed trailing whitespaces
authored
166
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
167 if sqlResults:
168 lastTime = int(sqlResults[0]["time"])
15e5833 @itofzo Fix lastTime in the future after correcting system time (not updating…
itofzo authored
169 if lastTime > int(time.mktime(datetime.datetime.today().timetuple())):
170 lastTime = 0
171
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
172 else:
173 lastTime = 0
7aea0d3 @midgetspy Removed trailing whitespaces
authored
174
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
175 return datetime.datetime.fromtimestamp(lastTime)
7aea0d3 @midgetspy Removed trailing whitespaces
authored
176
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
177 def setLastUpdate(self, toDate=None):
7aea0d3 @midgetspy Removed trailing whitespaces
authored
178
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
179 if not toDate:
180 toDate = datetime.datetime.today()
7aea0d3 @midgetspy Removed trailing whitespaces
authored
181
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
182 myDB = self._getDB()
183 myDB.upsert("lastUpdate",
184 {'time': int(time.mktime(toDate.timetuple()))},
4bc4535 @midgetspy Fixed lastUpdate name vs ID bug
authored
185 {'provider': self.providerID})
7aea0d3 @midgetspy Removed trailing whitespaces
authored
186
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
187 lastUpdate = property(_getLastUpdate)
7aea0d3 @midgetspy Removed trailing whitespaces
authored
188
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
189 def shouldUpdate(self):
190 # if we've updated recently then skip the update
191 if datetime.datetime.today() - self.lastUpdate < datetime.timedelta(minutes=self.minTime):
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
192 logger.log(u"Last update was too soon, using old cache: today()-" + str(self.lastUpdate) + "<" + str(datetime.timedelta(minutes=self.minTime)), logger.DEBUG)
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
193 return False
7aea0d3 @midgetspy Removed trailing whitespaces
authored
194
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
195 return True
196
197 def _addCacheEntry(self, name, url, season=None, episodes=None, tvdb_id=0, tvrage_id=0, quality=None, extraNames=[]):
7aea0d3 @midgetspy Removed trailing whitespaces
authored
198
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
199 myDB = self._getDB()
7aea0d3 @midgetspy Removed trailing whitespaces
authored
200
6b6bdc5 @midgetspy Initial commit of new name parser to replace tvnamer
authored
201 parse_result = None
7aea0d3 @midgetspy Removed trailing whitespaces
authored
202
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
203 # if we don't have complete info then parse the filename to get it
204 for curName in [name] + extraNames:
205 try:
6b6bdc5 @midgetspy Initial commit of new name parser to replace tvnamer
authored
206 myParser = NameParser()
207 parse_result = myParser.parse(curName)
208 except InvalidNameException:
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
209 logger.log(u"Unable to parse the filename " + curName + " into a valid episode", logger.DEBUG)
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
210 continue
7aea0d3 @midgetspy Removed trailing whitespaces
authored
211
6b6bdc5 @midgetspy Initial commit of new name parser to replace tvnamer
authored
212 if not parse_result:
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
213 logger.log(u"Giving up because I'm unable to parse this name: " + name, logger.DEBUG)
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
214 return False
7aea0d3 @midgetspy Removed trailing whitespaces
authored
215
6b6bdc5 @midgetspy Initial commit of new name parser to replace tvnamer
authored
216 if not parse_result.series_name:
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
217 logger.log(u"No series name retrieved from " + name + ", unable to cache it", logger.DEBUG)
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
218 return False
219
50b948e @midgetspy Fix a crash when using other languages for TVDB
authored
220 tvdb_lang = None
221
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
222 # if we need tvdb_id or tvrage_id then search the DB for them
223 if not tvdb_id or not tvrage_id:
7aea0d3 @midgetspy Removed trailing whitespaces
authored
224
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
225 # if we have only the tvdb_id, use the database
226 if tvdb_id:
227 showObj = helpers.findCertainShow(sickbeard.showList, tvdb_id)
228 if showObj:
229 tvrage_id = showObj.tvrid
585288e @midgetspy Fix indents, tidy up some logic
authored
230 tvdb_lang = showObj.lang
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
231 else:
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
232 logger.log(u"We were given a TVDB id " + str(tvdb_id) + " but it doesn't match a show we have in our list, so leaving tvrage_id empty", logger.DEBUG)
7aea0d3 @midgetspy Removed trailing whitespaces
authored
233 tvrage_id = 0
234
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
235 # if we have only a tvrage_id then use the database
236 elif tvrage_id:
237 showObj = helpers.findCertainTVRageShow(sickbeard.showList, tvrage_id)
238 if showObj:
239 tvdb_id = showObj.tvdbid
585288e @midgetspy Fix indents, tidy up some logic
authored
240 tvdb_lang = showObj.lang
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
241 else:
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
242 logger.log(u"We were given a TVRage id " + str(tvrage_id) + " but it doesn't match a show we have in our list, so leaving tvdb_id empty", logger.DEBUG)
7aea0d3 @midgetspy Removed trailing whitespaces
authored
243 tvdb_id = 0
244
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
245 # if they're both empty then fill out as much info as possible by searching the show name
7aea0d3 @midgetspy Removed trailing whitespaces
authored
246 else:
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
247
0c36bf7 @midgetspy Refactored the scene name lookups to get cached in cache.db. Provides…
authored
248 # check the name cache and see if we already know what show this is
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
249 logger.log(u"Checking the cache to see if we already know the tvdb id of " + parse_result.series_name, logger.DEBUG)
0c36bf7 @midgetspy Refactored the scene name lookups to get cached in cache.db. Provides…
authored
250 tvdb_id = name_cache.retrieveNameFromCache(parse_result.series_name)
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
251
0c36bf7 @midgetspy Refactored the scene name lookups to get cached in cache.db. Provides…
authored
252 # remember if the cache lookup worked or not so we know whether we should bother updating it later
253 if tvdb_id == None:
254 logger.log(u"No cache results returned, continuing on with the search", logger.DEBUG)
255 from_cache = False
7b9c4f2 @midgetspy Fixed a bug where shows with apostrophes in their names wouldn't get …
authored
256 else:
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
257 logger.log(u"Cache lookup found " + repr(tvdb_id) + ", using that", logger.DEBUG)
0c36bf7 @midgetspy Refactored the scene name lookups to get cached in cache.db. Provides…
authored
258 from_cache = True
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
259
0c36bf7 @midgetspy Refactored the scene name lookups to get cached in cache.db. Provides…
authored
260 # if the cache failed, try looking up the show name in the database
261 if tvdb_id == None:
262 logger.log(u"Trying to look the show up in the show database", logger.DEBUG)
263 showResult = helpers.searchDBForShow(parse_result.series_name)
264 if showResult:
ea210ca @thezoggy PEP8 fixes for tvcache/name_cache
thezoggy authored
265 logger.log(u"" + parse_result.series_name + " was found to be show " + showResult[1] + " (" + str(showResult[0]) + ") in our DB.", logger.DEBUG)
0c36bf7 @midgetspy Refactored the scene name lookups to get cached in cache.db. Provides…
authored
266 tvdb_id = showResult[0]
267
268 # if the DB lookup fails then do a comprehensive regex search
269 if tvdb_id == None:
d9bbb52 @midgetspy Explicitly use unicode for all log strings, assume exceptions are utf…
authored
270 logger.log(u"Couldn't figure out a show name straight from the DB, trying a regex search instead", logger.DEBUG)
7b9c4f2 @midgetspy Fixed a bug where shows with apostrophes in their names wouldn't get …
authored
271 for curShow in sickbeard.showList:
0c36bf7 @midgetspy Refactored the scene name lookups to get cached in cache.db. Provides…
authored
272 if show_name_helpers.isGoodResult(name, curShow, False):
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
273 logger.log(u"Successfully matched " + name + " to " + curShow.name + " with regex", logger.DEBUG)
7aea0d3 @midgetspy Removed trailing whitespaces
authored
274 tvdb_id = curShow.tvdbid
585288e @midgetspy Fix indents, tidy up some logic
authored
275 tvdb_lang = curShow.lang
c5d01c7 @midgetspy Don't waste cycles searching unnecessarily
authored
276 break
7aea0d3 @midgetspy Removed trailing whitespaces
authored
277
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
278 # if tvdb_id was anything but None (0 or a number) then
0c36bf7 @midgetspy Refactored the scene name lookups to get cached in cache.db. Provides…
authored
279 if not from_cache:
280 name_cache.addNameToCache(parse_result.series_name, tvdb_id)
7aea0d3 @midgetspy Removed trailing whitespaces
authored
281
0c36bf7 @midgetspy Refactored the scene name lookups to get cached in cache.db. Provides…
authored
282 # if we came out with tvdb_id = None it means we couldn't figure it out at all, just use 0 for that
283 if tvdb_id == None:
284 tvdb_id = 0
7aea0d3 @midgetspy Removed trailing whitespaces
authored
285
0c36bf7 @midgetspy Refactored the scene name lookups to get cached in cache.db. Provides…
authored
286 # if we found the show then retrieve the show object
287 if tvdb_id:
288 showObj = helpers.findCertainShow(sickbeard.showList, tvdb_id)
289 if showObj:
290 tvrage_id = showObj.tvrid
291 tvdb_lang = showObj.lang
7aea0d3 @midgetspy Removed trailing whitespaces
authored
292
0c36bf7 @midgetspy Refactored the scene name lookups to get cached in cache.db. Provides…
authored
293 # if we weren't provided with season/episode information then get it from the name that we parsed
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
294 if not season:
6b6bdc5 @midgetspy Initial commit of new name parser to replace tvnamer
authored
295 season = parse_result.season_number if parse_result.season_number != None else 1
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
296 if not episodes:
6b6bdc5 @midgetspy Initial commit of new name parser to replace tvnamer
authored
297 episodes = parse_result.episode_numbers
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
298
f4a7240 @midgetspy Better daily/talk show support, which should:
authored
299 # if we have an air-by-date show then get the real season/episode numbers
6b6bdc5 @midgetspy Initial commit of new name parser to replace tvnamer
authored
300 if parse_result.air_by_date and tvdb_id:
f4a7240 @midgetspy Better daily/talk show support, which should:
authored
301 try:
585288e @midgetspy Fix indents, tidy up some logic
authored
302 # There's gotta be a better way of doing this but we don't wanna
303 # change the language value elsewhere
304 ltvdb_api_parms = sickbeard.TVDB_API_PARMS.copy()
b937a37 Added lang property to shows that is used on every TVDB lookup
Duststorm authored
305
585288e @midgetspy Fix indents, tidy up some logic
authored
306 if not (tvdb_lang == "" or tvdb_lang == "en" or tvdb_lang == None):
307 ltvdb_api_parms['language'] = tvdb_lang
b937a37 Added lang property to shows that is used on every TVDB lookup
Duststorm authored
308
309 t = tvdb_api.Tvdb(**ltvdb_api_parms)
6b6bdc5 @midgetspy Initial commit of new name parser to replace tvnamer
authored
310 epObj = t[tvdb_id].airedOn(parse_result.air_date)[0]
f4a7240 @midgetspy Better daily/talk show support, which should:
authored
311 season = int(epObj["seasonnumber"])
312 episodes = [int(epObj["episodenumber"])]
a5eb46d @midgetspy Remove unused imports, remove all "from x import *" imports, add #@Ig…
authored
313 except tvdb_exceptions.tvdb_episodenotfound:
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
314 logger.log(u"Unable to find episode with date " + str(parse_result.air_date) + " for show " + parse_result.series_name + ", skipping", logger.WARNING)
f4a7240 @midgetspy Better daily/talk show support, which should:
authored
315 return False
04b3510 @midgetspy Deal with TVDB a little better when it's down
authored
316 except tvdb_exceptions.tvdb_error, e:
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
317 logger.log(u"Unable to contact TVDB: " + ex(e), logger.WARNING)
04b3510 @midgetspy Deal with TVDB a little better when it's down
authored
318 return False
f4a7240 @midgetspy Better daily/talk show support, which should:
authored
319
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
320 episodeText = "|" + "|".join(map(str, episodes)) + "|"
7aea0d3 @midgetspy Removed trailing whitespaces
authored
321
7b4869d @midgetspy Refactored TVCache class to include more common code, simplified the …
authored
322 # get the current timestamp
323 curTimestamp = int(time.mktime(datetime.datetime.today().timetuple()))
7aea0d3 @midgetspy Removed trailing whitespaces
authored
324
0d6214c @midgetspy Added preliminary version of Newzbin provider
authored
325 if not quality:
326 quality = Quality.nameQuality(name)
7aea0d3 @midgetspy Removed trailing whitespaces
authored
327
f8aeaf1 @itofzo Fix provider ID starts with number, change to quoted table name
itofzo authored
328 myDB.action("INSERT INTO [" + self.providerID + "] (name, season, episodes, tvrid, tvdbid, url, time, quality) VALUES (?,?,?,?,?,?,?,?)",
6fb5bfc @midgetspy Fixed a problem with tvrage/tvdb ids being reversed in the new cache …
authored
329 [name, season, episodeText, tvrage_id, tvdb_id, url, curTimestamp, quality])
7aea0d3 @midgetspy Removed trailing whitespaces
authored
330
6bac296 @midgetspy Fixed manual searches on non-backlog providers (only searches RSS)
authored
331 def searchCache(self, episode, manualSearch=False):
332 neededEps = self.findNeededEpisodes(episode, manualSearch)
05887d1 @midgetspy Fixed numerous random bugs, made NZBs.org provider able to search man…
authored
333 return neededEps[episode]
7aea0d3 @midgetspy Removed trailing whitespaces
authored
334
bed3723 @midgetspy Initial commit of new quality system
authored
335 def listPropers(self, date=None, delimiter="."):
7aea0d3 @midgetspy Removed trailing whitespaces
authored
336
d342224 @midgetspy Added support for PROPER & REPACK downloads for existing episodes
authored
337 myDB = self._getDB()
7aea0d3 @midgetspy Removed trailing whitespaces
authored
338
f8aeaf1 @itofzo Fix provider ID starts with number, change to quoted table name
itofzo authored
339 sql = "SELECT * FROM [" + self.providerID + "] WHERE name LIKE '%.PROPER.%' OR name LIKE '%.REPACK.%'"
7aea0d3 @midgetspy Removed trailing whitespaces
authored
340
d342224 @midgetspy Added support for PROPER & REPACK downloads for existing episodes
authored
341 if date != None:
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
342 sql += " AND time >= " + str(int(time.mktime(date.timetuple())))
7aea0d3 @midgetspy Removed trailing whitespaces
authored
343
d342224 @midgetspy Added support for PROPER & REPACK downloads for existing episodes
authored
344 #return filter(lambda x: x['tvdbid'] != 0, myDB.select(sql))
345 return myDB.select(sql)
346
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
347 def findNeededEpisodes(self, episode=None, manualSearch=False):
bed3723 @midgetspy Initial commit of new quality system
authored
348 neededEps = {}
349
05887d1 @midgetspy Fixed numerous random bugs, made NZBs.org provider able to search man…
authored
350 if episode:
351 neededEps[episode] = []
352
bed3723 @midgetspy Initial commit of new quality system
authored
353 myDB = self._getDB()
7aea0d3 @midgetspy Removed trailing whitespaces
authored
354
05887d1 @midgetspy Fixed numerous random bugs, made NZBs.org provider able to search man…
authored
355 if not episode:
f8aeaf1 @itofzo Fix provider ID starts with number, change to quoted table name
itofzo authored
356 sqlResults = myDB.select("SELECT * FROM [" + self.providerID + "]")
05887d1 @midgetspy Fixed numerous random bugs, made NZBs.org provider able to search man…
authored
357 else:
f8aeaf1 @itofzo Fix provider ID starts with number, change to quoted table name
itofzo authored
358 sqlResults = myDB.select("SELECT * FROM [" + self.providerID + "] WHERE tvdbid = ? AND season = ? AND episodes LIKE ?", [episode.show.tvdbid, episode.season, "%|" + str(episode.episode) + "|%"])
bed3723 @midgetspy Initial commit of new quality system
authored
359
360 # for each cache entry
361 for curResult in sqlResults:
362
4a122f3 @itofzo Remove obsolete providers
itofzo authored
363 # skip non-tv crap
364 if not show_name_helpers.filterBadReleases(curResult["name"]):
93e1b78 @midgetspy Fixed a bug with RSS results not being excluded for being the wrong l…
authored
365 continue
366
bed3723 @midgetspy Initial commit of new quality system
authored
367 # get the show object, or if it's not one of our shows then ignore it
368 showObj = helpers.findCertainShow(sickbeard.showList, int(curResult["tvdbid"]))
369 if not showObj:
370 continue
7aea0d3 @midgetspy Removed trailing whitespaces
authored
371
bed3723 @midgetspy Initial commit of new quality system
authored
372 # get season and ep data (ignoring multi-eps for now)
373 curSeason = int(curResult["season"])
8e8b0d9 @midgetspy Fixed a problem with the half-implemented air-by-date code
authored
374 if curSeason == -1:
375 continue
3e44d77 @midgetspy Fixed a problem where the search threads would crash because of seaso…
authored
376 curEp = curResult["episodes"].split("|")[1]
377 if not curEp:
378 continue
379 curEp = int(curEp)
05887d1 @midgetspy Fixed numerous random bugs, made NZBs.org provider able to search man…
authored
380 curQuality = int(curResult["quality"])
bed3723 @midgetspy Initial commit of new quality system
authored
381
382 # if the show says we want that episode then add it to the list
6bac296 @midgetspy Fixed manual searches on non-backlog providers (only searches RSS)
authored
383 if not showObj.wantEpisode(curSeason, curEp, curQuality, manualSearch):
16afe2f @itofzo Change providers: minidom to elementtree + check_auth
itofzo authored
384 logger.log(u"Skipping " + curResult["name"] + " because we don't want an episode that's " + Quality.qualityStrings[curQuality], logger.DEBUG)
7aea0d3 @midgetspy Removed trailing whitespaces
authored
385
05887d1 @midgetspy Fixed numerous random bugs, made NZBs.org provider able to search man…
authored
386 else:
7aea0d3 @midgetspy Removed trailing whitespaces
authored
387
05887d1 @midgetspy Fixed numerous random bugs, made NZBs.org provider able to search man…
authored
388 if episode:
389 epObj = episode
390 else:
391 epObj = showObj.getEpisode(curSeason, curEp)
7aea0d3 @midgetspy Removed trailing whitespaces
authored
392
bed3723 @midgetspy Initial commit of new quality system
authored
393 # build a result object
394 title = curResult["name"]
395 url = curResult["url"]
7aea0d3 @midgetspy Removed trailing whitespaces
authored
396
d9bbb52 @midgetspy Explicitly use unicode for all log strings, assume exceptions are utf…
authored
397 logger.log(u"Found result " + title + " at " + url)
7aea0d3 @midgetspy Removed trailing whitespaces
authored
398
0db8e20 @midgetspy Initial commit for changing providers to be classes and completely re…
authored
399 result = self.provider.getResult([epObj])
7aea0d3 @midgetspy Removed trailing whitespaces
authored
400 result.url = url
6d67d4e @midgetspy Refactored the SearchResult class to have the result name in it rathe…
authored
401 result.name = title
05887d1 @midgetspy Fixed numerous random bugs, made NZBs.org provider able to search man…
authored
402 result.quality = curQuality
7aea0d3 @midgetspy Removed trailing whitespaces
authored
403
bed3723 @midgetspy Initial commit of new quality system
authored
404 # add it to the list
405 if epObj not in neededEps:
406 neededEps[epObj] = [result]
407 else:
408 neededEps[epObj].append(result)
7aea0d3 @midgetspy Removed trailing whitespaces
authored
409
c409332 Properly escaped various SQL statements.
Thomas W. Most authored
410 return neededEps
Something went wrong with that request. Please try again.