Commit 22e81694 authored by fred's avatar fred

load-from-drupal-json: load soundfiles

parent 6500a7ef
......@@ -11,7 +11,7 @@ from django.core.management.base import BaseCommand, CommandError
from django.utils.text import slugify
from django.utils.timezone import make_naive
from ...models import Emission, Episode, Diffusion
from ...models import Emission, Episode, Diffusion, SoundFile
class Command(BaseCommand):
......@@ -79,3 +79,17 @@ class Command(BaseCommand):
diffusion = Diffusion(episode=episode)
diffusion.datetime = start_datetime
diffusion.save()
if episode_data.get('sound') and not episode.has_sound():
orig_path = 'media/sounds.orig/%s/%s' % (emission.slug, episode_data.get('sound').split('/')[-1])
if not default_storage.exists(orig_path):
response = requests.get(episode_data.get('sound'))
if response.status_code == 200:
path = default_storage.save(
'sounds.orig/%s/%s' % (
emission.slug,
episode_data.get('sound').split('/')[-1]),
ContentFile(response.content))
soundfile = SoundFile(episode=episode, podcastable=True,
fragment=False, title=episode.title)
soundfile.file = default_storage.open(path)
soundfile.save()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment