Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Оби-Ван Кеноби сезон 1 серия 4 «Часть IV» (сериал, 2022)
- # *ссылка*
- # Банды Лондона 1 сезон 1 серия (сериал, 2020)
- # *ссылка*
- # Детективное агентство Дирка Джентли 1 сезон 1 серия «Горизонты» (сериал, 2016)
- # *ссылка*
- # Детектив Вистинг 3 сезон 1 серия (сериал, 2019)
- # *ссылка*
- # Детективное агентство Дирка Джентли 2 сезон 1 серия «Кролик из космоса» (сериал, 2016)
- # *ссылка*
- # Люцифер 5 сезон 1 серия «Жалкий чёрт» (сериал, 2016-2021)
- # *ссылка*
- # Люцифер 6 сезон 1 серия «Здесь ничего никогда не меняется» (сериал, 2016-2021)
- # *ссылка*
- # Детектив Вистинг 2 сезон 1 серия (сериал, 2019)
- # *ссылка*
- import re
- from collections import defaultdict
- def extract_info(description):
- """
- Extracts the title, season, and episode from the description.
- """
- # Regular expression to extract title, season, and episode
- match = re.match(r'^([а-яА-ЯЁё\s\"\:\«\»\.\-a-zA-Z,/—*!?№]*)(?:(\d+)?\sсезон)?\s*(\d+)(?:\s*серия\s*(\d+))?', description)
- if match:
- title = match.group(1).strip()
- if match.group(4):
- season = int(match.group(3)) if match.group(3) else 0
- episode = int(match.group(4)) if match.group(3) else 0
- else:
- season = int(match.group(2)) if match.group(2) else 0
- episode = int(match.group(3)) if match.group(3) else 0
- else:
- title = description.strip()
- season = 0
- episode = 0
- return (title, season, episode)
- def process_file(filename):
- """
- Processes the file to extract and group episode information.
- """
- grouped_episodes = defaultdict(list)
- with open(filename, 'r', encoding='utf-8') as file:
- lines = file.readlines()
- # Process lines in pairs
- for i in range(0, len(lines), 2):
- description = lines[i].strip()
- # Remove #EXTINF:-1,4400 if present
- clean_description = re.sub(r'#EXTINF:-1,', '', description).strip()
- link = lines[i + 1].strip() if i + 1 < len(lines) else ""
- title, season, episode = extract_info(clean_description)
- # Add to the appropriate group
- grouped_episodes[title].append((season, episode, clean_description, link))
- return grouped_episodes
- def print_grouped_episodes(grouped_episodes):
- """
- Prints the grouped and sorted episodes.
- """
- for title, episodes in grouped_episodes.items():
- print(f"Series: {title}")
- # Sort episodes by season and episode
- for season, episode, desc, link in sorted(episodes, key=lambda x: (x[0], x[1])):
- print(f" {desc}\n {link}")
- print()
- def write_grouped_episodes_to_file(grouped_episodes, output_filename):
- """
- Writes the grouped and sorted episodes to a file.
- """
- with open(output_filename, 'w', encoding='utf-8') as file:
- for title, episodes in grouped_episodes.items():
- file.write(f"Series: {title}\n")
- # Sort episodes by season and episode
- for season, episode, desc, link in sorted(episodes, key=lambda x: (x[0], x[1])):
- file.write(f" {desc}\n {link}\n")
- file.write("\n")
- # Usage example
- filename = 'H:\\test.txt'
- output_filename = 'H:\\sorted_episodes.txt'
- grouped_episodes = process_file(filename)
- write_grouped_episodes_to_file(grouped_episodes, output_filename)
- #print_grouped_episodes(grouped_episodes)
Add Comment
Please, Sign In to add comment