本文整理汇总了Python中mediacore.model.Media.created_on方法的典型用法代码示例。如果您正苦于以下问题:Python Media.created_on方法的具体用法?Python Media.created_on怎么用?Python Media.created_on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mediacore.model.Media
的用法示例。
在下文中一共展示了Media.created_on方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: media_from_entry
# 需要导入模块: from mediacore.model import Media [as 别名]
# 或者: from mediacore.model.Media import created_on [as 别名]
def media_from_entry(e, tags=False, save_files=False):
# Get tags as a list of unicode objects.
tags = [t['term'] for t in e['tags']]
# Assume not explicit.
explicit = 0
if 'itunes_explicit' in e:
explicit = e['itunes_explicit']
# Find the duration, if it exists
duration = u''
if 'itunes_duration' in e:
try:
duration = e['itunes_duration']
duration = duration_to_seconds(duration)
except ValueError:
duration = None
# Find the first <img> tag in the summary, if there is one
image = None
m = img_regex.match(e['summary'])
if m is not None:
image = m.group(1)[1:-1]
title = e['title']
slug = slugify(title)
author_name = u"PLACEHOLDER NAME"
author_email = u"[email protected]"
if 'author_detail' in e:
if 'name' in e['author_detail']:
author_name = e['author_detail']['name']
if 'email' in e['author_detail']:
author_email = e['author_detail']['email']
year, month, day, hour, minute, second = e['updated_parsed'][:6]
updated = datetime(year, month, day, hour, minute, second)
media = Media()
media.slug = get_available_slug(Media, slug, media)
media.title = e['title']
media.author = Author(author_name, author_email)
media.description = e['summary']
media.notes = u''
if tags:
media.set_tags(tags)
else:
media.set_categories(tags)
media.publish_on = updated
media.created_on = updated
media.publishable = True
media.reviewed = True
media.duration = duration
DBSession.add(media)
DBSession.flush()
# Create thumbs from image, or default thumbs
created_images = False
if image:
temp_imagefile = tempfile.TemporaryFile()
imagefile = urllib2.urlopen(image)
temp_imagefile.write(imagefile.read())
temp_imagefile.seek(0)
filename = urlparse.urlparse(image)[2]
create_thumbs_for(media, temp_imagefile, filename)
created_images = True
if not created_images:
create_default_thumbs_for(media)
print "Loaded episode:", media
# now add all of the files.
for enc in e['enclosures']:
mf = media_file_from_enclosure(enc, media, save_files)
print "Loaded media file:", mf
media.update_status()
return media