Skip to content

Commit

Permalink
#567 ical: Using DTSTART/DTEND to calculate date/duration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfro committed Jan 17, 2018
1 parent 60146c3 commit ac7083f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
29 changes: 1 addition & 28 deletions galicaster/mediapackage/mediapackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,22 +1450,7 @@ def marshalDublincore(self):
continue
EPISODE_TERMS.append(node.nodeName.split(':')[1])
for name in EPISODE_TERMS:
if name in ["created"]:
creat = _checknget(dom, "dcterms:" + name)
if creat:
if creat[-1] == "Z":
try:
self.setDate(datetime.strptime(creat, "%Y-%m-%dT%H:%M:%SZ"))
except:
self.setDate(datetime.strptime(creat, "%Y-%m-%d %H:%M:%SZ"))
else:
try:
self.setDate(datetime.strptime(creat, "%Y-%m-%dT%H:%M:%S"))
except:
self.setDate(datetime.strptime(creat, "%Y-%m-%d %H:%M:%S"))

# parse erroneous format too
elif name in ['creator']:
if name in ['creator']:
self.setCreator(_checknget(dom, "dcterms:"+name))
elif name in ['isPartOf', 'ispartof']:
new = _checknget(dom, "dcterms:"+name)
Expand All @@ -1484,18 +1469,6 @@ def marshalDublincore(self):
for name in SERIES_TERMS:
self.metadata_series[name] = _checknget(dom, "dcterms:" + name)

# Parse temporal metadatum
if self.metadata_episode.has_key('temporal') and self.metadata_episode['temporal'] and not self.hasTracks():
try:
g = re.search('start=(.*); end=(.*); ', self.metadata_episode['temporal'])
start = parser.parse(g.group(1)).astimezone(tz.tzutc()).replace(tzinfo=None)
stop = parser.parse(g.group(2)).astimezone(tz.tzutc()).replace(tzinfo=None)
diff = stop - start
self.setDuration(diff.seconds*1000)
self.setDate(start)
except:
pass

#FIXME merge with add
def addAttachmentAsString(self, content, name=None, identifier=None):
"""Adds the information of an attachment in a file.
Expand Down
2 changes: 2 additions & 0 deletions galicaster/utils/ical.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def create_mp(repo, event):

mp.setTitle(event['SUMMARY'])
mp.setDate(event['DTSTART'].dt.replace(tzinfo=None))
diff = event['DTEND'].dt.replace(tzinfo=None) - event['DTSTART'].dt.replace(tzinfo=None)
mp.setDuration(diff.seconds*1000)

catalog= mp.getCatalogs("dublincore/series")
if catalog:
Expand Down

0 comments on commit ac7083f

Please sign in to comment.