|
1 | 1 | # Bu araç @keyiflerolsun tarafından | @KekikAkademi için yazılmıştır. |
2 | 2 |
|
3 | | -from KekikStream.Core import PluginBase, MainPageResult, SearchResult, MovieInfo, Subtitle |
| 3 | +from KekikStream.Core import PluginBase, MainPageResult, SearchResult, MovieInfo, SeriesInfo, Episode, Subtitle |
4 | 4 | from parsel import Selector |
5 | 5 | from Kekik.Sifreleme import Packer, StreamDecoder |
6 | 6 | import random, string, re |
@@ -71,36 +71,76 @@ async def search(self, query: str) -> list[SearchResult]: |
71 | 71 |
|
72 | 72 | return results |
73 | 73 |
|
74 | | - async def load_item(self, url: str) -> MovieInfo: |
| 74 | + async def load_item(self, url: str) -> MovieInfo | SeriesInfo: |
75 | 75 | istek = await self.httpx.get(url, headers = {"Referer": f"{self.main_url}/"}) |
76 | 76 | secici = Selector(istek.text) |
77 | 77 |
|
78 | | - title = secici.css("h1.section-title::text").get().strip() |
79 | | - poster = secici.css("aside.post-info-poster img.lazyload::attr(data-src)").get().strip() |
80 | | - description = secici.css("article.post-info-content > p::text").get().strip() |
| 78 | + title = secici.css("h1.section-title::text").get() |
| 79 | + title = title.strip() if title else "" |
| 80 | + poster = secici.css("aside.post-info-poster img.lazyload::attr(data-src)").get() or "" |
| 81 | + poster = poster.strip() if poster else "" |
| 82 | + description = secici.css("article.post-info-content > p::text").get() or "" |
| 83 | + description = description.strip() if description else "" |
81 | 84 | tags = secici.css("div.post-info-genres a::text").getall() |
82 | | - rating = secici.css("div.post-info-imdb-rating span::text").get().strip() |
83 | | - year = secici.css("div.post-info-year-country a::text").get().strip() |
| 85 | + rating = secici.css("div.post-info-imdb-rating span::text").get() or "" |
| 86 | + rating = rating.strip() if rating else "" |
| 87 | + year = secici.css("div.post-info-year-country a::text").get() or "" |
| 88 | + year = year.strip() if year else "" |
84 | 89 | actors = secici.css("div.post-info-cast a > strong::text").getall() |
85 | | - duration = secici.css("div.post-info-duration::text").get().replace("dakika", "").strip() |
| 90 | + duration = secici.css("div.post-info-duration::text").get() or "0" |
| 91 | + duration = duration.replace("dakika", "").strip() |
86 | 92 |
|
87 | | - |
88 | 93 | try: |
89 | | - duration_minutes = int(duration[2:-1]) |
| 94 | + duration_minutes = int(re.search(r'\d+', duration).group()) if re.search(r'\d+', duration) else 0 |
90 | 95 | except Exception: |
91 | 96 | duration_minutes = 0 |
92 | 97 |
|
93 | | - return MovieInfo( |
94 | | - url = url, |
95 | | - poster = self.fix_url(poster), |
96 | | - title = self.clean_title(title), |
97 | | - description = description, |
98 | | - tags = tags, |
99 | | - rating = rating, |
100 | | - year = year, |
101 | | - actors = actors, |
102 | | - duration = duration_minutes |
103 | | - ) |
| 98 | + # Dizi mi film mi kontrol et (Kotlin referansı: div.seasons kontrolü) |
| 99 | + is_series = len(secici.css("div.seasons").getall()) > 0 |
| 100 | + |
| 101 | + if is_series: |
| 102 | + episodes = [] |
| 103 | + for ep in secici.css("div.seasons-tab-content a"): |
| 104 | + ep_name = ep.css("h4::text").get() |
| 105 | + ep_href = ep.css("::attr(href)").get() |
| 106 | + if ep_name and ep_href: |
| 107 | + ep_name = ep_name.strip() |
| 108 | + # Regex ile sezon ve bölüm numarası çıkar |
| 109 | + ep_match = re.search(r'(\d+)\.\s*Bölüm', ep_name) |
| 110 | + sz_match = re.search(r'(\d+)\.\s*Sezon', ep_name) |
| 111 | + ep_num = int(ep_match.group(1)) if ep_match else 1 |
| 112 | + sz_num = int(sz_match.group(1)) if sz_match else 1 |
| 113 | + |
| 114 | + episodes.append(Episode( |
| 115 | + season = sz_num, |
| 116 | + episode = ep_num, |
| 117 | + title = ep_name, |
| 118 | + url = self.fix_url(ep_href) |
| 119 | + )) |
| 120 | + |
| 121 | + return SeriesInfo( |
| 122 | + url = url, |
| 123 | + poster = self.fix_url(poster), |
| 124 | + title = self.clean_title(title), |
| 125 | + description = description, |
| 126 | + tags = tags, |
| 127 | + rating = rating, |
| 128 | + year = year, |
| 129 | + actors = actors, |
| 130 | + episodes = episodes |
| 131 | + ) |
| 132 | + else: |
| 133 | + return MovieInfo( |
| 134 | + url = url, |
| 135 | + poster = self.fix_url(poster), |
| 136 | + title = self.clean_title(title), |
| 137 | + description = description, |
| 138 | + tags = tags, |
| 139 | + rating = rating, |
| 140 | + year = year, |
| 141 | + actors = actors, |
| 142 | + duration = duration_minutes |
| 143 | + ) |
104 | 144 |
|
105 | 145 | def generate_random_cookie(self): |
106 | 146 | return "".join(random.choices(string.ascii_letters + string.digits, k=16)) |
|
0 commit comments