def next(self, serie, scraper): if not serie.onGoing or serie.lastChapter == serie.totalChapters: PirateBayScraper.logger.info( '%s finished. No chapters to look for' % serie) return -1 # mapping parameters. params = scraper.map(serie.params) chapter = serie.lastChapter + 1 cssSelector = '#searchResult > tr:nth-of-type(1) > td:nth-of-type(2) > a:nth-of-type(1)' res = requests.get(serie.fansub.baseUrl + params['searchStr'] + '%02d' % chapter) soup = bs4.BeautifulSoup(res.text, 'html.parser') links = soup.select(cssSelector) if len(links) == 0: PirateBayScraper.logger.debug('%s chapter %d not found' % (serie, chapter)) return False else: PirateBayScraper.logger.info('%s chapter %d found' % (serie, chapter)) Link.create(link=links[0]['href'], serie=serie, chapter=chapter) serie.lastChapter = chapter # put the magnet link into transmission Transmission.add(links[0]['href']) if serie.lastChapter == serie.totalChapters: serie.onGoing = False serie.save() if scraper.notificate: Notification.create( message='New: %s - Ch. %d from %s' % (serie.title, serie.lastChapter, scraper.fansub.name)) return True
def _torrentNext(self, serie, params, scraper): res = requests.get(serie.fansub.baseUrl % (params['fl-animeId'], params['fl-fansubId'])) soup = bs4.BeautifulSoup(res.text, 'html.parser') chapter = serie.lastChapter + 1 # </a> anchors = soup.select(FrozenLayerScraper.cssPageSelector) chapterLink = False for a in anchors: # generates a list with all numbers of the </a> text if ' al ' in a.text or '1080' in a.text: # to avoid several chapters torrents continue chaptersList = [int(s) for s in a.text.split() if s.isdigit()] if chapter in chaptersList: chapterLink = a['href'] if chapterLink: # inside chapter page res = requests.get(chapterLink) soup = bs4.BeautifulSoup(res.text, 'html.parser') anchors = soup.select('a') magnetLink = False for a in anchors: if 'magnet:' in a['href']: magnetLink = a['href'] break if not magnetLink: FrozenLayerScraper.logger.debug('%s chapter %d not found' % (serie, chapter)) return -1 Link.create(link=magnetLink, serie=serie, chapter=chapter) serie.lastChapter = chapter # put the magnet link into transmission Transmission.add(magnetLink) if serie.lastChapter == serie.totalChapters: serie.onGoing = False serie.save() if scraper.notificate: Notification.create( message='New: %s - Ch. %d from %s' % (serie.title, serie.lastChapter, scraper.fansub.name)) FrozenLayerScraper.logger.info('%s chapter %d found' % (serie, chapter)) return True else: FrozenLayerScraper.logger.debug('%s chapter %d not found' % (serie, chapter)) return -1