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)
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)
def test_tasks_register(self): class MyClass(object): _meta = "djangotasks.myclass" def mymethod1(self): pass def mymethod2(self): pass def mymethod3(self): pass def mymethod4(self): pass def mymethod5(self): pass from djangotasks.models import TaskManager try: djangotasks.register_task(MyClass.mymethod1, '''Some documentation''') djangotasks.register_task(MyClass.mymethod2, '''Some other documentation''', MyClass.mymethod1) djangotasks.register_task(MyClass.mymethod3, None, MyClass.mymethod1, MyClass.mymethod2) djangotasks.register_task(MyClass.mymethod4, None, [MyClass.mymethod1, MyClass.mymethod2]) djangotasks.register_task(MyClass.mymethod5, None, (MyClass.mymethod1, MyClass.mymethod2)) self.assertEquals([ ('mymethod1', 'Some documentation', ''), ('mymethod2', 'Some other documentation', 'mymethod1'), ('mymethod3', '', 'mymethod1,mymethod2'), ('mymethod4', '', 'mymethod1,mymethod2'), ('mymethod5', '', 'mymethod1,mymethod2'), ], TaskManager.DEFINED_TASKS['djangotasks.myclass']) finally: del TaskManager.DEFINED_TASKS['djangotasks.myclass']
def test_tasks_register(self): class MyClass(object): _meta = "djangotasks.myclass" def mymethod1(self): pass def mymethod2(self): pass def mymethod3(self): pass def mymethod4(self): pass def mymethod5(self): pass from djangotasks.models import TaskManager try: djangotasks.register_task(MyClass.mymethod1, """Some documentation""") djangotasks.register_task(MyClass.mymethod2, """Some other documentation""", MyClass.mymethod1) djangotasks.register_task(MyClass.mymethod3, None, MyClass.mymethod1, MyClass.mymethod2) djangotasks.register_task(MyClass.mymethod4, None, [MyClass.mymethod1, MyClass.mymethod2]) djangotasks.register_task(MyClass.mymethod5, None, (MyClass.mymethod1, MyClass.mymethod2)) self.assertEquals( [ ("mymethod1", "Some documentation", ""), ("mymethod2", "Some other documentation", "mymethod1"), ("mymethod3", "", "mymethod1,mymethod2"), ("mymethod4", "", "mymethod1,mymethod2"), ("mymethod5", "", "mymethod1,mymethod2"), ], TaskManager.DEFINED_TASKS["djangotasks.myclass"], ) finally: del TaskManager.DEFINED_TASKS["djangotasks.myclass"]
help_text='Allowed extensions: .csv') return_email = models.EmailField() upload_time = models.DateTimeField(blank=True, null=True) def __unicode__(self): return self.name + ' -- Reply to: ' + str(self.return_email) def clean(self): # Set the Upload Time self.upload_time = datetime.datetime.now() # Make sure that the uploaded file is valid CSV try: csv.DictReader(self.csv_file) except: raise ValidationError('Uploaded file is not a valid CSV file.') def run_conversion(self): # Run the CSV > Metadata transformation transformcsv(self) # Ship the results send_results(self) # Clean up cleanup(self) pass djangotasks.register_task(CsvUpload.run_conversion, "Convert CSV File to XML Metadata.")
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))
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))
return_email = models.EmailField() upload_time = models.DateTimeField(blank=True, null=True) def __unicode__(self): return self.name + ' -- Reply to: ' + str(self.return_email) def clean(self): # Set the Upload Time self.upload_time = datetime.datetime.now() # Make sure that the uploaded file is valid CSV try: csv.DictReader(self.csv_file) except: raise ValidationError('Uploaded file is not a valid CSV file.') def run_conversion(self): # Run the CSV > Metadata transformation transformcsv(self) # Ship the results send_results(self) # Clean up cleanup(self) pass djangotasks.register_task(CsvUpload.run_conversion, "Convert CSV File to XML Metadata.")