def filter(cls, material: str, options: list, max: int = 5) -> list: """ filter movies based on options options supported values: filter : latest, top, popular year : year if under 2000 add 's' example -> 2012, 1950s bad usage -> 2012s, 1951 language: language example -> arabic, english country : iso code of the country example -> us, ma type: type -> example -> action, documentary content rating : example -> [PG-13] +13 , unrated, quality: example -> bluray, hdrip precision : example -> 1080p, 720p example of filtering - > Site.filter('tv', ['top', 'us', '1080p']) 1) order doesn't matter 2) pass options as a list 3) options are optinal you don't have to pass all of them """ material = material.lower() if material not in cls.supported: print(f'Supported filters are {", ".join(cls.supported)}') return None text = '' for page in range(1, max + 1): query = cls.filter_api.format(material=material, options='-'.join(options), page=page) r = requests.get(query).json() text += r['html'] soup = BeautifulSoup(text, 'lxml') return [ Utils.pickup_class(link['href'], title=link.find(class_='title').text) for link in soup.find_all(class_='movie') ]
def shows_container_scrape(self, item): t = item.find(class_='contents movies_small') return [ Utils.pickup_class(link=item['href'], title=item.find(class_='title').text, thumbnail=item.img['src']) for item in t.find_all('a') ]
def get_seasons(self): """ return all seasons of a serie """ container = self.soup.find(class_='contents movies_small') return [Utils.pickup_class( link=link['href'], title=link.find(class_='title').text, thumbnail=link.img['src'] ) for link in container.find_all('a')]
def get_similar(self): """get similar movies.""" container = self.soup.find(class_='contents movies_small') return [Utils.pickup_class( link['href'], title=link.find(class_='title').text ) for link in container.find_all('a')]
def get_episodes(self): """ get all episodes of a Season """ container = self.soup.find(class_='movies_small') return [ Utils.pickup_class( link['href'], title=link.find(class_='title').text, thumbnail=link.img['src'], ) for link in container.find_all('a') ]
def scrape_movies(self, max=1): content = dict(new=list(), top=list(), popular=list(), old=list()) for categorie in content.keys(): for id in range(1, max + 1): soup = Utils.page_downloader( f'{self.link}{categorie}?page={id}') con = soup.find(class_='movies movies_small') content[categorie].extend([ Utils.pickup_class(movie['href']) for movie in con.find_all(class_='movie') ]) return content
def search(cls, query: str, access=True, **kwargs) -> list or None: """ a class to search inside the site : movies, series ... return instance of class's that blong the the type of result """ tamplate = '%s/{}' % cls.my_site pram = (('q', query), ) r = requests.get(cls.search_api, params=pram, **kwargs).json() if r: return [ Utils.pickup_class( link=tamplate.format(movie['u']), title=movie['t'], ) for elem in r for movie in r[elem] ] return None