Exemplo n.º 1
0
def add_audio_old(request):
    if request.method == "GET":
        return render(request, "audio/add_audio_old.html", {
            "artists": Artist.objects.values("id", "name"),
            "genres": genres
        })
    elif request.method == "POST":
        a = Audio()
        a.title = request.POST["title"]
        a.artist_id = request.POST["artist"]
        a.genre = request.POST["genre"]
        a.save()
        return redirect(reverse("audio:audio_page", args=(a.id,)))
    else:
        return HttpResponse("405")
Exemplo n.º 2
0
 def create_audio(self, user, name="foobar"):
     audio = Audio(user=user, audio=self.TEST_FILE, name=name)
     audio.save()
     return audio
Exemplo n.º 3
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
Exemplo n.º 4
0
def add_audio(request):
	a = Audio(source_url=request.POST['source_url'], page_title=request.POST['page_title'], clip_title=request.POST['clip_title'], listened=False)
	a.save()
	return HttpResponse("Sure, that submitted.")
Exemplo n.º 5
0
#	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

with open("/home/fmk/Downloads/data/text_data1.txt", "rb") as f3:
    r3 = pickle.load(f3)
    i = 0
    for x in r3:
        try:

            chapter = Chapter.objects.get(id=int(x[1]))
            record = Audio(id=int(x[6]),
                           chapter_order=int(x[0]),
                           chapter_id=chapter,
                           name=x[2],
                           audio_file=x[3].rstrip(),
                           length=int(x[4]),
                           text=x[7].rstrip())
            record.save()
            print("in populate2.py {} record saved {}".format(i, x))
        except Chapter.DoesNotExist:
            continue
Exemplo n.º 6
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)
Exemplo n.º 7
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