christopi commited on
Commit
dcaf503
·
1 Parent(s): 56b6fde

add videos dir checking

Browse files
neurons/validator.py CHANGED
@@ -118,7 +118,7 @@ class Validator(base.BaseValidator):
118
 
119
  # Step 1: Send TaskWarrantProtocol requests to determine miner capabilities
120
  logger.info(f"Sending TaskWarrantProtocol requests to {len(axons)} miners")
121
- logger.info(f"Axons: {axons}")
122
  version = get_version()
123
  task_warrant_synapse = TaskWarrantProtocol(version=version)
124
 
 
118
 
119
  # Step 1: Send TaskWarrantProtocol requests to determine miner capabilities
120
  logger.info(f"Sending TaskWarrantProtocol requests to {len(axons)} miners")
121
+
122
  version = get_version()
123
  task_warrant_synapse = TaskWarrantProtocol(version=version)
124
 
check_queues.py → scripts/check_queues.py RENAMED
File without changes
scripts/get_video_lengths.py ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Video Length Scanner Script
4
+
5
+ This script scans the /videos directory and prints a list of all video files
6
+ along with their durations in a readable format.
7
+ """
8
+
9
+ import os
10
+ import subprocess
11
+ import sys
12
+ from pathlib import Path
13
+ from typing import List, Tuple, Optional
14
+
15
+ def get_video_duration(file_path: str) -> Optional[float]:
16
+ """
17
+ Get the duration of a video file using ffprobe.
18
+
19
+ Args:
20
+ file_path: Path to the video file
21
+
22
+ Returns:
23
+ Duration in seconds, or None if ffprobe fails
24
+ """
25
+ try:
26
+ # Use ffprobe to get video duration
27
+ cmd = [
28
+ 'ffprobe',
29
+ '-v', 'quiet',
30
+ '-show_entries', 'format=duration',
31
+ '-of', 'csv=p=0',
32
+ file_path
33
+ ]
34
+
35
+ result = subprocess.run(cmd, capture_output=True, text=True, check=True)
36
+ duration = float(result.stdout.strip())
37
+ return duration
38
+ except (subprocess.CalledProcessError, ValueError, FileNotFoundError):
39
+ return None
40
+
41
+ def format_duration(seconds: float) -> str:
42
+ """
43
+ Format duration in seconds to a human-readable string.
44
+
45
+ Args:
46
+ seconds: Duration in seconds
47
+
48
+ Returns:
49
+ Formatted duration string (e.g., "1:23.45")
50
+ """
51
+ if seconds < 0:
52
+ return "Invalid"
53
+
54
+ minutes = int(seconds // 60)
55
+ remaining_seconds = seconds % 60
56
+
57
+ if minutes == 0:
58
+ return f"{remaining_seconds:.2f}s"
59
+ else:
60
+ return f"{minutes}:{remaining_seconds:05.2f}"
61
+
62
+ def categorize_duration(seconds: float) -> str:
63
+ """
64
+ Categorize duration into chunks (e.g., 10s, 20s, 30s).
65
+ Videos within ±0.5 seconds of a whole number are grouped together.
66
+
67
+ Args:
68
+ seconds: Duration in seconds
69
+
70
+ Returns:
71
+ Category string (e.g., "10s", "20s", "1m", "2m")
72
+ """
73
+ if seconds < 0:
74
+ return "Invalid"
75
+
76
+ # Round to nearest second for categorization
77
+ rounded_seconds = round(seconds)
78
+
79
+ if rounded_seconds < 60:
80
+ return f"{rounded_seconds}s"
81
+ else:
82
+ minutes = rounded_seconds // 60
83
+ remaining_seconds = rounded_seconds % 60
84
+ if remaining_seconds == 0:
85
+ return f"{minutes}m"
86
+ else:
87
+ return f"{minutes}m{remaining_seconds}s"
88
+
89
+ def scan_videos_directory(videos_dir: str = "videos") -> List[Tuple[str, float]]:
90
+ """
91
+ Scan the videos directory and return a list of video files with their durations.
92
+
93
+ Args:
94
+ videos_dir: Path to the videos directory
95
+
96
+ Returns:
97
+ List of tuples containing (filename, duration_in_seconds)
98
+ """
99
+ video_files = []
100
+
101
+ if not os.path.exists(videos_dir):
102
+ print(f"Error: Directory '{videos_dir}' does not exist.")
103
+ return []
104
+
105
+ # Supported video extensions
106
+ video_extensions = {'.mp4', '.avi', '.mov', '.mkv', '.wmv', '.flv', '.webm', '.m4v'}
107
+
108
+ for filename in os.listdir(videos_dir):
109
+ file_path = os.path.join(videos_dir, filename)
110
+
111
+ # Check if it's a file and has a video extension
112
+ if os.path.isfile(file_path) and Path(filename).suffix.lower() in video_extensions:
113
+ duration = get_video_duration(file_path)
114
+ if duration is not None:
115
+ video_files.append((filename, duration))
116
+ else:
117
+ print(f"Warning: Could not get duration for {filename}")
118
+
119
+ return sorted(video_files, key=lambda x: x[1]) # Sort by duration
120
+
121
+ def main():
122
+ """Main function to run the video length scanner."""
123
+ print("Video Length Scanner")
124
+ print("=" * 50)
125
+
126
+ # Check if ffprobe is available
127
+ try:
128
+ subprocess.run(['ffprobe', '-version'], capture_output=True, check=True)
129
+ except (subprocess.CalledProcessError, FileNotFoundError):
130
+ print("Error: ffprobe is not installed or not in PATH.")
131
+ print("Please install FFmpeg to use this script.")
132
+ print("On Ubuntu/Debian: sudo apt install ffmpeg")
133
+ print("On CentOS/RHEL: sudo yum install ffmpeg")
134
+ print("On macOS: brew install ffmpeg")
135
+ sys.exit(1)
136
+
137
+ # Scan for videos
138
+ print("Scanning videos directory for video files...")
139
+ video_files = scan_videos_directory()
140
+
141
+ if not video_files:
142
+ print("No video files found in /videos directory.")
143
+ return
144
+
145
+ # Print results
146
+ print(f"\nFound {len(video_files)} video files:\n")
147
+ print(f"{'Filename':<50} {'Duration':<15} {'Size':<10}")
148
+ print("-" * 75)
149
+
150
+ total_duration = 0
151
+
152
+ for filename, duration in video_files:
153
+ # Get file size
154
+ file_path = os.path.join("videos", filename)
155
+ file_size = os.path.getsize(file_path)
156
+ size_mb = file_size / (1024 * 1024)
157
+
158
+ formatted_duration = format_duration(duration)
159
+ print(f"{filename:<50} {formatted_duration:<15} {size_mb:.1f}MB")
160
+ total_duration += duration
161
+
162
+ print("-" * 75)
163
+ print(f"{'Total':<50} {format_duration(total_duration):<15} {len(video_files)} files")
164
+
165
+ # Summary statistics
166
+ if video_files:
167
+ avg_duration = total_duration / len(video_files)
168
+ min_duration = min(video_files, key=lambda x: x[1])[1]
169
+ max_duration = max(video_files, key=lambda x: x[1])[1]
170
+
171
+ print(f"\nSummary Statistics:")
172
+ print(f"Average duration: {format_duration(avg_duration)}")
173
+ print(f"Shortest video: {format_duration(min_duration)}")
174
+ print(f"Longest video: {format_duration(max_duration)}")
175
+
176
+ # Duration category summary
177
+ print(f"\nDuration Categories:")
178
+ print("=" * 40)
179
+
180
+ # Group videos by duration category
181
+ duration_categories = {}
182
+ for filename, duration in video_files:
183
+ category = categorize_duration(duration)
184
+ if category not in duration_categories:
185
+ duration_categories[category] = []
186
+ duration_categories[category].append((filename, duration))
187
+
188
+ # Sort categories by duration (convert to seconds for sorting)
189
+ def category_sort_key(cat):
190
+ if 'm' in cat:
191
+ if 's' in cat:
192
+ # Format like "1m30s"
193
+ parts = cat.replace('m', ' ').replace('s', '').split()
194
+ return int(parts[0]) * 60 + int(parts[1])
195
+ else:
196
+ # Format like "2m"
197
+ return int(cat.replace('m', '')) * 60
198
+ else:
199
+ # Format like "30s"
200
+ return int(cat.replace('s', ''))
201
+
202
+ sorted_categories = sorted(duration_categories.items(), key=lambda x: category_sort_key(x[0]))
203
+
204
+ for category, videos in sorted_categories:
205
+ total_category_duration = sum(duration for _, duration in videos)
206
+ print(f"{category:<10} | {len(videos):>3} videos | Total: {format_duration(total_category_duration):<10} | Avg: {format_duration(total_category_duration/len(videos))}")
207
+
208
+ print("=" * 40)
209
+ print(f"Total categories: {len(duration_categories)}")
210
+
211
+ if __name__ == "__main__":
212
+ main()
services/video_scheduler/video_utils.py CHANGED
@@ -14,7 +14,7 @@ from pathlib import Path
14
  import concurrent.futures
15
  from dotenv import load_dotenv
16
  from typing import List, Tuple, Optional
17
- from redis_utils import pop_pexels_video_id
18
  from vidaio_subnet_core import CONFIG
19
 
20
  load_dotenv()
 
14
  import concurrent.futures
15
  from dotenv import load_dotenv
16
  from typing import List, Tuple, Optional
17
+ from services.video_scheduler.redis_utils import pop_pexels_video_id
18
  from vidaio_subnet_core import CONFIG
19
 
20
  load_dotenv()