本文整理汇总了Python中models.Video.save方法的典型用法代码示例。如果您正苦于以下问题:Python Video.save方法的具体用法?Python Video.save怎么用?Python Video.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Video
的用法示例。
在下文中一共展示了Video.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_vdn_dataset_url
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import save [as 别名]
def import_vdn_dataset_url(server, url, user):
r = requests.get(url)
response = r.json()
vdn_dataset = create_dataset(response, server)
vdn_dataset.save()
video = Video()
if user:
video.uploader = user
video.name = vdn_dataset.name
video.vdn_dataset = vdn_dataset
video.save()
if vdn_dataset.download_url:
task_name = 'import_vdn_file'
import_video_task = TEvent()
import_video_task.video = video
import_video_task.operation = task_name
import_video_task.save()
app.send_task(name=task_name, args=[import_video_task.pk, ], queue=settings.TASK_NAMES_TO_QUEUE[task_name])
elif vdn_dataset.aws_key and vdn_dataset.aws_bucket:
task_name = 'import_vdn_s3'
import_video_task = TEvent()
import_video_task.video = video
import_video_task.operation = task_name
import_video_task.save()
app.send_task(name=task_name, args=[import_video_task.pk, ], queue=settings.TASK_NAMES_TO_QUEUE[task_name])
else:
raise NotImplementedError
示例2: save_manifest_in_model
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import save [as 别名]
def save_manifest_in_model(house_id, m3u8_manifest):
#
# Search de Video, if exist return Error
try:
video = Video.objects.get(house_id=house_id)
return False
except:
video = Video()
video.house_id = house_id
video.format = 'hls'
video.save()
for rendition in m3u8_manifest.files:
profile = Profile()
profile.video = video
profile.bandwidth = rendition['bandwidth']
profile.average = rendition['average']
profile.codecs = rendition['codecs']
profile.resolution = rendition['resolution']
profile.filename = rendition['filename']
profile.version = rendition['rendition'].header['version']
profile.media_seq = rendition['rendition'].header['media_seq']
profile.allow_cache = rendition['rendition'].header['allow_cache']
profile.target_duration = rendition['rendition'].header['target_duration']
profile.save()
for tsfile in rendition['rendition'].files:
profile_file = ProfileFile()
profile_file.profile = profile
profile_file.number = tsfile['number']
profile_file.extinf = tsfile['extinf']
profile_file.filename = tsfile['filename']
profile_file.save()
return True
示例3: test_parse_video
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import save [as 别名]
def test_parse_video(self):
owner = GroupFactory(remote_id=GROUP_ID)
album = AlbumFactory(remote_id=ALBUM_ID, owner=owner)
response = '''{"photo_130": "http://cs313422.vk.me/u163668241/video/s_6819a7d1.jpg",
"repeat": 0,
"photo_320": "http://cs313422.vk.me/u163668241/video/l_4cc8a38a.jpg",
"description": "bla bla bla",
"title": "Эстафета Олимпийского огня «Сочи 2014». Неделя 3-я",
"can_repost": 1, "views": 928, "album_id": 50850761, "comments": 12, "player": "http://www.youtube.com/embed/UmDAmM53bU0", "date": 1386074580, "likes": {"count": 191, "user_likes": 0}, "duration": 206, "can_comment": 1, "id": 166742757, "owner_id": -16297716}
'''
d = json.loads(response)
instance = Video()
instance.parse(d.copy())
instance.save()
self.assertEqual(instance.album, album)
self.assertEqual(instance.owner, owner)
self.assertEqual(instance.remote_id, d['id'])
self.assertEqual(instance.title, d['title'])
self.assertEqual(instance.description, d['description'])
self.assertEqual(instance.photo_130, d['photo_130'])
self.assertEqual(instance.player, d['player'])
self.assertEqual(instance.views_count, d['views'])
self.assertEqual(instance.comments_count, d['comments'])
self.assertEqual(instance.likes_count, d['likes']['count'])
self.assertEqual(instance.duration, d['duration'])
self.assertIsNotNone(instance.date)
示例4: test_video_slugify_on_save
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import save [as 别名]
def test_video_slugify_on_save(self):
video = Video()
video.title = "I am an awesome title"
video.description = "I am a description"
video.save()
self.assertEqual("i-am-an-awesome-title", video.slug)
示例5: test_model_video_url
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import save [as 别名]
def test_model_video_url(self):
video = Video(title="I is title",description="i is desc")
video.video_h264 = "h264.mp4"
video.video_webm = "webm.webm"
video.save()
self.assertEqual("/media/episode-%s/%s" % (video.id, "h264.mp4"), video.h264)
self.assertEqual("/media/episode-%s/%s" % (video.id, "webm.webm"), video.webm)
示例6: add_to_db
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import save [as 别名]
def add_to_db(video_files):
for video_file in video_files:
video_filename = video_file.rsplit('/', 1)[1] # Get filename
if not Video.objects.filter(filename=video_filename).exists():
video = Video(title=os.path.splitext(video_filename)[0], \
filename=video_filename, \
fspath=video_file, \
media_url=MEDIA_URL + video_file.split(MEDIA_ROOT)[1])
video.save()
print 'Added to DB: ' + video_filename
示例7: generate_view
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import save [as 别名]
def generate_view(request):
bilibili_url = request.GET.get('url','')
aid = get_aid(bilibili_url)
if not aid:
sys.exit()
data_dict = view_data(aid)
error = data_dict.get('error','')
if error:
# remove the data which have problem
print '@253', error
return HttpResponse('finished')
cid,pages = data_dict['cid'],int(data_dict['pages'])
# source_json = get_video_source(cid)
video_list = Video.objects.filter(aid = aid)
if len(video_list) == 0:
v = Video(aid=aid)
v.title = data_dict['title']
v.pic_url = data_dict['pic']
v.save()
else:
v = video_list[0]
for i in range(1,pages+1):
time.sleep(5)
data_dict = view_data(aid,i)
cid = data_dict['cid']
partname = data_dict['partname']
video_title = data_dict['title']
video_path = video_title
source_json = get_video_source(cid)
title = data_dict['partname']
if not title:
title = data_dict['title']
code,path = get_video(source_json,'%s' % (title))
if code == 0 and path:
save_part(data_dict,v,path)
return HttpResponse('finished')
示例8: handle_youtube_video
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import save [as 别名]
def handle_youtube_video(name, url, extract=True, user=None, rate=30, rescale=0):
video = Video()
if user:
video.uploader = user
video.name = name
video.url = url
video.youtube_video = True
video.save()
task_name = 'segment_video'
extract_frames_task = TEvent()
extract_frames_task.video = video
extract_frames_task.operation = task_name
extract_frames_task.arguments_json = json.dumps({'rate': rate,'rescale': rescale})
extract_frames_task.save()
if extract:
app.send_task(name=task_name, args=[extract_frames_task.pk, ], queue=settings.TASK_NAMES_TO_QUEUE[task_name])
return video
示例9: test_model_fields
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import save [as 别名]
def test_model_fields(self):
video = Video()
video.title = "The Title"
video.slug = "the-title"
video.thumbnail_image = "thumbnail.jpg"
video.preview_image = "preview.jpg"
video.description = "long description here"
video.show_notes = "show notes here"
video.video_h264 = "video.mp4"
video.video_webm = "video.webm"
video.length = 12
video.episode = 1
video.publish_date = now()
video.is_premium = False
video.price = 105.00
video.save()
self.assertEqual(video, Video.objects.get(title__exact="The Title"))
示例10: cm_PostCuePoint
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import save [as 别名]
def cm_PostCuePoint(request):
if request.method == 'GET':
return TemplateResponse(request, 'cue_manager.html')
if request.method != 'POST':
status = http_METHOD_NOT_ALLOWED
return HttpResponse('', status=status)
if 'house_id' in request.POST.keys():
house_id = request.POST['house_id']
else:
status = http_BAD_REQUEST
return HttpResponse('', status=status)
if house_id == '':
status = http_BAD_REQUEST
return HttpResponse('', status=status)
languages = Language.objects.all()
for key, value in request.POST.iteritems():
if key.endswith('_tc') and value != '':
i, t = key.split('_')
for lang in languages:
lang_key = '%s_%s' % (i, lang.code)
if lang_key in request.POST.keys() and request.POST[lang_key] != '':
try:
video = Video.objects.get(house_id = house_id)
except:
video = Video()
video.house_id = house_id
video.save()
cuepoint = CuePoint()
cuepoint.video = video
cuepoint.timecode = value
cuepoint.language = lang
cuepoint.name = request.POST[lang_key]
cuepoint.save()
status = http_POST_OK
return TemplateResponse(request, 'cue_manager.html')
示例11: add_video
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import save [as 别名]
def add_video(request):
err = check_arguments(request, ["videoID"])
if err: return err
videoID = request.POST["videoID"]
# check to see if video exists for user
# TODO refactor to use get_video_query
if Video.objects.filter(user=request.user, videoID=videoID).count() != 0:
return HttpResponse(status=409, content="videoID %s already exists for user" % videoID)
# look up video in youtube api
from gdata.youtube.service import YouTubeService
yt_service = YouTubeService()
data = yt_service.GetYouTubeVideoEntry(video_id=videoID)
# save new video for user
v = Video(videoID=videoID, user=request.user, title=data.media.title.text)
v.save()
return HttpResponse(status=201, content=json.dumps(v.render()))
示例12: UserUploadView
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import save [as 别名]
def UserUploadView(request):
if request.user.is_authenticated():
if request.method == "GET":
return render_to_response('userUpload.html', None,
context_instance=RequestContext(request))
elif request.method == "POST":
videoName = request.POST['videoName']
vUrl = None
if request.POST['ch'] == "own":
handle_uploadVideo(request.FILES['videoFile'])
vUrl = request.FILES['videoFile'].name
elif request.POST['ch'] == "stream":
vUrl = request.POST['videoStream']
vLanguage = request.POST['language']
vCategory = request.POST['category']
pic = None
if 'pic' not in request.FILES:
pic = "testVideo1-12442143145e53.jpg"
else:
handle_uploadVideoImage(request.FILES['pic'])
pic = request.FILES['pic'].name
lan = Language.objects.get(pk=int(vLanguage))
cat = Category.objects.get(pk=int(vCategory))
video = Video(title=videoName, url="http://127.0.0.1:8000/media/" + vUrl, length=500, owner=request.user, displayImage=pic,
language=lan, category=cat)
video.save()
tags = request.POST['tags'].split(",")
for tag in tags:
tg, created = Tag.objects.get_or_create(tag_name=tag)
video.video_link.add(tg)
video.save()
return redirect("/video/?vId=" + str(video.id))
else:
return render_to_response('login.html', None,
context_instance=RequestContext(request))
示例13: handle_uploaded_file
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import save [as 别名]
def handle_uploaded_file(f, name, extract=True, user=None, rate=30, rescale=0):
video = Video()
if user:
video.uploader = user
video.name = name
video.save()
primary_key = video.pk
filename = f.name
filename = filename.lower()
if filename.endswith('.dva_export.zip'):
create_video_folders(video, create_subdirs=False)
with open('{}/{}/{}.{}'.format(settings.MEDIA_ROOT, video.pk, video.pk, filename.split('.')[-1]),
'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
video.uploaded = True
video.save()
task_name = 'import_video_by_id'
import_video_task = TEvent()
import_video_task.video = video
import_video_task.save()
app.send_task(name=task_name, args=[import_video_task.pk, ], queue=settings.TASK_NAMES_TO_QUEUE[task_name])
elif filename.endswith('.mp4') or filename.endswith('.flv') or filename.endswith('.zip'):
create_video_folders(video, create_subdirs=True)
with open('{}/{}/video/{}.{}'.format(settings.MEDIA_ROOT, video.pk, video.pk, filename.split('.')[-1]),
'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
video.uploaded = True
if filename.endswith('.zip'):
video.dataset = True
video.save()
if extract:
extract_frames_task = TEvent()
extract_frames_task.arguments_json = json.dumps({'rate': rate,'rescale': rescale})
extract_frames_task.video = video
task_name = 'extract_frames' if video.dataset else 'segment_video'
extract_frames_task.operation = task_name
extract_frames_task.save()
app.send_task(name=task_name, args=[extract_frames_task.pk, ],
queue=settings.TASK_NAMES_TO_QUEUE[task_name])
else:
raise ValueError, "Extension {} not allowed".format(filename.split('.')[-1])
return video
示例14: add_video
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import save [as 别名]
def add_video(request, party_token, video_token, user_id):
party = Party.objects.get(token=party_token)
video = Video(party_id=party, token=video_token, user_id_id=user_id, status='Q')
video.save()
return HttpResponse('SUCCESS')
示例15: test_model_get_absolute_url
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import save [as 别名]
def test_model_get_absolute_url(self):
video = Video(title="I is title", description="i is desc")
video.save()
self.assertEqual(
"/%s-%s/" % (video.id, video.slug), video.get_absolute_url())