Ao3 Mirror -

def _is_mirrored(self, work_id: str) -> bool: """Check if work is already mirrored""" return (self.work_dir / work_id / "metadata.json").exists()

return jsonify(result) @app.route('/api/library', methods=['GET']) def get_library(): works = [] work_dir = mirror.work_dir ao3 mirror

async def mirror_work(self, work_url: str, format: str = "html") -> Dict: """Mirror a single work from AO3""" work_id = self._extract_work_id(work_url) # Check if already mirrored if self._is_mirrored(work_id): return {"status": "exists", "work_id": work_id} # Fetch work data work_data = await self._fetch_work(work_url) # Save metadata self._save_metadata(work_id, work_data['metadata']) # Save content self._save_content(work_id, work_data['content'], format) return {"status": "success", "work_id": work_id} def _is_mirrored(self, work_id: str) -> bool: """Check if

def _extract_work_id(self, url: str) -> str: """Extract work ID from AO3 URL""" import re match = re.search(r'/works/(\d+)', url) if match: return match.group(1) raise ValueError("Invalid AO3 work URL") work_id: str) -&gt

for work_path in work_dir.iterdir(): if work_path.is_dir(): metadata_file = work_path / 'metadata.json' if metadata_file.exists(): with open(metadata_file, 'r', encoding='utf-8') as f: metadata = json.load(f) works.append({ 'work_id': metadata['work_id'], 'title': metadata['title'], 'author': metadata['author'], 'word_count': metadata['word_count'], 'chapters': metadata['chapters'], 'kudos': metadata['kudos'] })

Top