-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscan.py
49 lines (40 loc) · 1.82 KB
/
scan.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
47
48
49
from googleDriveService import getChanges
from emby import submitMediaUpdate
import time
import json
import db
def main():
scanIntervalMinutes = 5
with open('config.json', 'r', encoding='utf-8') as jsonConfig:
startTime = time.time()
configFile = json.load(jsonConfig)
drivesConfig = configFile['drives']
generalConfig = configFile['general']
embyConfig = configFile['emby']
for driveConfig in drivesConfig:
drive = db.getDrive(driveConfig['driveId'])
print(f'Starting scan for: {drive.driveId}')
currentPageToken = drive.nextPageToken
if driveConfig['currentPageToken']:
currentPageToken = driveConfig['currentPageToken']
embyUpdates, nextPageToken, error = getChanges(driveConfig, currentPageToken, generalConfig['headless'])
if error:
print('There was an issue with the google api... will try same change set again')
else:
if embyUpdates:
success = submitMediaUpdate(embyConfig, embyUpdates)
if success:
db.saveDriveInfo(drive.driveId, nextPageToken)
print (f'Updated nextPageToken to {nextPageToken}')
else:
print('There was an issue with emby... will try same change set again')
endTime = time.time()
totalSecs = int(endTime - startTime)
print(f'Finished scanning for: {drive.driveId}. Took {totalSecs}secs')
scanIntervalMinutes = generalConfig['scanIntervalMinutes']
timeToSleep = scanIntervalMinutes * 60
print(f'Waiting {scanIntervalMinutes} minutes before next scan')
time.sleep(timeToSleep)
if __name__ == '__main__':
while True:
main()