def add_chapter(request, episode): e_state = episode.get_user_state(request.user) podcast = Podcast.get(episode.podcast) try: start = parse_time(request.POST.get('start', '0')) if request.POST.get('end', '0'): end = parse_time(request.POST.get('end', '0')) else: end = start adv = 'advertisement' in request.POST label = request.POST.get('label') except Exception as e: # FIXME: when using Django's messaging system, set error message return HttpResponseRedirect(get_episode_link_target(episode, podcast)) chapter = Chapter() chapter.start = start chapter.end = end chapter.advertisement = adv chapter.label = label e_state.update_chapters(add=[chapter]) return HttpResponseRedirect(get_episode_link_target(episode, podcast))
def parse_new_chapters(user, chapters): for c in chapters: if not 'start' in c: raise ParameterMissing('start parameter missing') start = parse_time(c['start']) if not 'end' in c: raise ParameterMissing('end parameter missing') end = parse_time(c['end']) label = c.get('label', '') adv = c.get('advertisement', False) device_uid = c.get('device', None) if device_uid: device_id = get_device(user, device_uid, request.META.get('HTTP_USER_AGENT', ''), undelete=True).id else: device_id = None chapter = Chapter() chapter.device = device_id chapter.created = timestamp chapter.start = start chapter.end = end chapter.label = label chapter.advertisement = adv yield chapter
def parse_rem_chapters(chapers): for c in chapters: if not 'start' in c: raise ParameterMissing('start parameter missing') start = parse_time(c['start']) if not 'end' in c: raise ParameterMissing('end parameter missing') end = parse_time(c['end']) yield (start, end)
def parse_rem(self, chapter_data): """ Parse a chapter to be removed """ if not 'start' in chapter_data: raise ParameterMissing('start parameter missing') start = parse_time(chapter_data['start']) if not 'end' in chapter_data: raise ParameterMissing('end parameter missing') end = parse_time(chapter_data['end']) return (start, end)
def parse_rem(self, chapter_data): """ Parse a chapter to be removed """ if not "start" in chapter_data: raise ParameterMissing("start parameter missing") start = parse_time(chapter_data["start"]) if not "end" in chapter_data: raise ParameterMissing("end parameter missing") end = parse_time(chapter_data["end"]) return (start, end)
def parse_new(self, user, chapter_data): """ Parse a chapter to be added """ chapter = Chapter() if not 'start' in chapter_data: raise ParameterMissing('start parameter missing') chapter.start = parse_time(chapter_data['start']) if not 'end' in chapter_data: raise ParameterMissing('end parameter missing') chapter.end = parse_time(chapter_data['end']) chapter.label = chapter_data.get('label', '') chapter.advertisement = chapter_data.get('advertisement', False) return chapter
def parse_new(self, user, chapter_data): """ Parse a chapter to be added """ chapter = Chapter() if not "start" in chapter_data: raise ParameterMissing("start parameter missing") chapter.start = parse_time(chapter_data["start"]) if not "end" in chapter_data: raise ParameterMissing("end parameter missing") chapter.end = parse_time(chapter_data["end"]) chapter.label = chapter_data.get("label", "") chapter.advertisement = chapter_data.get("advertisement", False) return chapter
def get_duration(entry): str = entry.get('itunes_duration', '') try: return parse_time(str) except (ValueError, TypeError): return 0