Ejemplo n.º 1
0
 def create_audio(self, user, name="foobar"):
     from django.core.files.uploadedfile import SimpleUploadedFile
     audio_file = SimpleUploadedFile(u'áudio.mp3', 'foobarbaz')
     audio = Audio(user=user, audio=audio_file, name=name)
     audio.save()
     return audio
Ejemplo n.º 2
0
#for x in r1:
#	record = Book(id = int(x[0]), title = x[1].rstrip(), author = x[2].rstrip())
#	record.save()

#for x in r2:
#	try:
#		book = Book.objects.get(id=int(x[3]))
#		minutes = x[2]
#		seconds = int(minutes.split('.')[0])*60 + int(minutes.split('.')[1]) #convert minutes to seconds
#		record = Chapter(id = int(x[0]), length = seconds, book_id = book, title = x[4])
#		record.save()
#	except Book.DoesNotExist:
#		continue

for x in r3:

    try:
        chapter = Chapter.objects.get(pk=int(x[1]))
        record = Audio(id=int(x[5]),
                       chapter_order=int(x[0]),
                       chapter_id=chapter,
                       name=x[2],
                       audio_file=x[3].rstrip(),
                       length=int(x[4]),
                       text=x[6].rstrip())
        record.save()
        print("record saved")
    except Chapter.DoesNotExist:
        print("chapter ID : {}.".format(x[1]))
        print("in populate.py {}".format(x))
import get_fields
from audio.models import Audio, Chapter, Transcription

r1 = get_fields.audio_fields()
r2 = get_fields.chapter_fields()
r3 = get_fields.transcription_fields()

for x in r1:
    record = Audio(chapter_order=int(x[0]),
                   chapter_id=int(x[1]),
                   name=x[2],
                   length=int(x[4]),
                   path=x[5])
    record.save()

#for x in r2:
#	record = Chapter(id = int(x[0]), minutes = int(x[1]), title = x[2], book_title = x[3])
#	record.save()
for x in r3:
    record = Transcription(chapter_id=int(x[0]), name=x[1])
    record.save()
Ejemplo n.º 4
0

class AudioSerializer(serializers.ModelSerializer):
    class Meta:
        model = Audio
        fields = '__all__'


class AudioSliceSerializer(serializers.ModelSerializer):
    class Meta:
        model = AudioSlice
        fields = '__all__'


# class UploadSerializer(serializers.Serializer):
#     audio_file = serializers.FileField()
#     ext = serializers.CharField(max_length=5)

# def __init__(self, audio_file, extension):
#     self.audio_file = audio_file
#     self.ext = extension

if __name__ == '__main__':
    aud = Audio(audio_id="GNGbmg_pVlQ",
                title='Selena Gomez - Back to You (Lyrics)',
                duration=207.06,
                download_url="http://www.youtube.com/watch?v=GNGbmg_pVlQ")
    aud.save()
    result = AudioSerializer(aud).data
    print(result)
Ejemplo n.º 5
0
 def create_audio(self, user, name="foobar"):
     audio_file = get_test_audiofile()
     audio = Audio(user=user, audio=audio_file, name=name)
     audio.save()
     return audio