def __init__(self): generic.NZBProvider.__init__(self, "BinnewZ") self.supportsBacklog = True self.nzbDownloaders = [ NZBIndex(), NZBClub(), BinSearch() ] self.url = "http://www.binnews.in/"
class TestBinSearch(unittest.TestCase): def setUp(self): self.bs = BinSearch() self.arr = [] def test_empty_arr(self): key = random.randrange(-10, 10) self.assertEqual(self.bs.search([], key), -1, "Найден элемент в пустом массиве!") def test_non_empty_arr_true(self, size=10): arr = [random.randrange(-100, 100) for _ in range(size)] self.arr = sorted(arr) key_pos = random.randrange(0, len(arr)) self.assertEqual(self.bs.search(self.arr, self.arr[key_pos]), key_pos) def test_non_empty_arr_false(self, size=10): arr = [random.randrange(-100, 100) for _ in range(size)] self.arr = sorted(arr) self.assertEqual(self.bs.search(self.arr, arr[0] - 10), -1) self.assertEqual(self.bs.search(self.arr, arr[-1] + 10), -1) def test_non_empty_random(self, size=10): arr = [random.randrange(-100, 100) for _ in range(size)] self.arr = sorted(arr) key = random.randrange(self.arr[0], self.arr[-1] + 1) position = self.bs.search(self.arr, key) if key not in self.arr: self.assertEqual(position, -1, "Нету такого элемента в массиве") else: self.assertEqual(self.arr[position], key) def test(self, size_=10): self.test_empty_arr() for size in range(1, size_ + 1): self.test_non_empty_arr_true(size) self.test_non_empty_arr_false(size) self.test_non_empty_random(size)
class BinNewzProvider(generic.NZBProvider): allowedGroups = { 'abmulti': 'alt.binaries.multimedia', 'abtvseries': 'alt.binaries.tvseries', 'abtv': 'alt.binaries.tv', 'a.b.teevee': 'alt.binaries.teevee', 'abstvdivxf': 'alt.binaries.series.tv.divx.french', 'abhdtvx264fr': 'alt.binaries.hdtv.x264.french', 'abmom': 'alt.binaries.mom', 'abhdtv': 'alt.binaries.hdtv', 'abboneless': 'alt.binaries.boneless', 'abhdtvf': 'alt.binaries.hdtv.french', 'abhdtvx264': 'alt.binaries.hdtv.x264', 'absuperman': 'alt.binaries.superman', 'abechangeweb': 'alt.binaries.echange-web', 'abmdfvost': 'alt.binaries.movies.divx.french.vost', 'abdvdr': 'alt.binaries.dvdr', 'abmzeromov': 'alt.binaries.movies.zeromovies', 'abcfaf': 'alt.binaries.cartoons.french.animes-fansub', 'abcfrench': 'alt.binaries.cartoons.french', 'abgougouland': 'alt.binaries.gougouland', 'abroger': 'alt.binaries.roger', 'abtatu': 'alt.binaries.tatu', 'abstvf': 'alt.binaries.series.tv.french', 'abmdfreposts': 'alt.binaries.movies.divx.french.reposts', 'abmdf': 'alt.binaries.movies.french', 'ab.aa': 'alt.binaries.aa', 'abspectdf': 'alt.binaries.spectacles.divx.french' } qualityCategories = {3: ['24', '7', '56'], 500: ['44', '53']} qualityMinSize = { (Quality.SDTV, Quality.SDDVD): 130, Quality.HDTV: 500, (Quality.HDWEBDL, Quality.HDBLURAY, Quality.FULLHDBLURAY, Quality.FULLHDTV, Quality.FULLHDWEBDL): 600 } url = "http://www.binnews.in/" supportsBacklog = True nzbDownloaders = [BinSearch(), NZBIndex(), NZBClub()] def __init__(self): generic.NZBProvider.__init__(self, "BinnewZ") def isEnabled(self): return sickbeard.BINNEWZ def _get_season_search_strings(self, show, season, episode=None): showNam = show_name_helpers.allPossibleShowNames(show) showNames = list(set(showNam)) result = [] global globepid global searchstringlist searchstringlist = [] globepid = show.tvdbid for showName in showNames: result.append(showName + ".saison %2d" % season) return result def _get_episode_search_strings(self, ep_obj, french=None): strings = [] showNam = show_name_helpers.allPossibleShowNames(ep_obj.show) showNames = list(set(showNam)) global globepid global searchstringlist searchstringlist = [] myDB = db.DBConnection() epidr = myDB.select( "SELECT episode_id from tv_episodes where tvdbid=?", [ep_obj.tvdbid]) globepid = epidr[0][0] for showName in showNames: strings.append("%s S%02dE%02d" % (showName, ep_obj.season, ep_obj.episode)) strings.append("%s S%02dE%d" % (showName, ep_obj.season, ep_obj.episode)) strings.append("%s S%dE%02d" % (showName, ep_obj.season, ep_obj.episode)) strings.append("%s %dx%d" % (showName, ep_obj.season, ep_obj.episode)) strings.append("%s S%02d E%02d" % (showName, ep_obj.season, ep_obj.episode)) strings.append("%s S%02d E%d" % (showName, ep_obj.season, ep_obj.episode)) strings.append("%s S%d E%02d" % (showName, ep_obj.season, ep_obj.episode)) strings.append("%s S%02dEp%02d" % (showName, ep_obj.season, ep_obj.episode)) strings.append("%s S%02dEp%d" % (showName, ep_obj.season, ep_obj.episode)) strings.append("%s S%dEp%02d" % (showName, ep_obj.season, ep_obj.episode)) strings.append("%s S%02d Ep%02d" % (showName, ep_obj.season, ep_obj.episode)) strings.append("%s S%02d Ep%d" % (showName, ep_obj.season, ep_obj.episode)) strings.append("%s S%d Ep%02d" % (showName, ep_obj.season, ep_obj.episode)) strings.append("%s S%02d Ep %02d" % (showName, ep_obj.season, ep_obj.episode)) strings.append("%s S%02d Ep %d" % (showName, ep_obj.season, ep_obj.episode)) strings.append("%s S%d Ep %02d" % (showName, ep_obj.season, ep_obj.episode)) return strings def _get_title_and_url(self, item): cleanTitle = re.sub(r'(\s*\[[\w\s]+\-\w+\])', "", item.title) return cleanTitle, item.refererURL def getQuality(self, item): return item.quality def buildUrl(self, searchString, quality): if quality in self.qualityCategories: data = { 'chkInit': '1', 'edTitre': searchString, 'chkTitre': 'on', 'chkFichier': 'on', 'chkCat': 'on', 'cats[]': self.qualityCategories[quality], 'edAge': '', 'edYear': '' } else: data = { 'b_submit': 'BinnewZ', 'cats[]': 'all', 'edSearchAll': searchString, 'sections[]': 'all' } return data #wtf with the signature change... def _doSearch(self, searchString=None, show=None, season=None, french=None): if searchString is None: return [] logger.log("BinNewz : Searching for " + searchString, logger.DEBUG) data = self.buildUrl(searchString, show.quality) try: soup = BeautifulSoup( urllib2.urlopen("http://www.binnews.in/_bin/search2.php", urllib.urlencode(data, True))) except Exception, e: logger.log(u"Error trying to load BinNewz response: " + e, logger.ERROR) return [] results = [] tables = soup.findAll("table", id="tabliste") for table in tables: if len(results) > 5: break rows = table.findAll("tr") for row in rows: cells = row.select("> td") if len(cells) < 11: continue name = cells[2].text.strip() language = cells[3].find("img").get("src") if show: if show.audio_lang == "fr" or french: if not "_fr" in language: continue elif show.audio_lang == "en": if "_fr" in language: continue # blacklist_groups = [ "alt.binaries.multimedia" ] blacklist_groups = [] newgroupLink = cells[4].find("a") newsgroup = None if newgroupLink.contents: newsgroup = newgroupLink.contents[0] if newsgroup in self.allowedGroups: newsgroup = self.allowedGroups[newsgroup] else: logger.log(u"Unknown binnewz newsgroup: " + newsgroup, logger.ERROR) continue if newsgroup in blacklist_groups: logger.log( u"Ignoring result, newsgroup is blacklisted: " + newsgroup, logger.WARNING) continue filename = cells[5].contents[0] acceptedQualities = Quality.splitQuality(show.quality)[0] quality = Quality.nameQuality(filename) if quality == Quality.UNKNOWN: quality = self.getReleaseQuality(name) if quality not in acceptedQualities: continue if filename in searchstringlist: continue minSize = self.qualityMinSize[ quality] if quality in self.qualityMinSize else 100 searchItems = [] #multiEpisodes = False rangeMatcher = re.search( "(?i).*(?<![\s\.\-_])[\s\.\-_]+s?(?:aison)?[\s\.\-_]*\d{1,2}[\s\.\-_]?(?:x|dvd|[eéEÉ](?:p|pisodes?)?)[\s\.\-_]*(\d{1,2})(?:(?:[\s\.\-_]*(?:[aàAÀ,/\-\.\s\&_]|et|and|to|x)[\s\.\-_]*(?:x|dvd|[eéEÉ](?:p|pisodes?)?)?[\s\.\-_]*([0-9]{1,2})))+.*", name) if rangeMatcher: rangeStart = int(rangeMatcher.group(1)) rangeEnd = int(rangeMatcher.group(2)) if filename.find("*") != -1: for i in range(rangeStart, rangeEnd + 1): searchItem = filename.replace("**", str(i)) searchItem = searchItem.replace("*", str(i)) searchItems.append(searchItem) #else: # multiEpisodes = True if len(searchItems) == 0: searchItems.append(filename) for searchItem in searchItems: for downloader in self.nzbDownloaders: searchstringlist.append(searchItem) logger.log("Searching for download : " + name + ", search string = " + searchItem + " on " + downloader.__class__.__name__) try: binsearch_result = downloader.search( searchItem, minSize, newsgroup) if binsearch_result: links = [] if french: binsearch_result.audio_langs = 'fr' else: binsearch_result.audio_langs = show.audio_lang binsearch_result.title = searchString binsearch_result.quality = quality myDB = db.DBConnection() listlink = myDB.select( "SELECT link from episode_links where episode_id =?", [globepid]) for dlink in listlink: links.append(dlink[0]) if binsearch_result.nzburl in links: continue else: results.append(binsearch_result) logger.log("Found : " + searchItem + " on " + downloader.__class__.__name__) break except Exception, e: logger.log( "Searching from " + downloader.__class__.__name__ + " failed : " + str(e), logger.ERROR)
def _search(self, movie, quality, results): nzbDownloaders = [NZBClub(), BinSearch(), NZBIndex()] MovieTitles = movie['info']['titles'] moviequality = simplifyString(quality['identifier']) movieyear = movie['info']['year'] if quality['custom']['3d']==1: threeD= True else: threeD=False if moviequality in ("720p","1080p","bd50"): cat1='39' cat2='49' minSize = 2000 elif moviequality in ("dvdr"): cat1='23' cat2='48' minSize = 3000 else: cat1='6' cat2='27' minSize = 500 for MovieTitle in MovieTitles: try: TitleStringReal = str(MovieTitle.encode("latin-1").replace('-',' ')) except: continue if threeD: TitleStringReal = TitleStringReal + ' 3d' data = 'chkInit=1&edTitre='+TitleStringReal+'&chkTitre=on&chkFichier=on&chkCat=on&cats%5B%5D='+cat1+'&cats%5B%5D='+cat2+'&edAge=&edYear=' try: soup = BeautifulSoup( urllib2.urlopen(self.urls['search'], data) ) except Exception, e: log.error(u"Error trying to load BinNewz response: "+e) return [] tables = soup.findAll("table", id="tabliste") for table in tables: rows = table.findAll("tr") for row in rows: cells = row.select("> td") if (len(cells) < 11): continue name = cells[2].text.strip() testname=namer_check.correctName(name,movie) if testname==0: continue language = cells[3].find("img").get("src") if not "_fr" in language and not "_frq" in language: continue detectedlang='' if "_fr" in language: detectedlang=' truefrench ' else: detectedlang=' french ' # blacklist_groups = [ "alt.binaries.multimedia" ] blacklist_groups = [] newgroupLink = cells[4].find("a") newsgroup = None if newgroupLink.contents: newsgroup = newgroupLink.contents[0] if newsgroup == "abmulti": newsgroup = "alt.binaries.multimedia" elif newsgroup == "ab.moovee": newsgroup = "alt.binaries.moovee" elif newsgroup == "abtvseries": newsgroup = "alt.binaries.tvseries" elif newsgroup == "abtv": newsgroup = "alt.binaries.tv" elif newsgroup == "a.b.teevee": newsgroup = "alt.binaries.teevee" elif newsgroup == "abstvdivxf": newsgroup = "alt.binaries.series.tv.divx.french" elif newsgroup == "abhdtvx264fr": newsgroup = "alt.binaries.hdtv.x264.french" elif newsgroup == "abmom": newsgroup = "alt.binaries.mom" elif newsgroup == "abhdtv": newsgroup = "alt.binaries.hdtv" elif newsgroup == "abboneless": newsgroup = "alt.binaries.boneless" elif newsgroup == "abhdtvf": newsgroup = "alt.binaries.hdtv.french" elif newsgroup == "abhdtvx264": newsgroup = "alt.binaries.hdtv.x264" elif newsgroup == "absuperman": newsgroup = "alt.binaries.superman" elif newsgroup == "abechangeweb": newsgroup = "alt.binaries.echange-web" elif newsgroup == "abmdfvost": newsgroup = "alt.binaries.movies.divx.french.vost" elif newsgroup == "abdvdr": newsgroup = "alt.binaries.dvdr" elif newsgroup == "abmzeromov": newsgroup = "alt.binaries.movies.zeromovies" elif newsgroup == "abcfaf": newsgroup = "alt.binaries.cartoons.french.animes-fansub" elif newsgroup == "abcfrench": newsgroup = "alt.binaries.cartoons.french" elif newsgroup == "abgougouland": newsgroup = "alt.binaries.gougouland" elif newsgroup == "abroger": newsgroup = "alt.binaries.roger" elif newsgroup == "abtatu": newsgroup = "alt.binaries.tatu" elif newsgroup =="abstvf": newsgroup = "alt.binaries.series.tv.french" elif newsgroup =="abmdfreposts": newsgroup="alt.binaries.movies.divx.french.reposts" elif newsgroup =="abmdf": newsgroup="alt.binaries.movies.french" elif newsgroup =="abhdtvfrepost": newsgroup="alt.binaries.hdtv.french.repost" elif newsgroup == "abmmkv": newsgroup = "alt.binaries.movies.mkv" elif newsgroup == "abf-tv": newsgroup = "alt.binaries.french-tv" elif newsgroup == "abmdfo": newsgroup = "alt.binaries.movies.divx.french.old" elif newsgroup == "abmf": newsgroup = "alt.binaries.movies.french" elif newsgroup == "ab.movies": newsgroup = "alt.binaries.movies" elif newsgroup == "a.b.french": newsgroup = "alt.binaries.french" elif newsgroup == "a.b.3d": newsgroup = "alt.binaries.3d" elif newsgroup == "ab.dvdrip": newsgroup = "alt.binaries.dvdrip" elif newsgroup == "ab.welovelori": newsgroup = "alt.binaries.welovelori" elif newsgroup == "abblu-ray": newsgroup = "alt.binaries.blu-ray" elif newsgroup == "ab.bloaf": newsgroup = "alt.binaries.bloaf" elif newsgroup == "ab.hdtv.german": newsgroup = "alt.binaries.hdtv.german" elif newsgroup == "abmd": newsgroup = "alt.binaries.movies.divx" elif newsgroup == "ab.ath": newsgroup = "alt.binaries.ath" elif newsgroup == "a.b.town": newsgroup = "alt.binaries.town" elif newsgroup == "a.b.u-4all": newsgroup = "alt.binaries.u-4all" elif newsgroup == "ab.amazing": newsgroup = "alt.binaries.amazing" elif newsgroup == "ab.astronomy": newsgroup = "alt.binaries.astronomy" elif newsgroup == "ab.nospam.cheer": newsgroup = "alt.binaries.nospam.cheerleaders" elif newsgroup == "ab.worms": newsgroup = "alt.binaries.worms" elif newsgroup == "abcores": newsgroup = "alt.binaries.cores" elif newsgroup == "abdvdclassics": newsgroup = "alt.binaries.dvd.classics" elif newsgroup == "abdvdf": newsgroup = "alt.binaries.dvd.french" elif newsgroup == "abdvds": newsgroup = "alt.binaries.dvds" elif newsgroup == "abmdfrance": newsgroup = "alt.binaries.movies.divx.france" elif newsgroup == "abmisc": newsgroup = "alt.binaries.misc" elif newsgroup == "abnl": newsgroup = "alt.binaries.nl" elif newsgroup == "abx": newsgroup = "alt.binaries.x" else: log.error(u"Unknown binnewz newsgroup: " + newsgroup) continue if newsgroup in blacklist_groups: log.error(u"Ignoring result, newsgroup is blacklisted: " + newsgroup) continue filename = cells[5].contents[0] m = re.search("^(.+)\s+{(.*)}$", name) qualityStr = "" if m: name = m.group(1) qualityStr = m.group(2) m = re.search("^(.+)\s+\[(.*)\]$", name) source = None if m: name = m.group(1) source = m.group(2) m = re.search("(.+)\(([0-9]{4})\)", name) year = "" if m: name = m.group(1) year = m.group(2) if int(year) > movieyear + 1 or int(year) < movieyear - 1: continue m = re.search("(.+)\((\d{2}/\d{2}/\d{4})\)", name) dateStr = "" if m: name = m.group(1) dateStr = m.group(2) year = dateStr[-5:].strip(")").strip("/") m = re.search("(.+)\s+S(\d{2})\s+E(\d{2})(.*)", name) if m: name = m.group(1) + " S" + m.group(2) + "E" + m.group(3) + m.group(4) m = re.search("(.+)\s+S(\d{2})\s+Ep(\d{2})(.*)", name) if m: name = m.group(1) + " S" + m.group(2) + "E" + m.group(3) + m.group(4) filenameLower = filename.lower() searchItems = [] if qualityStr=="": if source in ("Blu Ray-Rip", "HD DVD-Rip"): qualityStr="brrip" elif source =="DVDRip": qualityStr="dvdrip" elif source == "TS": qualityStr ="ts" elif source == "DVDSCR": qualityStr ="scr" elif source == "CAM": qualityStr ="cam" elif moviequality == "dvdr": qualityStr ="dvdr" if year =='': year = '1900' if len(searchItems) == 0 and qualityStr == str(moviequality): searchItems.append( filename ) for searchItem in searchItems: resultno=1 for downloader in nzbDownloaders: log.info("Searching for download : " + name + ", search string = "+ searchItem + " on " + downloader.__class__.__name__) try: binsearch_result = downloader.search(searchItem, minSize, newsgroup ) if binsearch_result: new={} def extra_check(item): return True qualitytag='' if qualityStr.lower() in ['720p','1080p']: qualitytag=' hd x264 h264 ' elif qualityStr.lower() in ['dvdrip']: qualitytag=' dvd xvid ' elif qualityStr.lower() in ['brrip']: qualitytag=' hdrip ' elif qualityStr.lower() in ['ts']: qualitytag=' webrip ' elif qualityStr.lower() in ['scr']: qualitytag='' elif qualityStr.lower() in ['dvdr']: qualitytag=' pal video_ts ' new['id'] = binsearch_result.nzbid new['name'] = name + detectedlang + qualityStr + qualitytag + downloader.__class__.__name__ new['url'] = binsearch_result.nzburl new['detail_url'] = binsearch_result.refererURL new['size'] = binsearch_result.sizeInMegs new['age'] = binsearch_result.age new['extra_check'] = extra_check results.append(new) resultno=resultno+1 log.info("Found : " + searchItem + " on " + downloader.__class__.__name__) if resultno==3: break except Exception, e: log.error("Searching from " + downloader.__class__.__name__ + " failed : " + str(e) + traceback.format_exc())
class BinNewzProvider(NZBProvider): allowedGroups = { 'abmulti': 'alt.binaries.multimedia', 'ab.moovee': 'alt.binaries.moovee', 'abtvseries': 'alt.binaries.tvseries', 'abtv': 'alt.binaries.tv', 'a.b.teevee': 'alt.binaries.teevee', 'abstvdivxf': 'alt.binaries.series.tv.divx.french', 'abhdtvx264fr': 'alt.binaries.hdtv.x264.french', 'abmom': 'alt.binaries.mom', 'abhdtv': 'alt.binaries.hdtv', 'abboneless': 'alt.binaries.boneless', 'abhdtvf': 'alt.binaries.hdtv.french', 'abhdtvx264': 'alt.binaries.hdtv.x264', 'absuperman': 'alt.binaries.superman', 'abechangeweb': 'alt.binaries.echange-web', 'abmdfvost': 'alt.binaries.movies.divx.french.vost', 'abdvdr': 'alt.binaries.dvdr', 'abmzeromov': 'alt.binaries.movies.zeromovies', 'abcfaf': 'alt.binaries.cartoons.french.animes-fansub', 'abcfrench': 'alt.binaries.cartoons.french', 'abgougouland': 'alt.binaries.gougouland', 'abroger': 'alt.binaries.roger', 'abtatu': 'alt.binaries.tatu', 'abstvf': 'alt.binaries.series.tv.french', 'abmdfreposts': 'alt.binaries.movies.divx.french.reposts', 'abmdf': 'alt.binaries.movies.french', 'abhdtvfrepost': 'alt.binaries.hdtv.french.repost', 'abmmkv': 'alt.binaries.movies.mkv', 'abf-tv': 'alt.binaries.french-tv', 'abmdfo': 'alt.binaries.movies.divx.french.old', 'abmf': 'alt.binaries.movies.french', 'ab.movies': 'alt.binaries.movies', 'a.b.french': 'alt.binaries.french', 'a.b.3d': 'alt.binaries.3d', 'ab.dvdrip': 'alt.binaries.dvdrip', 'ab.welovelori': 'alt.binaries.welovelori', 'abblu-ray': 'alt.binaries.blu-ray', 'ab.bloaf': 'alt.binaries.bloaf', 'ab.hdtv.german': 'alt.binaries.hdtv.german', 'abmd': 'alt.binaries.movies.divx', 'ab.ath': 'alt.binaries.ath', 'a.b.town': 'alt.binaries.town', 'a.b.u-4all': 'alt.binaries.u-4all', 'ab.amazing': 'alt.binaries.amazing', 'ab.astronomy': 'alt.binaries.astronomy', 'ab.nospam.cheer': 'alt.binaries.nospam.cheerleaders', 'ab.worms': 'alt.binaries.worms', 'abcores': 'alt.binaries.cores', 'abdvdclassics': 'alt.binaries.dvd.classics', 'abdvdf': 'alt.binaries.dvd.french', 'abdvds': 'alt.binaries.dvds', 'abmdfrance': 'alt.binaries.movies.divx.france', 'abmisc': 'alt.binaries.misc', 'abnl': 'alt.binaries.nl', 'abx': 'alt.binaries.x', 'abdivxf': 'alt.binaries.divx.french' } qualityCategories = {3: ['24', '7', '56'], 500: ['44', '53', '59']} qualityMinSize = { (Quality.SDTV, Quality.SDDVD): 130, Quality.HDTV: 500, (Quality.HDWEBDL, Quality.HDBLURAY, Quality.FULLHDBLURAY, Quality.FULLHDTV, Quality.FULLHDWEBDL): 600 } url = "http://www.binnews.in/" supportsBacklog = True nzbDownloaders = [BinSearch(), NZBIndex(), NZBClub()] #[BinSearch(), NZBIndex(), NZBClub()] def __init__(self): NZBProvider.__init__(self, "BinnewZ") #def is_enabled(self): # return sickbeard.BINNEWZ def _get_season_search_strings(self, episode): showNam = show_name_helpers.allPossibleShowNames(episode.show) showNames = list(set(showNam)) result = [] global searchstringlist searchstringlist = [] for showName in showNames: result.append(showName + ".saison %2d" % episode.season) return result def _get_episode_search_strings(self, episode, add_string=''): strings = [] showNam = show_name_helpers.allPossibleShowNames(episode.show) showNames = list(set(showNam)) global searchstringlist searchstringlist = [] for showName in showNames: strings.append( "%s S%02dE%02d" % (showName, episode.scene_season, episode.scene_episode)) strings.append( "%s S%02dE%d" % (showName, episode.scene_season, episode.scene_episode)) strings.append( "%s S%dE%02d" % (showName, episode.scene_season, episode.scene_episode)) strings.append( "%s %dx%d" % (showName, episode.scene_season, episode.scene_episode)) strings.append( "%s S%02d E%02d" % (showName, episode.scene_season, episode.scene_episode)) strings.append( "%s S%02d E%d" % (showName, episode.scene_season, episode.scene_episode)) strings.append( "%s S%d E%02d" % (showName, episode.scene_season, episode.scene_episode)) strings.append( "%s S%02dEp%02d" % (showName, episode.scene_season, episode.scene_episode)) strings.append( "%s S%02dEp%d" % (showName, episode.scene_season, episode.scene_episode)) strings.append( "%s S%dEp%02d" % (showName, episode.scene_season, episode.scene_episode)) strings.append( "%s S%02d Ep%02d" % (showName, episode.scene_season, episode.scene_episode)) strings.append( "%s S%02d Ep%d" % (showName, episode.scene_season, episode.scene_episode)) strings.append( "%s S%d Ep%02d" % (showName, episode.scene_season, episode.scene_episode)) strings.append( "%s S%02d Ep %02d" % (showName, episode.scene_season, episode.scene_episode)) strings.append( "%s S%02d Ep %d" % (showName, episode.scene_season, episode.scene_episode)) strings.append( "%s S%d Ep %02d" % (showName, episode.scene_season, episode.scene_episode)) return strings def _get_title_and_url(self, item): cleanTitle = re.sub(r'(\s*\[[\w\s]+\-\w+\])', "", item.title) return cleanTitle, item.refererURL def get_quality(self, item, anime=False): return item.quality def buildUrl(self, searchString, quality): if quality in self.qualityCategories: data = { 'chkInit': '1', 'edTitre': searchString, 'chkTitre': 'on', 'chkFichier': 'on', 'chkCat': 'on', 'cats[]': self.qualityCategories[quality], 'edAge': '', 'edYear': '' } else: data = { 'b_submit': 'BinnewZ', 'cats[]': 'all', 'edSearchAll': searchString, 'sections[]': 'all' } return data def search(self, search_params, age=0, ep_obj=None): if search_params is None: return [] logger.log("BinNewz : Searching for " + search_params, logger.DEBUG) data = self.buildUrl(search_params.replace('!', ''), ep_obj.show.quality) try: soup = BeautifulSoup( urllib2.urlopen("http://www.binnews.in/_bin/search2.php", urllib.urlencode(data, True)), "html5lib") except Exception, e: logger.log(u"Error trying to load BinNewz response: " + e, logger.ERROR) return [] results = [] tables = soup.findAll("table", id="tabliste") for table in tables: if len(results) > 5: break rows = table.findAll("tr") for row in rows: cells = row.select("> td") if len(cells) < 11: continue name = cells[2].text.strip() language = cells[3].find("img").get("src") if not "_fr" in language and not "_frq" in language: continue detectedlang = '' if "_fr" in language: detectedlang = ' truefrench ' else: detectedlang = ' french ' # blacklist_groups = [ "alt.binaries.multimedia" ] blacklist_groups = [] newgroupLink = cells[4].find("a") newsgroup = None if newgroupLink.contents: newsgroup = newgroupLink.contents[0] if newsgroup in self.allowedGroups: newsgroup = self.allowedGroups[newsgroup] else: logger.log(u"Unknown binnewz newsgroup: " + newsgroup, logger.ERROR) continue if newsgroup in blacklist_groups: logger.log( u"Ignoring result, newsgroup is blacklisted: " + newsgroup, logger.WARNING) continue filename = cells[5].contents[0] acceptedQualities = Quality.splitQuality( ep_obj.show.quality)[0] quality = Quality.nameQuality(filename) if quality == Quality.UNKNOWN: quality = self.getReleaseQuality(name) if quality not in acceptedQualities: continue if filename in searchstringlist: continue minSize = self.qualityMinSize[ quality] if quality in self.qualityMinSize else 100 searchItems = [] #multiEpisodes = False rangeMatcher = re.search( "(?i).*(?<![\s\.\-_])[\s\.\-_]+s?(?:aison)?[\s\.\-_]*\d{1,2}[\s\.\-_]?(?:x|dvd|[eéEÉ](?:p|pisodes?)?)[\s\.\-_]*(\d{1,2})(?:(?:[\s\.\-_]*(?:[aàAÀ,/\-\.\s\&_]|et|and|to|x)[\s\.\-_]*(?:x|dvd|[eéEÉ](?:p|pisodes?)?)?[\s\.\-_]*([0-9]{1,2})))+.*", name) if rangeMatcher: rangeStart = int(rangeMatcher.group(1)) rangeEnd = int(rangeMatcher.group(2)) if filename.find("*") != -1: for i in range(rangeStart, rangeEnd + 1): searchItem = filename.replace("**", str(i)) searchItem = searchItem.replace("*", str(i)) searchItems.append(searchItem) #else: # multiEpisodes = True if len(searchItems) == 0: searchItems.append(filename) for searchItem in searchItems: for downloader in self.nzbDownloaders: searchstringlist.append(searchItem) logger.log("Searching for download : " + name + ", search string = " + searchItem + " on " + downloader.__class__.__name__) try: binsearch_result = downloader.search( searchItem, minSize, newsgroup) if binsearch_result: binsearch_result.title = search_params binsearch_result.quality = quality #nzbdata = binsearch_result.getNZB() results.append(binsearch_result) logger.log("Found : " + searchItem + " on " + downloader.__class__.__name__) break except Exception, e: logger.log( "Searching from " + downloader.__class__.__name__ + " failed : " + str(e), logger.ERROR)
def setUp(self): self.bs = BinSearch() self.arr = []