Exemple #1
0
    def test_load_from_file(self):
        m3u8_file = SimpleUploadedFile("playlist.m3u8",
                                       str.encode(self.sample_m3u8),
                                       content_type='application/x-mpegURL')
        load_m3u8_from_file(m3u8_file, self.playlist, remove_existed=True)

        self.assertEqual(self.playlist.count, 2)
Exemple #2
0
    def form_valid(self, form):
        playlist, created = Playlist.objects.get_or_create(
            user=self.request.user)
        if form.cleaned_data['url']:
            load_remote_m3u8(
                form.cleaned_data['url'],
                playlist,
                remove_existed=form.cleaned_data['remove_existed'])
        elif form.cleaned_data['file']:
            load_m3u8_from_file(
                form.cleaned_data['file'],
                playlist,
                remove_existed=form.cleaned_data['remove_existed'])

        return super(CreatePlaylist, self).form_valid(form)
Exemple #3
0
    def form_valid(self, form):
        playlist = Playlist.objects.filter(user=self.request.user).first()
        if not playlist:
            playlist = Playlist.objects.create(user=self.request.user)

        form.instance.user = self.request.user

        if form.cleaned_data['url']:
            load_remote_m3u8(
                form.cleaned_data['url'],
                playlist,
                remove_existed=form.cleaned_data['remove_existed'])
        elif form.cleaned_data['file']:
            load_m3u8_from_file(
                form.cleaned_data['file'],
                playlist,
                remove_existed=form.cleaned_data['remove_existed'])

        return super(CreatePlaylist, self).form_valid(form)