-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_content.py
48 lines (33 loc) · 1.03 KB
/
gen_content.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
import sys
import redis
import random
import shutil
content_num = 100
source_path = "/home/guanyu/Public/me/static/lvjuren"
source_id = "lvjuren"
source_start = 1 * 6
source_end = 10 * 6
dest_path = "/tmp"
r = redis.StrictRedis(host='localhost', port=6379, db=0)
r.set("content_num", content_num)
for content in range(0, content_num):
content = str(content)
new_dir = os.path.join(dest_path, content)
if os.path.exists(new_dir):
shutil.rmtree(new_dir)
os.makedirs(new_dir)
seg_num = random.randint(source_start, source_end)
print "new content id:", content
print "segment number:", seg_num
print "------------------------"
key = "content_" + str(content)
val = seg_num
r.set(key, val)
for seg in range(seg_num):
seg = str(seg)
new_seg = content + "_" + seg + ".ts"
new_seg = os.path.join(new_dir, new_seg)
old_seg = source_id + "_" + seg + ".ts"
old_seg = os.path.join(source_path, old_seg)
shutil.copy2(old_seg, new_seg)