-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoVirtual.py
43 lines (39 loc) · 1.97 KB
/
autoVirtual.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
import requests
import json
import yaml
import os.path
from os import path
from shutil import copyfile
from datetime import date
from datetime import timedelta
from utils import getNetwork
# Modify below for debug
daysBack = 9 # Used for debug to get more episodes (should be 0)
# Used for debug to get more episodes, one is actually for current day.
daysAhead = 0
startDate = date.today() - timedelta(daysBack)
endDate = date.today() + timedelta(daysAhead)
# End of debug section
with open("config.yaml") as config:
configData = yaml.load(config, Loader=yaml.FullLoader)
url = "http://" + configData['host'] + "/api/v3/calendar/?apikey=" + configData['apiKey'] + \
"&unmonitored=true&includeSeries=true&start=" + \
startDate.strftime("%Y-%m-%d") + "&end=" + endDate.strftime("%Y-%m-%d")
jsonResponse = requests.get(url).json()
for item in jsonResponse:
network = getNetwork(item['series'], configData)
if network in configData['networks']:
showSeason = "{:02d}".format(item['seasonNumber'])
showEpisode = "{:02d}".format(item['episodeNumber'])
showTitle = (item['series']['title']).replace(':','-')
print ("Adding: " + showTitle + " " + "S" +
showSeason + "E" + showEpisode + " from " + network)
# Make directories/files as needed
if not path.exists(configData['basePath'] + "/" + showTitle):
os.mkdir(configData['basePath'] + "/" + showTitle)
if not path.exists(configData['basePath'] + "/" + showTitle + "/Season " + showSeason):
os.mkdir(configData['basePath'] + "/" +
showTitle + "/Season " + showSeason)
if not path.exists(configData['basePath'] + "/" + showTitle + "/Season " + showSeason + "/" + network + "_S" + showSeason + "E" + showEpisode + ".mp4"):
copyfile(configData['dummyFile'], configData['basePath'] + "/" + showTitle +
"/Season " + showSeason + "/" + network + "_S" + showSeason + "E" + showEpisode + ".mp4")