MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / extract_custom_properties

Function extract_custom_properties

apps/epg/tasks.py:4089–4312  ·  view source on GitHub ↗
(prog)

Source from the content-addressed store, hash-verified

4087
4088# Helper function to extract custom properties - moved to a separate function to clean up the code
4089def extract_custom_properties(prog):
4090 # Create a new dictionary for each call
4091 custom_props = {}
4092
4093 # Extract categories with a single comprehension to reduce intermediate objects
4094 categories = [cat.text.strip() for cat in prog.findall('category') if cat.text and cat.text.strip()]
4095 if categories:
4096 custom_props['categories'] = categories
4097
4098 # Extract keywords (new)
4099 keywords = [kw.text.strip() for kw in prog.findall('keyword') if kw.text and kw.text.strip()]
4100 if keywords:
4101 custom_props['keywords'] = keywords
4102
4103 # Extract episode numbers
4104 for ep_num in prog.findall('episode-num'):
4105 system = ep_num.get('system', '')
4106 if system == 'xmltv_ns' and ep_num.text:
4107 # Parse XMLTV episode-num format (season.episode.part)
4108 parts = ep_num.text.split('.')
4109 if len(parts) >= 2:
4110 if parts[0].strip() != '':
4111 try:
4112 season = int(parts[0]) + 1 # XMLTV format is zero-based
4113 custom_props['season'] = season
4114 except ValueError:
4115 pass
4116 if parts[1].strip() != '':
4117 try:
4118 episode = int(parts[1]) + 1 # XMLTV format is zero-based
4119 custom_props['episode'] = episode
4120 except ValueError:
4121 pass
4122 elif system == 'onscreen' and ep_num.text:
4123 onscreen_text = ep_num.text.strip()
4124 custom_props['onscreen_episode'] = onscreen_text
4125 # Extract season/episode from onscreen format if not already set by xmltv_ns
4126 if 'season' not in custom_props or 'episode' not in custom_props:
4127 match = _ONSCREEN_RE.search(onscreen_text)
4128 if match:
4129 if 'season' not in custom_props:
4130 custom_props['season'] = int(match.group(1))
4131 if 'episode' not in custom_props:
4132 custom_props['episode'] = int(match.group(2))
4133 elif system == 'dd_progid' and ep_num.text:
4134 # Store the dd_progid format
4135 custom_props['dd_progid'] = ep_num.text.strip()
4136 # Add support for other systems like thetvdb.com, themoviedb.org, imdb.com
4137 elif system in ['thetvdb.com', 'themoviedb.org', 'imdb.com'] and ep_num.text:
4138 custom_props[f'{system}_id'] = ep_num.text.strip()
4139
4140 # Extract ratings more efficiently
4141 rating_elem = prog.find('rating')
4142 if rating_elem is not None:
4143 value_elem = rating_elem.find('value')
4144 if value_elem is not None and value_elem.text:
4145 custom_props['rating'] = value_elem.text.strip()
4146 if rating_elem.get('system'):

Callers 2

Calls 2

searchMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected