OSDN Git Service

fix encode.
[rec10/rec10-git.git] / rec10 / trunk / src / checker.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
5 import os
6 import os.path
7 import time
8 import recdblist
9
10 def checkB25Decode(b25filepath, decodedfilepath , csch):
11     ret = 0
12     if os.path.isfile(decodedfilepath):##tsファイルが存在している
13         dtime = time.time()-os.path.getmtime(decodedfilepath)
14         dtime = int(dtime)
15         if dtime > 20:
16             if csch>0:
17                 if (compareFilesize(b25filepath, decodedfilepath, 10) and minimizeCheck(decodedfilepath, 800)):
18                     ret = 1
19             else:
20                 if (compareFilesize(b25filepath, decodedfilepath, 80) and minimizeCheck(decodedfilepath, 800)):
21                     ret = 1
22         else:
23             time.sleep(30)
24             dtime = time.time()-os.path.getmtime(decodedfilepath)
25             dtime = int(dtime)
26             if dtime > 20:
27                 if csch>0:
28                     if (compareFilesize(b25filepath, decodedfilepath, 10) and minimizeCheck(decodedfilepath, 800)):
29                         ret = 1
30                 else:
31                     if (compareFilesize(b25filepath, decodedfilepath, 90) and minimizeCheck(decodedfilepath, 800)):
32                         ret = 1
33     #recdblist.printutf8("deleting b25 is " + str(ret))
34     return ret
35 def compareFilesize(pathbase, path, percentage):
36     """
37     return true if size of path is larger than that of pathbase.
38     percentage is int(0< <100)
39     """
40     if not os.path.exists(pathbase):
41         return 0
42     basesize = os.path.getsize(pathbase)
43     pathsize = os.path.getsize(path)
44     size = pathsize * 100-basesize * percentage
45     if size < 0:
46         return 0
47     else:
48         return 1
49 def minimizeCheck(filepath, minsize):
50     """
51     minsize is Megabytes
52     """
53     if os.path.getsize(filepath) > minsize * 1000 * 1000:
54         return 1
55     else:
56         return 0