Spaces:
Paused
Paused
File size: 4,107 Bytes
869331d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
from tmdbv3api import TMDb, Movie, TV
import requests
import logging
from bs4 import BeautifulSoup,SoupStrainer
from datetime import datetime
import dateparser
from convert import get_TMDb_id_from_IMDb_id
from info import get_info_tmdb, is_movie, get_info_imdb
import config
import re
import json
LC_DOMAIN = config.LC_DOMAIN
async def search(showname,date,season,episode,ismovie,client):
cookies = {
'csrftoken': '7lvc502CZe8Zbx7iSX1xkZOBA1NbDxJZ',
}
headers = {
'authority': f'lordchannel.{LC_DOMAIN}',
'accept': '*/*',
'accept-language': 'it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7',
# 'cookie': 'csrftoken=7lvc502CZe8Zbx7iSX1xkZOBA1NbDxJZ',
'referer': f'https://lordchannel.{LC_DOMAIN}/anime/anime-ita/',
'sec-ch-ua': '"Not-A.Brand";v="99", "Chromium";v="124"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Android"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
'x-requested-with': 'XMLHttpRequest',
}
params = {
'media': showname,
'_': '1724421723999',
}
response = await client.get(f'https://lordchannel.{LC_DOMAIN}/live_search/', params=params, cookies=cookies, headers=headers, follow_redirects=True)
data = json.loads(response.text)
for entry in data['data']:
if entry is not None: # check if the a_tag exists
href = entry['url']
quality = entry['qualit\u00e0_video']
link = f'https://lordchannel.{LC_DOMAIN}{href}'
response = await client.get(link, follow_redirects=True)
soup2 = BeautifulSoup(response.text,'lxml')
li_tag = soup2.select_one("ul.card__meta li:nth-of-type(2)")
if li_tag is not None: # check if the li_tag exists
card_date = li_tag.text[-4:]
if card_date == date:
if ismovie == 1:
video_url = soup2.find('a', class_="btn-streaming streaming_btn")
video_url = video_url['href']
return video_url,quality
elif ismovie == 0:
div = soup2.find('div', id=f'collapse{season}')
episode = episode -1 #Index start from 0 so I need to subtract 1
episode = div.select('tr')[2] # index is 2 because we want the correct element
video_url = href = episode.find('a').get('href')
return video_url,quality
else:
print("Sadly date are not equals")
continue
async def get_m3u8(video_url,client):
response = await client.get(video_url, follow_redirects=True)
pattern = r'const videoData = \[(.*?)\];'
match = re.search(pattern, response.text)
if match:
video_data = match.group(1).strip().split(', ')
url = video_data[0]
return url
async def lordchannel(imdb,client):
try:
general = is_movie(imdb)
ismovie = general[0]
imdb_id = general[1]
type = "LordChannel"
if ismovie == 0:
season = int(general[2])
episode = int(general[3])
if "tt" in imdb:
tmdba = await get_TMDb_id_from_IMDb_id(imdb_id,client)
else:
tmdba = imdb_id
else:
season = None
episode = None
if "tt" in imdb:
tmdba = await get_TMDb_id_from_IMDb_id(imdb_id,client)
else:
tmdba = imdb_id
showname,date = get_info_tmdb(tmdba,ismovie,type)
video_url,quality = await search(showname,date,season,episode,ismovie,client)
url = await get_m3u8(video_url,client)
url = url.replace('"','')
print(url)
return url,quality
except:
print("Lordchannel Failed")
return None,None
|