Skip to content

Commit

Permalink
Used Session in some modules
Browse files Browse the repository at this point in the history
  • Loading branch information
YofaGh committed Jul 17, 2024
1 parent 7171644 commit ad0bc63
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
6 changes: 4 additions & 2 deletions modules/Comick.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ def get_info(manga):
}

def get_chapters(manga):
response = Comick.send_request(f'https://comick.cc/comic/{manga}', headers=Comick.headers)
session = Comick.create_session()
session.headers = Comick.headers
response = Comick.send_request(f'https://comick.cc/comic/{manga}', session=session)
soup = BeautifulSoup(response.text, 'html.parser')
script = soup.find('script', {'id': '__NEXT_DATA__'})
hid = json.loads(script.get_text(strip=True))['props']['pageProps']['comic']['hid']
chapters_urls = []
page = 1
while True:
response = Comick.send_request(f'https://api.comick.cc/comic/{hid}/chapters?lang=en&chap-order=1&page={page}', headers=Comick.headers).json()
response = Comick.send_request(f'https://api.comick.cc/comic/{hid}/chapters?lang=en&chap-order=1&page={page}', session=session).json()
if not response['chapters']:
break
chapters_urls.extend([f'{chapter["hid"]}-chapter-{chapter["chap"]}-en' for chapter in response['chapters'] if chapter['chap']])
Expand Down
5 changes: 3 additions & 2 deletions modules/Comics8Muses.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def get_info(manga):
def get_chapters(manga):
page = 1
chapters_urls = []
response = Comics8Muses.send_request(f'https://comics.8muses.com/comics/album/{manga}/{page}')
session = Comics8Muses.create_session()
response = Comics8Muses.send_request(f'https://comics.8muses.com/comics/album/{manga}/{page}', session=session)
soup = BeautifulSoup(response.text, 'html.parser')
if not soup.find('div', {'class':'image-title'}):
return ['']
Expand All @@ -26,7 +27,7 @@ def get_chapters(manga):
break
chapters_urls += [link.get('href').split('/')[-1] for link in links]
page += 1
response = Comics8Muses.send_request(f'https://comics.8muses.com/comics/album/{manga}/{page}')
response = Comics8Muses.send_request(f'https://comics.8muses.com/comics/album/{manga}/{page}', session=session)
soup = BeautifulSoup(response.text, 'html.parser')
chapters = [{
'url': chapter_url,
Expand Down
7 changes: 4 additions & 3 deletions modules/Hentaixcomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ def get_info(manga):
}

def get_chapters(manga):
response = Hentaixcomic.send_request(f'https://hentaixcomic.com/manga/{manga}')
session = Hentaixcomic.create_session()
response = Hentaixcomic.send_request(f'https://hentaixcomic.com/manga/{manga}', session=session)
soup = BeautifulSoup(response.text, 'html.parser')
manga_id = soup.find('a', {'class': 'wp-manga-action-button'})['data-post']
headers = {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}
session.headers = {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}
data = f'action=manga_get_chapters&manga={manga_id}'
response = Hentaixcomic.send_request('https://hentaixcomic.com/wp-admin/admin-ajax.php', method='POST', headers=headers, data=data)
response = Hentaixcomic.send_request('https://hentaixcomic.com/wp-admin/admin-ajax.php', method='POST', session=session, data=data)
soup = BeautifulSoup(response.text, 'html.parser')
divs = soup.find_all('li', {'class':'wp-manga-chapter'})
chapters_urls = [div.find('a')['href'].split('/')[-2] for div in divs[::-1]]
Expand Down
5 changes: 3 additions & 2 deletions modules/Luscious.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ def get_title(code):

def get_images(code):
data = 'https://apicdn.luscious.net/graphql/nobatch/?operationName=PictureListInsideAlbum&query=%2520query%2520PictureListInsideAlbum%28%2524input%253A%2520PictureListInput%21%29%2520%257B%2520picture%2520%257B%2520list%28input%253A%2520%2524input%29%2520%257B%2520info%2520%257B%2520...FacetCollectionInfo%2520%257D%2520items%2520%257B%2520url_to_original%2520position%2520%257B%2520category%2520text%2520url%2520%257D%2520thumbnails%2520%257B%2520width%2520height%2520size%2520url%2520%257D%2520%257D%2520%257D%2520%257D%2520%257D%2520fragment%2520FacetCollectionInfo%2520on%2520FacetCollectionInfo%2520%257B%2520page%2520total_pages%2520%257D%2520&variables=%7B%22input%22%3A%7B%22filters%22%3A%5B%7B%22name%22%3A%22album_id%22%2C%22value%22%3A%22__album__id__%22%7D%5D%2C%22display%22%3A%22position%22%2C%22items_per_page%22%3A50%2C%22page%22%3A__page__number__%7D%7D'
response = Luscious.send_request(data.replace('__album__id__', str(code)).replace('__page__number__', '1')).json()
session = Luscious.create_session()
response = Luscious.send_request(data.replace('__album__id__', str(code)).replace('__page__number__', '1'), session=session).json()
total_pages = response['data']['picture']['list']['info']['total_pages']
images = [item['url_to_original'] for item in response['data']['picture']['list']['items']]
for page in range(2,total_pages + 1):
response = Luscious.send_request(data.replace('__album__id__', str(code)).replace('__page__number__', str(page))).json()
response = Luscious.send_request(data.replace('__album__id__', str(code)).replace('__page__number__', str(page)), session=session).json()
new_images = [item['url_to_original'] for item in response['data']['picture']['list']['items']]
images.extend(new_images)
return images, False
Expand Down
7 changes: 4 additions & 3 deletions modules/Mangaforfree.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ def get_info(manga):
}

def get_chapters(manga):
response = Mangaforfree.send_request(f'https://mangaforfree.net/manga/{manga}')
session = Mangaforfree.create_session()
response = Mangaforfree.send_request(f'https://mangaforfree.net/manga/{manga}', session=session)
soup = BeautifulSoup(response.text, 'html.parser')
manga_id = soup.find('a', {'class': 'wp-manga-action-button'})['data-post']
headers = {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}
session.headers = {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}
data = f'action=manga_get_chapters&manga={manga_id}'
response = Mangaforfree.send_request('https://mangaforfree.net/wp-admin/admin-ajax.php', method='POST', headers=headers, data=data)
response = Mangaforfree.send_request('https://mangaforfree.net/wp-admin/admin-ajax.php', method='POST', session=session, data=data)
soup = BeautifulSoup(response.text, 'html.parser')
divs = soup.find_all('li', {'class': 'wp-manga-chapter'})
chapters_urls = [div.find('a')['href'].split('/')[-2] for div in divs[::-1]]
Expand Down
5 changes: 3 additions & 2 deletions modules/Omegascans.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ def get_info(manga):
}

def get_chapters(manga):
response = Omegascans.send_request('https://omegascans.org/series/where-is-my-hammer')
session = Omegascans.create_session()
response = Omegascans.send_request('https://omegascans.org/series/where-is-my-hammer', session=session)
soup = BeautifulSoup(response.text, 'html.parser')
series_id = soup.find(lambda tag: tag.name == 'script' and 'series_id' in tag.text).text.split('{\\"series_id\\":')[1].split(',')[0]
response = Omegascans.send_request(f'https://api.omegascans.org/chapter/query?page=1&perPage=10000&series_id={series_id}')
response = Omegascans.send_request(f'https://api.omegascans.org/chapter/query?page=1&perPage=10000&series_id={series_id}', session=session)
chapters = [{
'url': chapter['chapter_slug'],
'name': chapter['chapter_name']
Expand Down
5 changes: 3 additions & 2 deletions modules/Truemanga.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ def get_info(manga):
}

def get_chapters(manga):
response = Truemanga.send_request(f'https://truemanga.com/{manga}')
session = Truemanga.create_session()
response = Truemanga.send_request(f'https://truemanga.com/{manga}', session=session)
soup = BeautifulSoup(response.text, 'html.parser')
script = soup.find(lambda tag:tag.name == 'script' and 'bookId' in tag.text).text
book_id = script.split('bookId = ')[1].split(';', 1)[0]
response = Truemanga.send_request(f'https://truemanga.com/api/manga/{book_id}/chapters')
response = Truemanga.send_request(f'https://truemanga.com/api/manga/{book_id}/chapters', session=session)
soup = BeautifulSoup(response.text, 'html.parser')
chapters = [{
'url': chapter['value'].split('/')[-1],
Expand Down

0 comments on commit ad0bc63

Please sign in to comment.