@@ -159,8 +159,19 @@ def convert_quality_group(self, group: Dict) -> Dict:
159159 allowed_qualities = []
160160 for q_item in group .get ("qualities" , []):
161161 input_name = q_item .get ("name" , "" )
162+
163+ # First map the quality name to handle remux qualities properly
164+ mapped_name = ValueResolver .get_quality_name (
165+ input_name , self .target_app )
166+
167+ # Create a case-insensitive lookup map
162168 quality_map = {k .lower (): k for k in self .quality_mappings }
163- if input_name .lower () in quality_map :
169+
170+ # Try to find the mapped name in quality mappings
171+ if mapped_name .lower () in quality_map :
172+ allowed_qualities .append (quality_map [mapped_name .lower ()])
173+ # Fallback to the original name
174+ elif input_name .lower () in quality_map :
164175 allowed_qualities .append (quality_map [input_name .lower ()])
165176
166177 converted_group = {
@@ -218,30 +229,41 @@ def convert_profile(self, profile: Dict) -> ConvertedProfile:
218229 language = selected_language )
219230
220231 used_qualities = set ()
232+ quality_ids_in_groups = set ()
233+
234+ # First pass: Gather all quality IDs in groups to avoid duplicates
235+ for quality_entry in profile .get ("qualities" , []):
236+ if quality_entry .get ("id" , 0 ) < 0 : # It's a group
237+ # Process this group to collect quality IDs
238+ converted_group = self .convert_quality_group (quality_entry )
239+ for item in converted_group ["items" ]:
240+ if "quality" in item and "id" in item ["quality" ]:
241+ quality_ids_in_groups .add (item ["quality" ]["id" ])
221242
243+ # Second pass: Add groups and individual qualities to the profile
222244 for quality_entry in profile .get ("qualities" , []):
223- if quality_entry .get ("id" , 0 ) < 0 :
245+ if quality_entry .get ("id" , 0 ) < 0 : # It's a group
224246 converted_group = self .convert_quality_group (quality_entry )
225247 if converted_group ["items" ]:
226248 converted_profile .items .append (converted_group )
227249 for q in quality_entry .get ("qualities" , []):
228250 used_qualities .add (q .get ("name" , "" ).upper ())
229- else :
251+ else : # It's a single quality
230252 quality_name = quality_entry .get ("name" )
231253 mapped_name = ValueResolver .get_quality_name (
232254 quality_name , self .target_app )
233255 if mapped_name in self .quality_mappings :
234256 converted_profile .items .append ({
235- "quality" :
236- self .quality_mappings [mapped_name ],
257+ "quality" : self .quality_mappings [mapped_name ],
237258 "items" : [],
238- "allowed" :
239- True
259+ "allowed" : True
240260 })
241261 used_qualities .add (mapped_name .upper ())
242262
263+ # Add all unused qualities as disabled, but skip those already in groups
243264 for quality_name , quality_data in self .quality_mappings .items ():
244- if quality_name .upper () not in used_qualities :
265+ if (quality_name .upper () not in used_qualities and
266+ quality_data ["id" ] not in quality_ids_in_groups ):
245267 converted_profile .items .append ({
246268 "quality" : quality_data ,
247269 "items" : [],
0 commit comments