def handle(self, *args, **options):
     now = time.time()
     five_minutes_ago = now - 60*2
     hotfolders = Hotfolder.objects.filter(activated=True)
     for folder in hotfolders:
         self.stdout.write('This is folder "%s"\n' % folder.folderName)
         os.chdir(settings.HOTFOLDER_BASE_DIR + folder.folderName)
         for file in os.listdir("."):
             st=os.stat(file)
             mtime=st.st_mtime
             if mtime < five_minutes_ago:
                 if file.endswith(".mov") or file.endswith(".mp4") or file.endswith(".avi") or file.endswith(".ogv") or file.endswith(".m4v") or file.endswith(".mp3") or file.endswith(".ogg"):
                     self.stdout.write('Using file %s\n' % file) 
                     video = Video(title=folder.defaultName,date=datetime.date.today(),description=folder.description,kind=folder.kind,channel=folder.channel,autoPublish=folder.autoPublish)
                     video.save()
                     shutil.copy(settings.HOTFOLDER_BASE_DIR + folder.folderName + '/' + file, settings.HOTFOLDER_MOVE_TO_DIR)
                     video.originalFile = settings.HOTFOLDER_MOVE_TO_DIR + file
                     video.save()
                     os.remove(settings.HOTFOLDER_BASE_DIR + folder.folderName + '/' + file)
                     djangotasks.register_task(video.encode_media, "Encode the files using ffmpeg")
                     encoding_task = djangotasks.task_for_object(video.encode_media)
                     djangotasks.run_task(encoding_task)
                     if settings.USE_BITTORRENT:
                         djangotasks.register_task(video.create_bittorrent, "Create Bittorrent file for video and serve via Bittorrent")
                         torrent_task = djangotasks.task_for_object(video.create_bittorrent)
                         djangotasks.run_task(torrent_task)
Example #2
0
 def handle(self, *args, **options):
     now = time.time()
     five_minutes_ago = now - 60 * 2
     hotfolders = Hotfolder.objects.filter(activated=True)
     for folder in hotfolders:
         self.stdout.write('This is folder "%s"\n' % folder.folderName)
         os.chdir(settings.HOTFOLDER_BASE_DIR + folder.folderName)
         for file in os.listdir("."):
             st = os.stat(file)
             mtime = st.st_mtime
             if mtime < five_minutes_ago:
                 if file.endswith(".mov") or file.endswith(
                         ".mp4") or file.endswith(".avi") or file.endswith(
                             ".ogv") or file.endswith(
                                 ".m4v") or file.endswith(
                                     ".mp3") or file.endswith(".ogg"):
                     self.stdout.write('Using file %s\n' % file)
                     video = Video(title=folder.defaultName,
                                   date=datetime.date.today(),
                                   description=folder.description,
                                   kind=folder.kind,
                                   channel=folder.channel,
                                   autoPublish=folder.autoPublish)
                     video.save()
                     shutil.copy(
                         settings.HOTFOLDER_BASE_DIR + folder.folderName +
                         '/' + file, settings.HOTFOLDER_MOVE_TO_DIR)
                     video.originalFile = settings.HOTFOLDER_MOVE_TO_DIR + file
                     video.save()
                     os.remove(settings.HOTFOLDER_BASE_DIR +
                               folder.folderName + '/' + file)
                     djangotasks.register_task(
                         video.encode_media,
                         "Encode the files using ffmpeg")
                     encoding_task = djangotasks.task_for_object(
                         video.encode_media)
                     djangotasks.run_task(encoding_task)
                     if settings.USE_BITTORRENT:
                         djangotasks.register_task(
                             video.create_bittorrent,
                             "Create Bittorrent file for video and serve via Bittorrent"
                         )
                         torrent_task = djangotasks.task_for_object(
                             video.create_bittorrent)
                         djangotasks.run_task(torrent_task)
Example #3
0
 def save_model(self, request, obj, form, change):
     obj.save()
     task = djangotasks.task_for_object(obj.run_conversion)
     djangotasks.run_task(task)
Example #4
0
 def save_model(self, request, obj, form, change):
     obj.save()
     task = djangotasks.task_for_object(obj.run_conversion)
     djangotasks.run_task(task)
Example #5
0
def submit(request):
    ''' The view for uploading the videos. Only authenticated users can upload videos!
    If we use transloadit to encode the videos we use the more or less official python
    "API" to ask transloadit to transcode our files otherwise we use django tasks to make
    a new task task for encoding this video. If we use bittorrent to distribute our files
    we also use django tasks to make the .torrent files (this can take a few minutes for
    very large files '''
    if request.user.is_authenticated():
        if request.method == 'POST':
            form = VideoForm(request.POST, request.FILES or None)
            if form.is_valid():
                cmodel = form.save()
                if cmodel.originalFile:
                    if settings.USE_TRANLOADIT:
                        client = Client(settings.TRANSLOAD_AUTH_KEY,
                                        settings.TRANSLOAD_AUTH_SECRET)
                        params = None
                        if (cmodel.kind == 0):
                            params = {
                                'steps': {
                                    ':original': {
                                        'robot': '/http/import',
                                        'url': cmodel.originalFile.url,
                                    }
                                },
                                'template_id':
                                settings.TRANSLOAD_TEMPLATE_VIDEO_ID,
                                'notify_url': settings.TRANSLOAD_NOTIFY_URL
                            }
                        if (cmodel.kind == 1):
                            params = {
                                'steps': {
                                    ':original': {
                                        'robot': '/http/import',
                                        'url': cmodel.originalFile.url,
                                    }
                                },
                                'template_id':
                                settings.TRANSLOAD_TEMPLATE_AUDIO_ID,
                                'notify_url': settings.TRANSLOAD_NOTIFY_URL
                            }
                        if (cmodel.kind == 2):
                            params = {
                                'steps': {
                                    ':original': {
                                        'robot': '/http/import',
                                        'url': cmodel.originalFile.url,
                                    }
                                },
                                'template_id':
                                settings.TRANSLOAD_TEMPLATE_VIDEO_AUDIO_ID,
                                'notify_url': settings.TRANSLOAD_NOTIFY_URL
                            }
                        result = client.request(**params)
                        cmodel.assemblyid = result['assembly_id']
                        cmodel.published = cmodel.autoPublish
                        cmodel.encodingDone = False
                        cmodel.save()
                    else:
                        cmodel.save()
                        djangotasks.register_task(
                            cmodel.encode_media,
                            "Encode the files using ffmpeg")
                        encoding_task = djangotasks.task_for_object(
                            cmodel.encode_media)
                        djangotasks.run_task(encoding_task)
                if settings.USE_BITTORRENT:
                    djangotasks.register_task(
                        cmodel.create_bittorrent,
                        "Create Bittorrent file for video and serve it")
                    torrent_task = djangotasks.task_for_object(
                        cmodel.create_bittorrent)
                    djangotasks.run_task(torrent_task)
                cmodel.user = request.user
                cmodel.save()
                return redirect(list)

            return render_to_response('videos/submit.html',
                                      {'submit_form': form},
                                      context_instance=RequestContext(request))
        else:
            form = VideoForm()
            return render_to_response('videos/submit.html',
                                      {'submit_form': form},
                                      context_instance=RequestContext(request))
    else:
        return render_to_response('videos/nothing.html',
                                  context_instance=RequestContext(request))
Example #6
0
def submit(request):
    ''' The view for uploading the videos. Only authenticated users can upload videos!
    If we use transloadit to encode the videos we use the more or less official python
    "API" to ask transloadit to transcode our files otherwise we use django tasks to make
    a new task task for encoding this video. If we use bittorrent to distribute our files
    we also use django tasks to make the .torrent files (this can take a few minutes for
    very large files '''
    if request.user.is_authenticated():
        if request.method == 'POST':
            form = VideoForm(request.POST, request.FILES or None)
            if form.is_valid():
                    cmodel = form.save()
                    if cmodel.originalFile:
                        if settings.USE_TRANLOADIT:
                            client = Client(settings.TRANSLOAD_AUTH_KEY, settings.TRANSLOAD_AUTH_SECRET)
                            params = None
                            if (cmodel.kind==0):
                                params = {
                                    'steps': {
                                        ':original': {
                                            'robot': '/http/import',
                                            'url': cmodel.originalFile.url,
                                        }
                                    },
                                    'template_id': settings.TRANSLOAD_TEMPLATE_VIDEO_ID,
                                    'notify_url': settings.TRANSLOAD_NOTIFY_URL
                                }
                            if (cmodel.kind==1):
                                params = {
                                    'steps': {
                                        ':original': {
                                            'robot': '/http/import',
                                            'url': cmodel.originalFile.url,
                                        }
                                    },
                                    'template_id': settings.TRANSLOAD_TEMPLATE_AUDIO_ID,
                                    'notify_url': settings.TRANSLOAD_NOTIFY_URL
                                }
                            if (cmodel.kind==2):
                                params = {
                                    'steps': {
                                        ':original': {
                                            'robot': '/http/import',
                                            'url': cmodel.originalFile.url,
                                        }
                                    },
                                    'template_id': settings.TRANSLOAD_TEMPLATE_VIDEO_AUDIO_ID,
                                    'notify_url': settings.TRANSLOAD_NOTIFY_URL
                                }
                            result = client.request(**params)
                            cmodel.assemblyid = result['assembly_id']
                            cmodel.published = cmodel.autoPublish
                            cmodel.encodingDone = False
                            cmodel.save()
                        else:
                            cmodel.save()
                            djangotasks.register_task(cmodel.encode_media, "Encode the files using ffmpeg")
                            encoding_task = djangotasks.task_for_object(cmodel.encode_media)
                            djangotasks.run_task(encoding_task)
                    if settings.USE_BITTORRENT:
                        djangotasks.register_task(cmodel.create_bittorrent, "Create Bittorrent file for video and serve it")
                        torrent_task = djangotasks.task_for_object(cmodel.create_bittorrent)
                        djangotasks.run_task(torrent_task)
                    cmodel.user = request.user
                    cmodel.save()
                    return redirect(list)
    
            return render_to_response('videos/submit.html',
                                    {'submit_form': form},
                                    context_instance=RequestContext(request))
        else:
            form = VideoForm()
            return render_to_response('videos/submit.html',
                                    {'submit_form': form},
                                    context_instance=RequestContext(request))
    else:
        return render_to_response('videos/nothing.html',
                            context_instance=RequestContext(request))
Example #7
0
 def _task_for_object(self, method, object_id):
     key = join(self.tempdir, object_id)
     object, _ = method.im_class.objects.get_or_create(pk=key)
     return djangotasks.task_for_object(getattr(object, method.func_name))
Example #8
0
 def _task_for_object(self, method, object_id):
     key = join(self.tempdir, object_id)
     object, _ = method.im_class.objects.get_or_create(pk=key)
     return djangotasks.task_for_object(getattr(object, method.func_name))