Guest User

source_utils.py

a guest
Apr 7th, 2025
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.41 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import re
  3. import json
  4. from urllib.parse import unquote, unquote_plus
  5. from modules.metadata import episodes_meta
  6. from modules.settings import date_offset
  7. from modules.kodi_utils import supported_media, set_property, notification
  8. from modules.utils import adjust_premiered_date, get_datetime, jsondate_to_datetime, subtract_dates
  9. # from modules.kodi_utils import logger
  10.  
  11. def extras():
  12. return ('sample', 'extra', 'extras', 'deleted', 'unused', 'footage', 'inside', 'blooper', 'bloopers', 'making.of', 'feature', 'featurette', 'behind.the.scenes', 'trailer')
  13.  
  14. def unwanted_tags():
  15. return (
  16. 'tamilrockers.com', 'www.tamilrockers.com', 'www.tamilrockers.ws', 'www.tamilrockers.pl', 'www-tamilrockers-cl', 'www.tamilrockers.cl', 'www.tamilrockers.li',
  17. 'www.tamilrockerrs.pl', 'www.tamilmv.bid', 'www.tamilmv.biz', 'www.1tamilmv.org', 'gktorrent-bz', 'gktorrent-com', 'www.torrenting.com', 'www.torrenting.org',
  18. 'www-torrenting-com', 'www-torrenting-org', 'katmoviehd.pw', 'katmoviehd-pw', 'www.torrent9.nz', 'www-torrent9-uno', 'torrent9-cz', 'torrent9.cz',
  19. 'agusiq-torrents-pl', 'oxtorrent-bz', 'oxtorrent-com', 'oxtorrent.com', 'oxtorrent-sh', 'oxtorrent-vc', 'www.movcr.tv', 'movcr-com', 'www.movcr.to', '(imax)',
  20. 'imax', 'xtorrenty.org', 'nastoletni.wilkoak', 'www.scenetime.com', 'kst-vn', 'www.movierulz.vc', 'www-movierulz-ht', 'www.2movierulz.ac', 'www.2movierulz.ms',
  21. 'www.3movierulz.com', 'www.3movierulz.tv', 'www.3movierulz.ws', 'www.3movierulz.ms', 'www.7movierulz.pw', 'www.8movierulz.ws', 'mkvcinemas.live', 'www.bludv.tv',
  22. 'ramin.djawadi', 'extramovies.casa', 'extramovies.wiki', '13+', '18+', 'taht.oyunlar', 'crazy4tv.com', 'karibu', '989pa.com', 'best-torrents-net', '1-3-3-8.com',
  23. 'ssrmovies.club', 'va:', 'zgxybbs-fdns-uk', 'www.tamilblasters.mx', 'www.1tamilmv.work', 'www.xbay.me', 'crazy4tv-com', '(es)')
  24.  
  25. def audio_filter_choices():
  26. return (
  27. ('DOLBY DIGITAL', 'DD'), ('DOLBY DIGITAL PLUS', 'DD+'), ('DOLBY DIGITAL EX', 'DD-EX'), ('DOLBY ATMOS', 'ATMOS'), ('DOLBY TRUEHD', 'TRUEHD'),
  28. ('DTS', 'DTS'), ('DTS-HD MASTER AUDIO', 'DTS-HD MA'), ('DTS-X', 'DTS-X'), ('DTS-HD', 'DTS-HD'), ('AAC', 'AAC'), ('OPUS', 'OPUS'), ('MP3', 'MP3'),
  29. ('8CH AUDIO', '8CH'), ('7CH AUDIO', '7CH'), ('6CH AUDIO', '6CH'), ('2CH AUDIO', '2CH'))
  30.  
  31. def source_filters():
  32. return (
  33. ('PACK', 'PACK'), ('DOLBY VISION', '[B]D/VISION[/B]'), ('HIGH DYNAMIC RANGE (HDR)', '[B]HDR[/B]'), ('IMAX', 'IMAX'), ('HYBRID', '[B]HYBRID[/B]'), ('AV1', '[B]AV1[/B]'),
  34. ('HEVC (X265)', '[B]HEVC[/B]'), ('REMUX', 'REMUX'), ('BLURAY', 'BLURAY'), ('AI ENHANCED/UPSCALED', '[B]AI ENHANCED/UPSCALED[/B]'), ('SDR', 'SDR'), ('3D', '[B]3D[/B]'),
  35. ('DOLBY ATMOS', 'ATMOS'), ('DOLBY TRUEHD', 'TRUEHD'), ('DOLBY DIGITAL EX', 'DD-EX'), ('DOLBY DIGITAL PLUS', 'DD+'), ('DOLBY DIGITAL', 'DD'), ('DTS-HD MASTER AUDIO', 'DTS-HD MA'),
  36. ('DTS-X', 'DTS-X'), ('DTS-HD', 'DTS-HD'), ('DTS', 'DTS'), ('AAC', 'AAC'), ('OPUS', 'OPUS'), ('MP3', 'MP3'), ('8CH AUDIO', '8CH'), ('7CH AUDIO', '7CH'), ('6CH AUDIO', '6CH'),
  37. ('2CH AUDIO', '2CH'), ('DVD SOURCE', 'DVD'), ('WEB SOURCE', 'WEB'), ('MULTIPLE LANGUAGES', 'MULTI-LANG'), ('SUBTITLES', 'SUBS'))
  38.  
  39. def get_aliases_titles(aliases):
  40. try: result = [i['title'] for i in aliases]
  41. except: result = []
  42. return result
  43.  
  44. def make_alias_dict(meta, title):
  45. aliases = []
  46. alternative_titles = meta.get('alternative_titles', [])
  47. original_title = meta['original_title']
  48. country_codes = set([i.replace('GB', 'UK') for i in meta.get('country_codes', [])])
  49. if alternative_titles: aliases = [{'title': i, 'country': ''} for i in alternative_titles]
  50. if original_title not in alternative_titles: aliases.append({'title': original_title, 'country': ''})
  51. if country_codes: aliases.extend([{'title': '%s %s' % (title, i), 'country': ''} for i in country_codes])
  52. return aliases
  53.  
  54. def internal_results(provider, sources):
  55. set_property('fenlight.internal_results.%s' % provider, json.dumps(sources))
  56.  
  57. def normalize(title):
  58. import unicodedata
  59. try:
  60. title = ''.join(c for c in unicodedata.normalize('NFKD', title) if unicodedata.category(c) != 'Mn')
  61. return str(title)
  62. except: return title
  63.  
  64. def pack_enable_check(meta, season, episode):
  65. try:
  66. status = meta['extra_info']['status']
  67. if status in ('Ended', 'Canceled'): return True, True
  68. adjust_hours, current_date = date_offset(), get_datetime()
  69. episodes_data = episodes_meta(season, meta)
  70. unaired_episodes = [adjust_premiered_date(i['premiered'], adjust_hours)[0] for i in episodes_data]
  71. if None in unaired_episodes or any(i > current_date for i in unaired_episodes): return False, False
  72. else: return True, False
  73. except: pass
  74. return False, False
  75.  
  76. def clear_scrapers_cache(silent=False):
  77. from caches.base_cache import clear_cache
  78. for item in ('internal_scrapers', 'external_scrapers'): clear_cache(item, silent=True)
  79. if not silent: notification('Success')
  80.  
  81. def supported_video_extensions():
  82. supported_video_extensions = supported_media().split('|')
  83. return [i for i in supported_video_extensions if not i in ('','.zip','.rar','.iso')]
  84.  
  85. def seas_ep_filter(season, episode, release_title, split=False, return_match=False):
  86. str_season, str_episode = str(season), str(episode)
  87. season_fill, episode_fill = str_season.zfill(2), str_episode.zfill(2)
  88. str_ep_plus_1, str_ep_minus_1 = str(episode+1), str(episode-1)
  89. release_title = re.sub(r'[^A-Za-z0-9-]+', '.', unquote(release_title).replace('\'', '')).lower()
  90.  
  91. string1 = r'(s<<S>>[.-]?e[p]?[.-]?<<E>>[.-])'
  92. string2 = r'(season[.-]?<<S>>[.-]?episode[.-]?<<E>>[.-])|([s]?<<S>>[x.]<<E>>[.-])'
  93. string3 = r'(s<<S>>e<<E1>>[.-]?e?<<E2>>[.-])'
  94. string4 = r'([.-]<<S>>[.-]?<<E>>[.-])'
  95. string5 = r'(episode[.-]?<<E>>[.-])'
  96. string6 = r'([.-]e[p]?[.-]?<<E>>[.-])'
  97. string7 = r'(^(?=.*\.e?0*<<E>>\.)(?:(?!((?:s|season)[.-]?\d+[.-x]?(?:ep?|episode)[.-]?\d+)|\d+x\d+).)*$)'
  98.  
  99. # -- Custom additional regex patterns start here --
  100. string8 = r'(s<<S>>[.-]?<<E>>[.-])'
  101. # -- Custom additional regex patterns end here --
  102.  
  103. string_list = []
  104. string_list_append = string_list.append
  105. string_list_append(string1.replace('<<S>>', season_fill).replace('<<E>>', episode_fill))
  106. string_list_append(string1.replace('<<S>>', str_season).replace('<<E>>', episode_fill))
  107. string_list_append(string1.replace('<<S>>', season_fill).replace('<<E>>', str_episode))
  108. string_list_append(string1.replace('<<S>>', str_season).replace('<<E>>', str_episode))
  109. string_list_append(string2.replace('<<S>>', season_fill).replace('<<E>>', episode_fill))
  110. string_list_append(string2.replace('<<S>>', str_season).replace('<<E>>', episode_fill))
  111. string_list_append(string2.replace('<<S>>', season_fill).replace('<<E>>', str_episode))
  112. string_list_append(string2.replace('<<S>>', str_season).replace('<<E>>', str_episode))
  113. string_list_append(string3.replace('<<S>>', season_fill).replace('<<E1>>', str_ep_minus_1.zfill(2)).replace('<<E2>>', episode_fill))
  114. string_list_append(string3.replace('<<S>>', season_fill).replace('<<E1>>', episode_fill).replace('<<E2>>', str_ep_plus_1.zfill(2)))
  115. string_list_append(string4.replace('<<S>>', season_fill).replace('<<E>>', episode_fill))
  116. string_list_append(string4.replace('<<S>>', str_season).replace('<<E>>', episode_fill))
  117. string_list_append(string5.replace('<<E>>', str_episode))
  118. string_list_append(string6.replace('<<E>>', episode_fill))
  119. string_list_append(string7.replace('<<E>>', episode_fill))
  120.  
  121. # -- Custom additional regex patterns: string8 appended below --
  122. string_list_append(string8.replace('<<S>>', season_fill).replace('<<E>>', episode_fill))
  123. string_list_append(string8.replace('<<S>>', str_season).replace('<<E>>', episode_fill))
  124. string_list_append(string8.replace('<<S>>', season_fill).replace('<<E>>', str_episode))
  125. string_list_append(string8.replace('<<S>>', str_season).replace('<<E>>', str_episode))
  126.  
  127. final_string = '|'.join(string_list)
  128. reg_pattern = re.compile(final_string)
  129. if split:
  130. return release_title.split(re.search(reg_pattern, release_title).group(), 1)[1]
  131. if return_match:
  132. return re.search(reg_pattern, release_title).group()
  133. return bool(re.search(reg_pattern, release_title))
  134.  
  135. def find_season_in_release_title(release_title):
  136. release_title = re.sub(r'[^A-Za-z0-9-]+', '.', unquote(release_title).replace('\'', '')).lower()
  137. match = None
  138. regex_list = [r's(\d+)', r's\.(\d+)', r'(\d+)x', r'(\d+)\.x', r'season(\d+)', r'season\.(\d+)']
  139. for item in regex_list:
  140. try:
  141. match = re.search(item, release_title)
  142. if match:
  143. match = int(str(match.group(1)).lstrip('0'))
  144. break
  145. except: pass
  146. return match
  147.  
  148. def check_title(title, release_title, aliases, year, season, episode):
  149. try:
  150. all_titles = [title]
  151. if aliases: all_titles += aliases
  152. cleaned_titles = []
  153. cleaned_titles_append = cleaned_titles.append
  154. year = str(year)
  155. for i in all_titles:
  156. cleaned_titles_append(
  157. i.lower().replace('\'', '').replace(':', '').replace('!', '').replace('(', '').replace(')', '').replace('&', 'and').replace(' ', '.').replace(year, ''))
  158. release_title = strip_non_ascii_and_unprintable(release_title).lstrip('/ ').replace(' ', '.').replace(':', '.').lower()
  159. releasetitle_startswith = release_title.startswith
  160. for i in unwanted_tags():
  161. if releasetitle_startswith(i):
  162. i_startswith = i.startswith
  163. pattern = r'\%s' % i if i_startswith('[') or i_startswith('+') else r'%s' % i
  164. release_title = re.sub(r'^%s' % pattern, '', release_title, 1, re.I)
  165. release_title = release_title.lstrip('.-:/')
  166. release_title = re.sub(r'^\[.*?]', '', release_title, 1, re.I)
  167. release_title = release_title.lstrip('.-[](){}:/')
  168. if season:
  169. if season == 'pack': hdlr = ''
  170. else:
  171. try: hdlr = seas_ep_filter(season, episode, release_title, return_match=True)
  172. except: return False
  173. else: hdlr = year
  174. if hdlr:
  175. release_title = release_title.split(hdlr.lower())[0]
  176. release_title = release_title.replace(year, '').replace('(', '').replace(')', '').replace('&', 'and').rstrip('.-').rstrip('.').rstrip('-').replace(':', '')
  177. if not any(release_title == i for i in cleaned_titles): return False
  178. else:
  179. release_title = release_title.replace(year, '').replace('(', '').replace(')', '').replace('&', 'and').rstrip('.-').rstrip('.').rstrip('-').replace(':', '')
  180. if not any(i in release_title for i in cleaned_titles): return False
  181. return True
  182. except: return True
  183.  
  184. def strip_non_ascii_and_unprintable(text):
  185. try:
  186. result = ''.join(char for char in text if char in printable)
  187. return result.encode('ascii', errors='ignore').decode('ascii', errors='ignore')
  188. except: pass
  189. return text
  190.  
  191. def release_info_format(release_title):
  192. try:
  193. release_title = url_strip(release_title)
  194. release_title = release_title.lower().replace("'", "").lstrip('.').rstrip('.')
  195. title = '.%s.' % re.sub(r'[^a-z0-9-~]+', '.', release_title).replace('.-.', '.').replace('-.', '.').replace('.-', '.').replace('--', '.')
  196. return title
  197. except:
  198. return release_title.lower()
  199.  
  200. def clean_title(title):
  201. try:
  202. if not title: return
  203. title = title.lower()
  204. title = re.sub(r'&#(\d+);', '', title)
  205. title = re.sub(r'(&#[0-9]+)([^;^0-9]+)', '\\1;\\2', title)
  206. title = title.replace('&quot;', '\"').replace('&amp;', '&')
  207. title = re.sub(r'\n|([\[({].+?[})\]])|([:;–\-"\',!_.?~$@])|\s', '', title)
  208. except: pass
  209. return title
  210.  
  211. def url_strip(url):
  212. try:
  213. url = unquote_plus(url)
  214. if 'magnet:' in url: url = url.split('&dn=')[1]
  215. url = url.lower().replace("'", "").lstrip('.').rstrip('.')
  216. title = re.sub(r'[^a-z0-9]+', ' ', url)
  217. if 'http' in title: return None
  218. if title == '': return None
  219. return title
  220. except: return None
  221.  
  222. def get_file_info(name_info=None, url=None, default_quality='SD'):
  223. title = None
  224. if name_info: title = name_info
  225. elif url: title = url_strip(url)
  226. if not title: return 'SD', ''
  227. quality = get_release_quality(title) or default_quality
  228. info = get_info(title)
  229. return quality, info
  230.  
  231. def get_release_quality(release_info):
  232. if any(i in release_info for i in ('.scr.', 'screener', 'dvdscr', 'dvd.scr', '.r5', '.r6')):
  233. return 'SCR'
  234. if any(i in release_info for i in ('.cam.', 'camrip', 'hdcam', '.hd.cam', 'hqcam', '.hq.cam', 'cam.rip', 'dvdcam')):
  235. return 'CAM'
  236. if any(i in release_info for i in ('.tc.', '.ts.', 'tsrip', 'hdts', 'hdtc', '.hd.tc', 'dvdts', 'telesync', 'tele.sync', 'telecine', 'tele.cine')):
  237. return 'TELE'
  238. if any(i in release_info for i in ('720', '720p', '720i', 'hd720', '720hd', 'hd720p', '72o', '72op')):
  239. return '720p'
  240. if any(i in release_info for i in ('1080', '1080p', '1080i', 'hd1080', '1080hd', 'hd1080p', 'm1080p', 'fullhd', 'full.hd', '1o8o', '1o8op', '108o', '108op', '1o80', '1o80p')):
  241. return '1080p'
  242. if any(i in release_info for i in ('.4k', 'hd4k', '4khd', '.uhd', 'ultrahd', 'ultra.hd', 'hd2160', '2160hd', '2160', '2160p', '216o', '216op')):
  243. return '4K'
  244. return None
  245.  
  246. def get_info(title):
  247. # thanks 123Venom and gaiaaaiaai, whom I knicked most of this code from. :)
  248. info = []
  249. info_append = info.append
  250. if any(i in title for i in ('.3d.', '.sbs.', '.hsbs', 'sidebyside', 'side.by.side', 'stereoscopic', '.tab.', '.htab.', 'topandbottom', 'top.and.bottom')):
  251. info_append('[B]3D[/B]')
  252. if '.sdr' in title:
  253. info_append('SDR')
  254. elif any(i in title for i in ('dolby.vision', 'dolbyvision', '.dovi.', '.dv.')):
  255. info_append('[B]D/VISION[/B]')
  256. elif any(i in title for i in ('2160p.bluray.hevc.truehd', '2160p.bluray.hevc.dts', '2160p.bluray.hevc.lpcm', '2160p.blu.ray.hevc.truehd', '2160p.blu.ray.hevc.dts',
  257. '2160p.uhd.bluray', '2160p.uhd.blu.ray', '2160p.us.bluray.hevc.truehd', '2160p.us.bluray.hevc.dts', '.hdr.', 'hdr10', 'hdr.10', 'uhd.bluray.2160p', 'uhd.blu.ray.2160p')):
  258. info_append('[B]HDR[/B]')
  259. elif all(i in title for i in ('2160p', 'remux')):
  260. info_append('[B]HDR[/B]')
  261. if '[B]D/VISION[/B]' in info:
  262. if any(i in title for i in ('.hdr.', '.hdr10.', 'hdr.10')) or 'hybrid' in title:
  263. info_append('[B]HDR[/B]')
  264. if '[B]HDR[/B]' in info:
  265. info_append('[B]HYBRID[/B]')
  266. if any(i in title for i in ('avc', 'h264', 'h.264', 'x264', 'x.264')):
  267. info_append('AVC')
  268. elif '.av1.' in title:
  269. info_append('[B]AV1[/B]')
  270. elif any(i in title for i in ('h265', 'h.265', 'hevc', 'x265', 'x.265')):
  271. info_append('[B]HEVC[/B]')
  272. elif any(i in info for i in ('[B]HDR[/B]', '[B]D/VISION[/B]')):
  273. info_append('[B]HEVC[/B]')
  274. if any(i in title for i in ('.imax.', '.(imax).', '.(.imax.).')):
  275. info_append('IMAX')
  276. elif any(i in title for i in ('.enhanced.', '.upscaled.', '.enhance.', '.upscale.')):
  277. info_append('[B]AI ENHANCED/UPSCALED[/B]')
  278. if '.atvp' in title:
  279. info_append('APPLETV+')
  280. elif any(i in title for i in ('xvid', '.x.vid')):
  281. info_append('XVID')
  282. elif any(i in title for i in ('divx', 'div2', 'div3', 'div4')):
  283. info_append('DIVX')
  284. if any(i in title for i in ('remux', 'bdremux')):
  285. info_append('REMUX')
  286. if any(i in title for i in ('bluray', 'blu.ray', 'bdrip', 'bd.rip')):
  287. info_append('BLURAY')
  288. elif any(i in title for i in ('dvdrip', 'dvd.rip')):
  289. info_append('DVD')
  290. elif any(i in title for i in ('.web.', 'webdl', 'web.dl', 'web-dl', 'webrip', 'web.rip')):
  291. info_append('WEB')
  292. elif 'hdtv' in title:
  293. info_append('HDTV')
  294. elif 'pdtv' in title:
  295. info_append('PDTV')
  296. elif any(i in title for i in ('.hdrip', '.hd.rip')):
  297. info_append('HDRIP')
  298. if 'atmos' in title:
  299. info_append('ATMOS')
  300. if any(i in title for i in ('true.hd', 'truehd')):
  301. info_append('TRUEHD')
  302. if any(i in title for i in ('dolby.digital.plus', 'dolbydigital.plus', 'dolbydigitalplus', 'dd.plus.', 'ddplus', '.ddp.', 'ddp2', 'ddp5', 'ddp7', 'eac3', '.e.ac3')):
  303. info_append('DD+')
  304. elif any(i in title for i in ('.dd.ex.', 'ddex', 'dolby.ex.', 'dolby.digital.ex.', 'dolbydigital.ex.')):
  305. info_append('DD-EX')
  306. elif any(i in title for i in ('dd2.', 'dd5', 'dd7', 'dolby.digital', 'dolbydigital', '.ac3', '.ac.3.', '.dd.')):
  307. info_append('DD')
  308. if 'aac' in title:
  309. info_append('AAC')
  310. elif 'mp3' in title:
  311. info_append('MP3')
  312. elif '.flac.' in title:
  313. info_append('FLAC')
  314. elif 'opus' in title and not title.endswith('opus.'):
  315. info_append('OPUS')
  316. if any(i in title for i in ('.dts.x.', 'dtsx')):
  317. info_append('DTS-X')
  318. elif any(i in title for i in ('hd.ma', 'hdma')):
  319. info_append('DTS-HD MA')
  320. elif any(i in title for i in ('dts.hd.', 'dtshd')):
  321. info_append('DTS-HD')
  322. elif '.dts' in title:
  323. info_append('DTS')
  324. if any(i in title for i in ('ch8.', '8ch.', '7.1ch', '7.1.')):
  325. info_append('8CH')
  326. elif any(i in title for i in ('ch7.', '7ch.', '6.1ch', '6.1.')):
  327. info_append('7CH')
  328. elif any(i in title for i in ('ch6.', '6ch.', '5.1ch', '5.1.')):
  329. info_append('6CH')
  330. elif any(i in title for i in ('ch2', '2ch', '2.0ch', '2.0.', 'audio.2.0.', 'stereo')):
  331. info_append('2CH')
  332. if '.wmv' in title:
  333. info_append('WMV')
  334. elif any(i in title for i in ('.mpg', '.mp2', '.mpeg', '.mpe', '.mpv', '.mp4', '.m4p', '.m4v', 'msmpeg', 'mpegurl')):
  335. info_append('MPEG')
  336. elif '.avi' in title:
  337. info_append('AVI')
  338. elif any(i in title for i in ('.mkv', 'matroska')):
  339. info_append('MKV')
  340. if any(i in title for i in ('hindi.eng', 'ara.eng', 'ces.eng', 'chi.eng', 'cze.eng', 'dan.eng', 'dut.eng', 'ell.eng', 'esl.eng', 'esp.eng', 'fin.eng', 'fra.eng', 'fre.eng',
  341. 'frn.eng', 'gai.eng', 'ger.eng', 'gle.eng', 'gre.eng', 'gtm.eng', 'heb.eng', 'hin.eng', 'hun.eng', 'ind.eng', 'iri.eng', 'ita.eng', 'jap.eng', 'jpn.eng', 'kor.eng',
  342. 'lat.eng', 'lebb.eng', 'lit.eng', 'nor.eng', 'pol.eng', 'por.eng', 'rus.eng', 'som.eng', 'spa.eng', 'sve.eng', 'swe.eng', 'tha.eng', 'tur.eng', 'uae.eng', 'ukr.eng',
  343. 'vie.eng', 'zho.eng', 'dual.audio', 'multi')):
  344. info_append('MULTI-LANG')
  345. if any(i in title for i in ('1xbet', 'betwin')):
  346. info_append('ADS')
  347. if any(i in title for i in ('subita', 'subfrench', 'subspanish', 'subtitula', 'swesub', 'nl.subs', 'subbed')):
  348. info_append('SUBS')
  349. return ' | '.join(filter(None, info))
  350.  
  351. def get_cache_expiry(media_type, meta, season):
  352. try:
  353. current_date = get_datetime()
  354. if media_type == 'movie':
  355. premiered = jsondate_to_datetime(meta['premiered'], '%Y-%m-%d', remove_time=True)
  356. difference = subtract_dates(current_date, premiered)
  357. if difference == 0: single_expiry = 3
  358. elif difference <= 7: single_expiry = 24
  359. elif difference <= 14: single_expiry = 48
  360. elif difference <= 21: single_expiry = 72
  361. elif difference <= 30: single_expiry = 96
  362. elif difference <= 60: single_expiry = 168
  363. else: single_expiry = 336
  364. season_expiry, show_expiry = 0, 0
  365. else:
  366. recently_ended = False
  367. extra_info = meta['extra_info']
  368. ended = extra_info['status'] in ('Ended', 'Canceled')
  369. premiered = adjust_premiered_date(meta['premiered'], date_offset())[0]
  370. difference = subtract_dates(current_date, premiered)
  371. last_episode_to_air = jsondate_to_datetime(extra_info['last_episode_to_air']['air_date'], '%Y-%m-%d', remove_time=True)
  372. last_ep_difference = subtract_dates(current_date, last_episode_to_air)
  373. if ended and last_ep_difference <= 14: recently_ended = True
  374. if not ended or recently_ended:
  375. if difference == 0: single_expiry = 3
  376. elif difference <= 3: single_expiry = 24
  377. elif difference <= 7: single_expiry = 72
  378. else: single_expiry = 168
  379. if meta['total_seasons'] == season:
  380. if last_ep_difference <= 7: season_expiry = 72
  381. else: season_expiry = 240
  382. else: season_expiry = 720
  383. show_expiry = 240
  384. else: single_expiry, season_expiry, show_expiry = 240, 720, 720
  385. except: single_expiry, season_expiry, show_expiry = 72, 72, 240
  386. return single_expiry, season_expiry, show_expiry
  387.  
Add Comment
Please, Sign In to add comment