Skip to content

Commit eec8cc9

Browse files
committed
video stuff
1 parent 18c2cb0 commit eec8cc9

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

tasks.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import structlog
1010

1111
from src import bsky, cache
12-
from src import worker
12+
13+
# from src import worker
1314

1415
dotenv.load_dotenv()
1516
bsky_instance = bsky.Bsky()
@@ -104,15 +105,27 @@ def bsky_emoji_summary(ctx: invoke.Context, handle: str, num_keywords: int = 25,
104105

105106

106107
@invoke.task
107-
def stream_video(path: str, chunk_size: int = 25 * 1024):
108+
def stream_video(ctx: invoke.Context, path: str, chunk_size: int = 1):
109+
chunk_size = chunk_size * 1024 # Convert KB
110+
print(f"Streaming video from {path} with chunk size {chunk_size}")
111+
108112
with open(path, "rb") as f:
109-
size = f.__sizeof__()
113+
print(f"Reading file {path}")
114+
# Get actual file size
115+
f.seek(0, 2) # Seek to end
116+
size = f.tell() # Get position (file size)
117+
f.seek(0) # Seek back to start
110118
read_size = 0
111119

112120
while True:
121+
progress = (read_size / size * 100) if size > 0 else 0
122+
print(f"Progress: {progress:.2f}%")
113123
chunk = f.read(chunk_size)
114124
if not chunk:
115125
break
116-
yield chunk
117-
read_size += chunk_size
118-
print(f"{read_size / size * 100}%")
126+
# Write chunk to stdout
127+
sys.stdout.buffer.write(chunk)
128+
sys.stdout.flush()
129+
read_size += len(chunk)
130+
131+
print("\nDone")

0 commit comments

Comments
 (0)