def scrapeContent(self): import scrapers scrapers.setContentPath(self._contentDirectory) for stype, source in util.contentScrapers(): if stype == 'trailers': util.DEBUG_LOG('Getting trailers from {0}'.format(source)) self._callback(heading='Adding {0} trailers...'.format(source)) self._callback('Getting trailer list...', pct=0) trailers = scrapers.getTrailers(source) total = len(trailers) util.DEBUG_LOG(' - Received {0} trailers'.format(total)) if trailers: DB.Trailers.update(verified=False).where( DB.Trailers.source == source).execute() total = float(total) allct = 0 ct = 0 for t in trailers: allct += 1 try: dt = DB.Trailers.get(DB.Trailers.WID == t.ID) dt.verified = True dt.watched = t.watched or dt.watched dt.save() except DB.peewee.DoesNotExist: ct += 1 url = t.getStaticURL() DB.Trailers.create(WID=t.ID, source=source, watched=t.watched, title=t.title, url=url, userAgent=t.userAgent, rating=str(t.rating), genres=','.join(t.genres), thumb=t.thumb, release=t.release, is3D=t.is3D, verified=True) pct = int((allct / total) * 100) self._callback(t.title, pct=pct) rows = DB.Trailers.delete().where( DB.Trailers.verified == 0, DB.Trailers.source == source).execute() util.DEBUG_LOG( ' - {0} new {1} trailers added to database'.format( ct, source)) util.DEBUG_LOG( ' - {0} {1} trailers removed from database'.format( rows, source)) else: util.DEBUG_LOG( ' - No new {0} trailers added to database'.format( source))
def scrapeContent(self): import scrapers scrapers.setContentPath(self._contentDirectory) for stype, source in util.contentScrapers(): if stype == 'trailers': util.DEBUG_LOG('Getting trailers from {0}'.format(source)) self._callback(heading='Adding {0} trailers...'.format(source)) self._callback('Getting trailer list...', pct=0) trailers = scrapers.getTrailers(source) total = len(trailers) util.DEBUG_LOG(' - Received {0} trailers'.format(total)) if trailers: DB.Trailers.update(verified=False).where( DB.Trailers.source == source ).execute() total = float(total) allct = 0 ct = 0 for t in trailers: allct += 1 try: dt = DB.Trailers.get(DB.Trailers.WID == t.ID) dt.verified = True dt.watched = t.watched or dt.watched dt.save() except DB.peewee.DoesNotExist: ct += 1 url = t.getStaticURL() DB.Trailers.create( WID=t.ID, source=source, watched=t.watched, title=t.title, url=url, userAgent=t.userAgent, rating=str(t.rating), genres=','.join(t.genres), thumb=t.thumb, release=t.release, is3D=t.is3D, verified=True ) pct = int((allct/total)*100) self._callback(t.title, pct=pct) rows = DB.Trailers.delete().where( DB.Trailers.verified == 0, DB.Trailers.source == source ).execute() util.DEBUG_LOG(' - {0} new {1} trailers added to database'.format(ct, source)) util.DEBUG_LOG(' - {0} {1} trailers removed from database'.format(rows, source)) else: util.DEBUG_LOG(' - No new {0} trailers added to database'.format(source))
def getLive(self, attr): if attr != 'scrapers': return Item.getLive(self, attr) val = Item.getLive(self, attr) if not val: return val inSettings = (val).split(',') contentScrapers = [s for t, s in util.contentScrapers() if t == 'trailers'] return ','.join([s for s in inSettings if s in contentScrapers])
def Select(self, attr): selected = [s.strip().lower() for s in self.liveScrapers()] contentScrapers = util.contentScrapers() temp = [list(x) for x in self._scrapers] ret = [] for s in temp: for ctype, c in contentScrapers: if ctype == 'trailers' and c == s[0]: s[2] = s[2] in selected ret.append(s) ret.sort(key=lambda i: i[0].lower() in selected and selected.index(i[0].lower())+1 or 99) return ret