vericudebuget commited on
Commit
7d7426a
·
verified ·
1 Parent(s): 2e469cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -38,7 +38,15 @@ def save_custom_thumbnail(thumbnail_file, thumbnail_path):
38
  img.save(thumbnail_path)
39
  return True
40
 
41
- def generate_metadata(video_name, title, description, uploader, file_location, thumbnail_location):
 
 
 
 
 
 
 
 
42
  return {
43
  "fileName": video_name,
44
  "title": title,
@@ -47,6 +55,7 @@ def generate_metadata(video_name, title, description, uploader, file_location, t
47
  "uploadTimestamp": datetime.now().isoformat(),
48
  "fileLocation": file_location,
49
  "thumbnailLocation": thumbnail_location,
 
50
  "views": 0,
51
  "likes": 0
52
  }
@@ -129,6 +138,9 @@ def upload_video_to_hf(video_file, original_video_name, title, description, uplo
129
  st.error("Failed to process thumbnail")
130
  return None
131
 
 
 
 
132
  # Upload the video
133
  video_location = f"videos/{video_name}"
134
  api.upload_file(
@@ -148,7 +160,7 @@ def upload_video_to_hf(video_file, original_video_name, title, description, uplo
148
  )
149
 
150
  # Generate and upload metadata JSON
151
- metadata = generate_metadata(video_name, title, description, uploader, video_location, thumbnail_location)
152
  with open(json_path, "w") as f:
153
  json.dump(metadata, f, indent=2)
154
 
@@ -208,4 +220,4 @@ if uploaded_video:
208
  st.success("Upload completed successfully!")
209
  st.json(metadata)
210
  else:
211
- st.info("Please upload a video file to begin.")
 
38
  img.save(thumbnail_path)
39
  return True
40
 
41
+ def get_video_length(video_path):
42
+ video = cv2.VideoCapture(video_path)
43
+ fps = video.get(cv2.CAP_PROP_FPS) # Frames per second
44
+ total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT)) # Total frames in the video
45
+ duration = total_frames / fps if fps > 0 else 0 # Duration in seconds
46
+ video.release()
47
+ return duration
48
+
49
+ def generate_metadata(video_name, title, description, uploader, file_location, thumbnail_location, duration):
50
  return {
51
  "fileName": video_name,
52
  "title": title,
 
55
  "uploadTimestamp": datetime.now().isoformat(),
56
  "fileLocation": file_location,
57
  "thumbnailLocation": thumbnail_location,
58
+ "duration": duration, # Add duration here
59
  "views": 0,
60
  "likes": 0
61
  }
 
138
  st.error("Failed to process thumbnail")
139
  return None
140
 
141
+ # Get video length
142
+ video_length = get_video_length(video_path)
143
+
144
  # Upload the video
145
  video_location = f"videos/{video_name}"
146
  api.upload_file(
 
160
  )
161
 
162
  # Generate and upload metadata JSON
163
+ metadata = generate_metadata(video_name, title, description, uploader, video_location, thumbnail_location, video_length)
164
  with open(json_path, "w") as f:
165
  json.dump(metadata, f, indent=2)
166
 
 
220
  st.success("Upload completed successfully!")
221
  st.json(metadata)
222
  else:
223
+ st.info("Please upload a video file to begin.")