本文整理汇总了Python中models.Video类的典型用法代码示例。如果您正苦于以下问题:Python Video类的具体用法?Python Video怎么用?Python Video使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Video类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_manifest_in_model
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
示例2: add_video_to_db
def add_video_to_db(video_url, thumbnail_url, video_type, object_id, username=None):
if not Video.query.filter(Video.url==video_url).count():
v = Video(url=video_url, thumbnail=thumbnail_url, video_type=video_type, object_id=object_id)
if username:
v.username=username
db.session.add(v)
db.session.commit()
示例3: create_or_edit_video
def create_or_edit_video(request, project_slug, video_slug=None):
project = get_object_or_404(Project, slug=project_slug)
if video_slug:
if not project.get_perms(request.user).get("has_member_perm", False):
request.user.message_set.create(message=NEED_MEMBER_PERM)
else:
video = get_object_or_404(Video, slug=video_slug, project=project)
if request.method == "POST" and "update" in request.POST:
video.sync_with_yt()
video.save()
request.user.message_set.create(message="Video infromation was updated.")
else:
request.user.message_set.create(message="Invalid data.")
return HttpResponseRedirect(video.get_absolute_url())
else:
action = "Add new Video"
form_class = forms.VideoCreationForm
video = Video(project=project, added_by=request.user)
if request.method == 'POST':
form = form_class(data=request.POST, instance=video)
form.project = project
if form.is_valid():
video = form.save()
return HttpResponseRedirect(video.get_absolute_url())
else:
form = form_class(instance=video)
return render_to_response('projects/create_or_edit_video.html', locals(),
context_instance=RequestContext(request))
示例4: new_video
def new_video():
form = VideoForm()
if form.validate_on_submit():
now = moment.now().format('dddd, MMMM D YYYY')
today = Day.query.filter_by(date=now).first()
if today is not None:
video = Video(title=form.title.data,description=form.description.data,video_link=form.video_link.data,day_id=today.id)
db.session.add(video)
db.session.flush()
video.generate_hash()
video.generate_thumbnail(app.config["UPLOAD_FOLDER"], form.thumbnail.data, app.config["ALLOWED_EXTENSIONS"])
db.session.add(video)
db.session.commit()
flash("Video Successfully Added")
return redirect(url_for("index"))
else:
day = Day(date=now)
db.session.add(day)
db.session.flush()
video = Video(title=form.title.data,description=form.description.data,video_link=form.video_link.data,day_id=day.id)
db.session.add(video)
db.session.flush()
video.generate_hash()
video.generate_thumbnail(app.config["UPLOAD_FOLDER"], form.thumbnail.data, app.config["ALLOWED_EXTENSIONS"])
db.session.add(video)
db.session.commit()
flash("Video Successfully Added")
return redirect(url_for("index"))
return render_template("videos/new.html",form=form)
示例5: test_parse_video
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)
示例6: test_model_video_url
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)
示例7: test_video_slugify_on_save
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)
示例8: add_to_db
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
示例9: process_play_complete
def process_play_complete(self, timestamp):
next_video = None
if self.force_play_id:
print "force video lined up"
next_video = Video.objects(id = self.force_play_id)
self.force_play_id = None
if not next_video:
print "get next video based on timestamp"
next_video = Video.objects(created_at__gt=timestamp)
if next_video:
self.play_async(next_video[0]['video_url'], next_video[0]['created_at'])
示例10: generate_view
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')
示例11: video_title_dicts
def video_title_dicts():
return map(lambda video: {
"title": video.title,
"key": str(video.key()),
"ka_url": video.relative_url, # remove once js clients update
"url": video.relative_url
}, [v for v in Video.get_all_live() if v is not None])
示例12: get
def get(self, id=1):
video = Video.get(id)
debug = str(video)
render_template(self, 'video.html', {
'video': video,
'debug': debug,
})
示例13: library_content_html
def library_content_html(mobile=False, version_number=None):
if version_number:
version = TopicVersion.get_by_number(version_number)
else:
version = TopicVersion.get_default_version()
tree = Topic.get_root(version).make_tree(types = ["Topics", "Video", "Exercise", "Url"])
videos = [item for item in walk_children(tree) if item.kind()=="Video"]
root, = prepare(tree)
topics = root.subtopics
timestamp = time.time()
template_values = {
'topics': topics,
'is_mobile': mobile,
# convert timestamp to a nice integer for the JS
'timestamp': int(round(timestamp * 1000)),
'version_date': str(version.made_default_on),
'version_id': version.number,
'approx_vid_count': Video.approx_count(),
'exercise_count': Exercise.get_count(),
}
html = shared_jinja.get().render_template("library_content_template.html", **template_values)
return html
示例14: saveVideo
def saveVideo():
#Saving Video#
print 'saveVideo called'
try:
myDB.connect()
record = json.loads(request.data)
#Get all the label ids here#
labels = record['labels']
videoId = record['videoId']
labelArray = []
#for k,v in sorted(label,key=itemgetter('year')):
# print k, v
for record in labels:
oneLabel = Label.select().where((Label.category == record['name'])
& (Label.label == record['value'])).get()
#commaLabelIds = commaLabelIds + str(oneLabel.labelId) + ','
labelArray.append(str(oneLabel.labelId))
video = Video.select().where(Video.videoId == videoId).get()
labelArray.sort()
csvLabels = ",".join([str(x) for x in labelArray])
video.labelIds = csvLabels #commaLabelIds[:-1]
video.status = 'Y'
video.save()
myDB.close()
except Exception as e:
myDB.close()
traceback.print_exc(file=sys.stdout)
return 'Save Video Error', 404
return 'Video/Labels saved'
示例15: searchVideos
def searchVideos():
videos = []
#Subject.name ** ('%' + keyword + '%'),
myDB.connect()
try:
record = json.loads(request.data)
labels = record['labels']
labelArray = []
for record in labels:
oneLabel = Label.select().where((Label.category == record['name'])
& (Label.label == record['value'])).get()
#commaLabelIds = commaLabelIds + str(oneLabel.labelId) + ','
labelArray.append(str(oneLabel.labelId))
labelArray.sort()
csvLabels = ",".join([str(x) for x in labelArray])
#for record in Video.select().where(Video.status == 'N').get():
for record in Video.select().where(Video.labelIds % ('%' + csvLabels + '%')):
videos.append({'videoId':record.videoId, 'fileName':record.fileName,
'folderName':record.folderName, 'boxLink':record.boxLink})
#print videos
except Exception as e:
myDB.close()
print e
return 'Search Videos Error', 404
if len(videos) == 0:
return 'No Videos'
return jsonify(data=videos)