mfarre HF staff commited on
Commit
0a5b574
·
1 Parent(s): e05c441
Files changed (1) hide show
  1. app.py +26 -7
app.py CHANGED
@@ -156,7 +156,16 @@ class VideoHighlightDetector:
156
 
157
  def create_xspf_playlist(video_path: str, segments: list, descriptions: list) -> str:
158
  """Create XSPF playlist from segments with descriptions."""
159
- root = ET.Element("playlist", version="1", xmlns="http://xspf.org/ns/0/")
 
 
 
 
 
 
 
 
 
160
 
161
  # Get video filename for the title
162
  video_filename = os.path.basename(video_path)
@@ -172,24 +181,34 @@ def create_xspf_playlist(video_path: str, segments: list, descriptions: list) ->
172
  location.text = f"file:///{video_filename}"
173
 
174
  title = ET.SubElement(track, "title")
175
- title.text = f"Highlight {idx + 1}"
176
 
177
  annotation = ET.SubElement(track, "annotation")
178
  annotation.text = description
179
 
180
- start_meta = ET.SubElement(track, "meta", rel="start")
 
181
  start_meta.text = format_duration(start_time)
182
 
183
- end_meta = ET.SubElement(track, "meta", rel="end")
 
184
  end_meta.text = format_duration(end_time)
185
 
186
  # Add VLC extension
187
- extension = ET.SubElement(root, "extension", application="http://www.videolan.org/vlc/playlist/0")
 
 
188
  for i in range(len(segments)):
189
- item = ET.SubElement(extension, "vlc:item", tid=str(i))
 
190
 
191
  # Convert to string with pretty printing
192
- xml_str = minidom.parseString(ET.tostring(root)).toprettyxml(indent=" ")
 
 
 
 
 
193
  return xml_str
194
 
195
  def create_ui(examples_path: str, model_path: str):
 
156
 
157
  def create_xspf_playlist(video_path: str, segments: list, descriptions: list) -> str:
158
  """Create XSPF playlist from segments with descriptions."""
159
+ # Define namespaces
160
+ XSPF_NS = "http://xspf.org/ns/0/"
161
+ VLC_NS = "http://www.videolan.org/vlc/playlist/ns/0/"
162
+
163
+ # Create the root element with proper namespace
164
+ root = ET.Element("playlist", {
165
+ "xmlns": XSPF_NS,
166
+ "xmlns:vlc": VLC_NS,
167
+ "version": "1"
168
+ })
169
 
170
  # Get video filename for the title
171
  video_filename = os.path.basename(video_path)
 
181
  location.text = f"file:///{video_filename}"
182
 
183
  title = ET.SubElement(track, "title")
184
+ title.text = f"Highlight {idx + 1}: {description}"
185
 
186
  annotation = ET.SubElement(track, "annotation")
187
  annotation.text = description
188
 
189
+ start_meta = ET.SubElement(track, "meta")
190
+ start_meta.set("rel", "start")
191
  start_meta.text = format_duration(start_time)
192
 
193
+ end_meta = ET.SubElement(track, "meta")
194
+ end_meta.set("rel", "end")
195
  end_meta.text = format_duration(end_time)
196
 
197
  # Add VLC extension
198
+ extension = ET.SubElement(root, "extension")
199
+ extension.set("application", "http://www.videolan.org/vlc/playlist/0")
200
+
201
  for i in range(len(segments)):
202
+ item = ET.SubElement(extension, "{%s}item" % VLC_NS)
203
+ item.set("tid", str(i))
204
 
205
  # Convert to string with pretty printing
206
+ xml_str = minidom.parseString(ET.tostring(root, encoding='unicode')).toprettyxml(indent=" ")
207
+
208
+ # Clean up any potential namespace declaration issues
209
+ xml_str = xml_str.replace('xmlns:ns0="http://www.videolan.org/vlc/playlist/ns/0/"', '')
210
+ xml_str = xml_str.replace('ns0:', 'vlc:')
211
+
212
  return xml_str
213
 
214
  def create_ui(examples_path: str, model_path: str):