MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS-TTSD / parse_input_content

Function parse_input_content

podcast_generate.py:177–225  ·  view source on GitHub ↗

Parse input content, supports URL, PDF or TXT files Args: input_path (str): URL address, PDF file path or TXT file path Returns: str: Parsed text content

(input_path)

Source from the content-addressed store, hash-verified

175
176
177def parse_input_content(input_path):
178 """Parse input content, supports URL, PDF or TXT files
179
180 Args:
181 input_path (str): URL address, PDF file path or TXT file path
182
183 Returns:
184 str: Parsed text content
185 """
186 print(f"Parsing input: {input_path}")
187
188 # Check if it's a URL
189 if input_path.startswith(("http://", "https://")):
190 print("URL detected, extracting web content...")
191 result = extract_web_content(input_path)
192 if result:
193 title, content = result
194 print(f"Web title: {title}")
195 print(f"Content length: {len(content)} characters")
196 return f"{title}\n\n{content}" if title else content
197 else:
198 print("Web content extraction failed")
199 return None
200
201 # Check if it's a PDF file
202 elif input_path.lower().endswith(".pdf"):
203 print("PDF file detected, extracting content...")
204 content = extract_text_from_pdf(input_path)
205 if content:
206 print(f"PDF content length: {len(content)} characters")
207 return content
208 else:
209 print("PDF content extraction failed")
210 return None
211
212 # Check if it's a TXT file
213 elif input_path.lower().endswith(".txt"):
214 print("TXT file detected, reading content...")
215 content = extract_text_from_txt(input_path)
216 if content:
217 print(f"TXT file content length: {len(content)} characters")
218 return content
219 else:
220 print("TXT file reading failed")
221 return None
222
223 else:
224 print(f"Unsupported input format: {input_path}")
225 return None
226
227
228# =============== Dialogue Script Generation Function ===============

Callers 1

process_input_to_audioFunction · 0.85

Calls 3

extract_web_contentFunction · 0.85
extract_text_from_pdfFunction · 0.85
extract_text_from_txtFunction · 0.85

Tested by

no test coverage detected