def __call__(self, caller, sItem):
        self.caller = caller
        self.sItem = sItem

        source = sItem.getLive('source')
        count = sItem.getLive('count')

        playables = []
        if source == 'content':
            scrapers.setContentPath(self.caller.contentPath)
            util.DEBUG_LOG('[{0}] {1} x {2}'.format(self.sItem.typeChar, source, count))
            scrapersList = (sItem.getLive('scrapers') or '').split(',')
            if util.getSettingDefault('trailer.preferUnwatched'):
                scrapersInfo = [(s.strip(), True, False) for s in scrapersList]
                scrapersInfo += [(s.strip(), False, True) for s in scrapersList]
            else:
                scrapersInfo = [(s.strip(), True, True) for s in scrapersList]

            for scraper, unwatched, watched in scrapersInfo:
                util.DEBUG_LOG('    - [{0}]'.format(scraper))
                playables += self.scraperHandler(scraper, count, unwatched=unwatched, watched=watched)
                count -= min(len(playables), count)
                if count <= 0:
                    break

        elif source == 'dir' or source == 'content':
            playables = self.dirHandler(sItem)
        elif source == 'file':
            playables = self.fileHandler(sItem)

        if not playables:
            util.DEBUG_LOG('    - NOT SHOWING')

        return playables
    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 __call__(self, caller, sItem):
        self.caller = caller
        self.sItem = sItem

        source = sItem.getLive('source')
        count = sItem.getLive('count')

        playables = []
        if source == 'content':
            scrapers.setContentPath(self.caller.contentPath)
            util.DEBUG_LOG('[{0}] {1} x {2}'.format(self.sItem.typeChar,
                                                    source, count))
            scrapersList = (sItem.getLive('scrapers') or '').split(',')
            if util.getSettingDefault('trailer.preferUnwatched'):
                scrapersInfo = [(s.strip(), True, False) for s in scrapersList]
                scrapersInfo += [(s.strip(), False, True)
                                 for s in scrapersList]
            else:
                scrapersInfo = [(s.strip(), True, True) for s in scrapersList]

            for scraper, unwatched, watched in scrapersInfo:
                util.DEBUG_LOG('    - [{0}]'.format(scraper))
                playables += self.scraperHandler(scraper,
                                                 count,
                                                 unwatched=unwatched,
                                                 watched=watched)
                count -= min(len(playables), count)
                if count <= 0:
                    break

        elif source == 'dir' or source == 'content':
            playables = self.dirHandler(sItem)
        elif source == 'file':
            playables = self.fileHandler(sItem)

        if not playables:
            util.DEBUG_LOG('    - NOT SHOWING')

        return playables