')
+ if collection_start != -1:
+ # Find the proper end of the collectionChildren section
+ # Look for the closing
that matches the opening collectionChildren div
+ # We need to count div tags to find the matching closing tag
+
+ search_pos = collection_start + len('')
+ div_count = 1 # We've opened one div
+ collection_end = -1
+
+ while search_pos < len(html_content) and div_count > 0:
+ next_open = html_content.find('
', search_pos)
+
+ if next_close == -1:
+ break
+
+ if next_open != -1 and next_open < next_close:
+ div_count += 1
+ search_pos = next_open + 4
+ else:
+ div_count -= 1
+ if div_count == 0:
+ collection_end = next_close + 6
+ break
+ search_pos = next_close + 6
+
+ if collection_end == -1:
+ collection_end = len(html_content)
+
+ collection_section = html_content[collection_start:collection_end]
+
+ # Extract IDs from sharedfile_ elements (these are the actual collection items)
+ sharedfile_ids = re.findall(r'id="sharedfile_(\d+)"', collection_section)
+ workshop_ids.extend(sharedfile_ids)
+
+ self._safe_update_output(f"Found {len(sharedfile_ids)} collection items\n")
+ else:
+ # Fallback: search the entire page but be more selective
+ self._safe_update_output("Collection section not found, using fallback method\n")
+ sharedfile_ids = re.findall(r'id="sharedfile_(\d+)"', html_content)
+ workshop_ids.extend(sharedfile_ids)
+
+ # Remove duplicates and the collection ID itself
+ unique_ids = list(set(workshop_ids))
+ if collection_id in unique_ids:
+ unique_ids.remove(collection_id)
+
+ return sorted(unique_ids) # Sort for consistent output
+
+ except requests.RequestException as e:
+ self._safe_update_output(f"Network error: {str(e)}\n")
+ return []
+ except Exception as e:
+ self._safe_update_output(f"Error fetching collection: {str(e)}\n")
+ return []
+
+ def _update_output(self, text):
+ """Update output text (called from main thread)"""
+ try:
+ self.output_text.insert(tk.END, text)
+ self.output_text.see(tk.END)
+ except Exception:
+ pass # Prevent recursion errors
+
+def main():
+ root = tk.Tk()
+ app = SteamWorkshopGUI(root)
+ root.mainloop()
+
+if __name__ == "__main__":
+ main()
\ No newline at end of file