fix diffusion not found

This commit is contained in:
bkfox 2022-01-19 14:28:15 +01:00
parent e28fe56aca
commit 69a65379c3
2 changed files with 14 additions and 6 deletions

View File

@ -80,6 +80,7 @@ class SoundFile:
program = kwargs['program'] = Program.get_from_path(self.path) program = kwargs['program'] = Program.get_from_path(self.path)
sound, created = Sound.objects.get_or_create(path=self.path, defaults=kwargs) \ sound, created = Sound.objects.get_or_create(path=self.path, defaults=kwargs) \
if not sound else (sound, False) if not sound else (sound, False)
self.sound = sound
sound.program = program sound.program = program
if created or sound.check_on_file(): if created or sound.check_on_file():
@ -95,7 +96,6 @@ class SoundFile:
if sound.episode is None and self.read_path(): if sound.episode is None and self.read_path():
self.find_episode(program) self.find_episode(program)
self.sound = sound
sound.save() sound.save()
if self.info is not None: if self.info is not None:
self.find_playlist(sound) self.find_playlist(sound)
@ -112,7 +112,11 @@ class SoundFile:
name = os.path.splitext(os.path.basename(self.path))[0] name = os.path.splitext(os.path.basename(self.path))[0]
match = sound_path_re.search(name) match = sound_path_re.search(name)
if match: if match:
self.path_info = match.groupdict() path_info = match.groupdict()
for k in ('year', 'month', 'day', 'hour', 'minute'):
if path_info.get(k) is not None:
path_info[k] = int(path_info[k])
self.path_info = path_info
return True return True
else: else:
self.path_info = {'name': name} self.path_info = {'name': name}
@ -135,17 +139,19 @@ class SoundFile:
rerun. rerun.
""" """
pi = self.path_info pi = self.path_info
print('find episode', pi, self.sound, self.sound and self.sound.episode)
if 'year' not in pi or not self.sound or self.sound.episode: if 'year' not in pi or not self.sound or self.sound.episode:
return None return None
if 'hour' not in pi: if pi.get('hour') is not None:
date = datetime.date(pi.get('year'), pi.get('month'), pi.get('day'))
else:
date = tz.datetime(pi.get('year'), pi.get('month'), pi.get('day'), date = tz.datetime(pi.get('year'), pi.get('month'), pi.get('day'),
pi.get('hour') or 0, pi.get('minute') or 0) pi.get('hour') or 0, pi.get('minute') or 0)
date = tz.get_current_timezone().localize(date) date = tz.get_current_timezone().localize(date)
else:
date = datetime.date(pi.get('year'), pi.get('month'), pi.get('day'))
diffusion = program.diffusion_set.initial().at(date).first() diffusion = program.diffusion_set.at(date).first()
print('related diffusion', date, diffusion)
if not diffusion: if not diffusion:
return None return None

View File

@ -95,6 +95,8 @@ class DiffusionQuerySet(BaseRerunQuerySet):
date = date or datetime.date.today() date = date or datetime.date.today()
start = tz.datetime.combine(date, datetime.time()) start = tz.datetime.combine(date, datetime.time())
end = tz.datetime.combine(date, datetime.time(23, 59, 59, 999)) end = tz.datetime.combine(date, datetime.time(23, 59, 59, 999))
# start = tz.get_current_timezone().localize(start)
# end = tz.get_current_timezone().localize(end)
qs = self.filter(start__range = (start, end)) qs = self.filter(start__range = (start, end))
return qs.order_by('start') if order else qs return qs.order_by('start') if order else qs