本文整理汇总了Python中videos.models.Video.save方法的典型用法代码示例。如果您正苦于以下问题:Python Video.save方法的具体用法?Python Video.save怎么用?Python Video.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类videos.models.Video
的用法示例。
在下文中一共展示了Video.save方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_cocreate
# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import save [as 别名]
def init_cocreate(cocreate, generate_slug):
if len(cocreate.videos) <= 0:
return
if not cocreate.output_video:
slug = generate_slug(SLUG_LENGTH)
video = Video(title=cocreate.title, slug=slug, description=cocreate.description, uploader=cocreate.owner)
video.save()
cocreate.output_video = video
cocreate.save()
else:
# reset video status to encoding
video_status = cocreate.output_video.get_video_status()
video_status.set_to_encoding()
#create outline from the sections
VideoOutline.objects.filter(video=cocreate.output_video).delete()
outline = VideoOutline.objects.create(video=cocreate.output_video)
asections = cocreate.available_sections
for i in xrange(len(asections)):
outline.videooutlinepin_set.create(text=asections[i],
current_time=Decimal(str(i)))
# enqueue on cocreate task queue
enqueue_cocreate(cocreate)
示例2: main
# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import save [as 别名]
def main():
parsed = feedparser.parse(file("mostravideolivre.atom").read())
for i in parsed.entries:
mp4_url = i.content[0].src
ogg_url = mp4_url.replace(".mp4", ".ogg")
ogg_url = ogg_url.replace(".MP4", ".ogg")
thumb = ogg_url + ".png"
video = Video()
video.title = i.title
video.creation_date = datetime.now()
video.summary = i.get("summary", "")
video.author = i.author
video.license_name = "Creative Commons - Atribuição - Partilha nos Mesmos " + "Termos 3.0 Não Adaptada"
video.license_link = "http://creativecommons.org/licenses/by-sa/3.0/"
video.thumb_url = thumb
video.save()
tag = Tag.objects.get_or_create(name="mvl2010")[0]
tag.save()
video.tags.add(tag.id)
url = Url()
url.url = mp4_url
url.content_type = 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"'
url.video = video
url.save()
url = Url()
url.url = ogg_url
url.content_type = 'video/ogg; codecs="theora, vorbis"'
url.video = video
url.save()
示例3: upload_videos
# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import save [as 别名]
def upload_videos(request):
try:
uploaded_files = None
if request.method == 'POST':
author_email = request.POST['author']
set_slug = request.POST['set_slug']
fps_choice = request.POST['fps_choice']
author = User.objects.filter(email=author_email)[0]
for k in request.FILES.keys():
uploaded_file = request.FILES[k]
uploaded_file_content = uploaded_file.read()
name, ext = os.path.splitext(uploaded_file.name)
md5digest = hashlib.md5(uploaded_file_content).hexdigest()
#if duplicate, overwrite the old
try:
uploaded_video = Video.objects.filter(md5=md5digest)[0]
#TODO make other checkt to see if it is from the same user and the same filename
# if not raise an error (duplicate md5 from 2 different sources)
except IndexError:
uploaded_video = Video()
uploaded_video.filename = uploaded_file.name
uploaded_video.size = uploaded_file.size
uploaded_video.status = settings.DEFAULT_UPLOADED_VIDEO_STATUS
uploaded_video.extension = ext[1:]
uploaded_video.mimetype = mimetypes.types_map.get(ext)
uploaded_video.md5 = md5digest
delta = datetime.timedelta(days=-46)
uploaded_video.created_at = datetime.datetime.now()+delta
uploaded_video.updated_at = datetime.datetime.now()+delta
uploaded_video.author = author
uploaded_video.set_slug = set_slug
uploaded_video.fps_choice = fps_choice
if not os.path.exists(os.path.join(settings.TMP_VIDEO_ROOT, 'originals')):
os.makedirs(os.path.join(settings.TMP_VIDEO_ROOT, 'originals'))
if not os.path.exists(os.path.join(settings.TMP_VIDEO_ROOT, 'originals', set_slug)):
os.makedirs(os.path.join(settings.TMP_VIDEO_ROOT, 'originals', set_slug))
original_filename = "%s.%s" % (uploaded_video.md5, uploaded_video.extension)
with open(os.path.join(settings.TMP_VIDEO_ROOT, 'originals', set_slug, original_filename), 'wb') as f:
f.write(uploaded_file_content)
del uploaded_file_content
uploaded_video.save()
return HttpResponse('')
else:
author_email = request.GET['author'] if 'author' in request.GET else ''
set_slug = request.GET['set_slug'] if 'set_slug' in request.GET else ''
fps_choice = request.GET['fps_choice'] if 'fps_choice' in request.GET else ''
return render_to_response("videos/upload.html", locals())
except:
error_details = open(settings.DEBUG_ERROR_FILE, 'w')
traceback.print_exc(file=error_details)
error_details.close()
示例4: create
# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import save [as 别名]
def create(self, validated_data):
# logged in required
user = ContextUtils(self.context).logged_in_user()
# create video
video = Video(**validated_data)
video.user = user
video.save()
# add video tags
tags = TagBuilder.get_or_create_tags(validated_data['title'])
for tag in tags:
video.tags.add(tag)
return video
示例5: video_new
# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import save [as 别名]
def video_new(request,section_id):
if request.method=='POST':
form=AddVideoForm(request.POST)
if form.is_valid():
title=form.cleaned_data['title']
video_html_code=form.cleaned_data['video_html_code']
video_section=form.cleaned_data['video_section']
pub_date=timezone.now().date()
v=Video(title=title,
video_html_code=video_html_code,
pub_date=pub_date,
video_section=video_section)
v.save()
v.catch_youtube_id()
v.save()
return HttpResponseRedirect(reverse('videos:videos',kwargs={'section_id':section_id}))
else:
form=AddVideoForm()
return_path=request.META.get('HTTP_REFERER','/')
return render(request, 'video/blank_for_adding_video.html', {'form': form,
'return_path': return_path})
示例6: _execute_crawler
# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import save [as 别名]
def _execute_crawler(self, term, max_depth, max_breadth):
token = os.environ.get('TOKEN_YOUTUBE')
crawler = Crawler(site='youtube', site_token=token,
max_breadth=max_breadth, max_depth=max_depth)
for video in crawler.run(term.split()):
if Video.objects.filter(id_source=video.id_source).exists():
continue
base_url = 'http://www.youtube.com/watch?v='
db_video = Video(id_source=video.id_source,
source='youtube',
user=self.get_user(),
title=video.title,
description=video.description,
filename=base_url+video.id_source)
db_video.save(force_insert=True) # Could be problematic on sqlite
for tag in video.tags:
db_video.tags.add(self.get_tag(tag))
# Erase CrawlerBot thread controller
self.mutex.acquire()
del(self.threads[threading.currentThread().ident])
self.mutex.release()
示例7: _import_video
# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import save [as 别名]
def _import_video(self, video_url, videoid, title, description, thumbnail, videosrt):
videoid_match = VIDEOID_RE.search(videoid)
videoid = videoid_match.group(1)
video_type = YoutubeVideoType(
'http://www.youtube.com/watch?v={0}'.format(videoid))
try:
video_url_obj = VideoUrl.objects.get(
url=video_type.convert_to_video_url())
video = video_url_obj.video
except ObjectDoesNotExist:
video_url_obj = None
video = Video()
video.youtube_videoid = videoid
video.title = title
video.description = description
if video_type.entry.media.duration:
video.duration = int(video_type.entry.media.duration.seconds)
video.thumbnail = thumbnail
video.save()
Action.create_video_handler(video)
if videosrt:
self._import_srt(video, videosrt)
else:
SubtitleLanguage(video=video, language='en', is_original=True, is_forked=True).save()
if not video_url_obj:
video_url_obj = VideoUrl(
videoid=videoid,
url=video_type.convert_to_video_url(),
type=video_type.abbreviation,
original=True,
primary=True,
video=video)
video_url_obj.save()
self._save_alternate_url(video, video_url)
示例8: main
# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import save [as 别名]
def main():
for index, line in enumerate(csv.reader(file('mostravideolivre.csv'))):
# I don't need the column names :)
if index == 0:
continue
# No title
if not line[0].strip():
continue
video = Video()
video.title = line[0]
video.creation_date = datetime.now()
video.summary = line[5]
video.author = line[1]
video.license_name = \
'Creative Commons - Atribuição - Partilha nos Mesmos ' + \
'Termos 3.0 Não Adaptada'
video.license_link = 'http://creativecommons.org/licenses/by-sa/3.0/'
video.thumb_url = findvideo(line[7]).replace('ogv', 'png')
video.save()
tag = Tag.objects.get_or_create(name='mvl2011')[0]
tag.save()
video.tags.add(tag.id)
for tag_name in line[4].split(','):
tag = Tag.objects.get_or_create(name=tag_name.strip())[0]
tag.save()
video.tags.add(tag.id)
url = Url()
url.url = findvideo(line[7])
url.content_type = 'video/ogg; codecs="theora, vorbis"'
url.video = video
url.save()
示例9: AssertionError
# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import save [as 别名]
# check if rabbitmq is working
try:
connection = pika.BlockingConnection(pika.ConnectionParameters(settings.RABBITMQ_SERVER))
except Exception, e:
raise AssertionError("Cannot connect to rabbitmq server: %s" % e)
# Get uploader
uploader, created = User.objects.get_or_create(username="encodetester")
# Get video
slug = "LONGENCODE"
title = "Encode Test A"
description = "5-minute video with audio"
video = Video(title=title, slug=slug, uploader=uploader, description=description)
video.save()
logger.info("Video slug: %s" % slug)
slug_tmp = slug + "_tmp"
logger.info("Uploading file to s3...")
upload_to_s3(slug_tmp, LONG_VIDEO)
logger.info("Upload process successful.")
# should indicate that video was uploaded and is stored in s3
logger.info("Checking if video is already in s3 (should be there)...")
check = check_from_s3(slug_tmp)
if check != "Video is in s3":
raise AssertionError("Video was not uploaded to s3 properly.")
logger.info("Enqueuing slug to rabbitmq...")
enqueue(slug_tmp)
示例10: handle_noargs
# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import save [as 别名]
def handle_noargs(self, **options):
short_video_size_passed = False
short_video_duration_passed = False
short_video_encode_time_passed = False
long_video_size_passed = False
long_video_duration_passed = False
long_video_encode_time_passed = False
#check if rabbitmq is working
try:
connection = pika.BlockingConnection(pika.ConnectionParameters(settings.RABBITMQ_SERVER))
except:
logger.critical("We are experiencing a connection problem and cannot perform uploads for now. Please try again later.")
# Get uploader
uploader, created = User.objects.get_or_create(username='encodetester')
# Get video
slug = reserve_slug(SLUG_LENGTH)
title = "Encode Test A"
description = "5-minute video with audio"
video = Video(title=title, slug=slug, uploader=uploader, description=description)
video.save()
print ("Video slug: %s" % slug)
slug_tmp = slug + '_tmp'
print ("Uploading file to s3...")
upload_to_s3(slug_tmp, LONG_VIDEO)
print ("Upload process successful.")
print ("Enqueuing slug to rabbitmq...")
enqueue(slug_tmp)
print ("Enqueue process successful.")
# Mark reserved slug as used
try:
reserved_slug = ReservedSlug.objects.get(slug=slug)
except:
pass
else:
reserved_slug.used = True
reserved_slug.save()
while not is_encoded(slug):
time.sleep(3)
print ("Encoded!")
# Checks
video = Video.objects.get(slug=slug)
video_duration = video.video_duration
if Decimal(str(video_duration)) != Decimal(str(LONG_VIDEO_LENGTH)):
print ("Long video duration check failed.")
print ("%s vs %s" % (video_duration, LONG_VIDEO_LENGTH))
else:
print ("Long video duration check passed.")
long_video_duration_passed = True
video_status = VideoStatus.objects.get(video_slug=slug)
duration_difference = math.fabs(Decimal(str(video_status.encode_duration)) - Decimal(str(LONG_VIDEO_ENCODING)))
percent_error = (duration_difference / LONG_VIDEO_ENCODING) * 100
if percent_error > 30.0:
print ("Long video encoding time check failed.")
else:
print ("Long video encoding time check passed.")
long_video_encode_time_passed = True
print ("Percent error: %s" % percent_error)
video_file_len = len(get_from_s3(slug))
size_difference = math.fabs(video_file_len - LONG_VIDEO_SIZE)
percent_error = (size_difference / LONG_VIDEO_SIZE) * 100
if percent_error > 5.0:
print ("Long video encoded size check failed.")
else:
print ("Long video encoded size check passed.")
long_video_size_passed = True
print ("Percent error: %s" % percent_error)
# Get video
slug = reserve_slug(SLUG_LENGTH)
title = "Encode Test B"
description = "2-minute video with no audio"
video = Video(title=title, slug=slug, uploader=uploader, description=description)
video.save()
print ("Video slug: %s" % slug)
slug_tmp = slug + '_tmp'
print ("Uploading file to s3...")
upload_to_s3(slug_tmp, SHORT_VIDEO)
print ("Upload process successful.")
print ("Enqueuing slug to rabbitmq...")
enqueue(slug_tmp)
print ("Enqueue process successful.")
# Mark reserved slug as used
try:
reserved_slug = ReservedSlug.objects.get(slug=slug)
except:
#.........这里部分代码省略.........