当前位置: 首页>>代码示例>>Python>>正文


Python model.Media类代码示例

本文整理汇总了Python中mediacore.model.Media的典型用法代码示例。如果您正苦于以下问题:Python Media类的具体用法?Python Media怎么用?Python Media使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Media类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save_media_obj

    def save_media_obj(self, name, email, title, description, tags, uploaded_file, url):
        # create our media object as a status-less placeholder initially
        media_obj = Media()
        media_obj.author = Author(name, email)
        media_obj.title = title
        media_obj.slug = get_available_slug(Media, title)
        media_obj.description = description
        if request.settings['wording_display_administrative_notes']:
            media_obj.notes = request.settings['wording_administrative_notes']
        media_obj.set_tags(tags)

        # Give the Media object an ID.
        DBSession.add(media_obj)
        DBSession.flush()

        # Create a MediaFile object, add it to the media_obj, and store the file permanently.
        media_file = add_new_media_file(media_obj, file=uploaded_file, url=url)

        # The thumbs may have been created already by add_new_media_file
        if not has_thumbs(media_obj):
            create_default_thumbs_for(media_obj)

        media_obj.update_status()
        DBSession.flush()

        return media_obj
开发者ID:AshKash,项目名称:mediacore-community,代码行数:26,代码来源:upload.py

示例2: save_media_obj

def save_media_obj(author_name, author_email, title, description, tags, file, url):
    media = Media()
    media.author = Author(author_name, author_email)
    media.title = title
    media.description = description
    media.tags = tags
    add_new_media_file(media, file=file, url=url)
    DBSession.add(media)
    DBSession.commit()
    return media
开发者ID:BlendedLearningCollaborative,项目名称:mediacore-community,代码行数:10,代码来源:test_helpers.py

示例3: add_file

    def add_file(self, id, file=None, url=None, **kwargs):
        """Save action for the :class:`~mediacore.forms.admin.media.AddFileForm`.

        Creates a new :class:`~mediacore.model.media.MediaFile` from the
        uploaded file or the local or remote URL.

        :param id: Media ID. If ``"new"`` a new Media stub is created.
        :type id: :class:`int` or ``"new"``
        :param file: The uploaded file
        :type file: :class:`cgi.FieldStorage` or ``None``
        :param url: A URL to a recognizable audio or video file
        :type url: :class:`unicode` or ``None``
        :rtype: JSON dict
        :returns:
            success
                bool
            message
                Error message, if unsuccessful
            media_id
                The :attr:`~mediacore.model.media.Media.id` which is
                important if new media has just been created.
            file_id
                The :attr:`~mediacore.model.media.MediaFile.id` for the newly
                created file.
            edit_form
                The rendered XHTML :class:`~mediacore.forms.admin.media.EditFileForm`
                for this file.
            status_form
                The rendered XHTML :class:`~mediacore.forms.admin.media.UpdateStatusForm`

        """
        if id == 'new':
            media = Media()
            user = request.environ['repoze.who.identity']['user']
            media.author = Author(user.display_name, user.email_address)
            # Create a temp stub until we can set it to something meaningful
            timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            media.title = u'Temporary stub %s' % timestamp
            media.slug = get_available_slug(Media, '_stub_' + timestamp)
            DBSession.add(media)
            DBSession.flush()
        else:
            media = fetch_row(Media, id)

        try:
            media_file = add_new_media_file(media, file, url)
        except Invalid, e:
            DBSession.rollback()
            data = dict(
                success = False,
                message = e.message,
            )
开发者ID:RadioErewan,项目名称:mediacore,代码行数:52,代码来源:media.py

示例4: setUp

 def setUp(self):
     super(FilteringRestrictedItemsTest, self).setUp()
     
     # without explicit re-registration of the default policy unit tests 
     # failed when running 'python setup.py test'
     self._register_default_policy()
     # get rid of default media
     Media.query.delete()
     self.private_media = Media.example(slug=u'private')
     self.public_media = Media.example(slug=u'public')
     self.permission_system = MediaCorePermissionSystem(self.pylons_config)
     self.media_query = Media.query
     user = self._create_user_without_groups()
     self.perm = UserPermissions(user, self.permission_system)
开发者ID:dummyanni,项目名称:Bachelor-Thesis,代码行数:14,代码来源:filtering_restricted_items_test.py

示例5: test_sets_video_type_if_media_contains_audio_and_video_files

 def test_sets_video_type_if_media_contains_audio_and_video_files(self):
     media = Media.example()
     assert_none(media.type)
     self.add_external_file(media, 'mp4')
     self.add_external_file(media, 'mp3')
     media.update_status()
     assert_equals(VIDEO, media.type, message='did not detect mixed video/audio media as VIDEO type')
开发者ID:Jpoudrier,项目名称:mediacore-community,代码行数:7,代码来源:media_status_test.py

示例6: test_does_not_set_type_if_only_audio_description_files_are_attached

 def test_does_not_set_type_if_only_audio_description_files_are_attached(self, suffix):
     media = Media.example()
     assert_none(media.type)
     media_file = self.add_external_file(media, suffix)
     media_file.type = AUDIO_DESC
     media.update_status()
     assert_none(media.type, message='did detect media with audio description file as %s' % media.type)
开发者ID:Jpoudrier,项目名称:mediacore-community,代码行数:7,代码来源:media_status_test.py

示例7: save_thumb

    def save_thumb(self, id, thumb, **kwargs):
        """Save a thumbnail uploaded with :class:`~mediacore.forms.admin.ThumbForm`.

        :param id: Media ID. If ``"new"`` a new Media stub is created.
        :type id: ``int`` or ``"new"``
        :param file: The uploaded file
        :type file: :class:`cgi.FieldStorage` or ``None``
        :rtype: JSON dict
        :returns:
            success
                bool
            message
                Error message, if unsuccessful
            id
                The :attr:`~mediacore.model.media.Media.id` which is
                important if a new media has just been created.

        """
        if id == 'new':
            media = Media()
            user = request.environ['repoze.who.identity']['user']
            media.author = Author(user.display_name, user.email_address)
            media.title = os.path.basename(thumb.filename)
            media.slug = get_available_slug(Media, '_stub_' + media.title)
            DBSession.add(media)
            DBSession.flush()
        else:
            media = fetch_row(Media, id)

        try:
            # Create JPEG thumbs
            create_thumbs_for(media, thumb.file, thumb.filename)
            success = True
            message = None
        except IOError, e:
            success = False
            if id == 'new':
                DBSession.delete(media)
            if e.errno == 13:
                message = _('Permission denied, cannot write file')
            elif e.message == 'cannot identify image file':
                message = _('Unsupport image type: %s') \
                    % os.path.splitext(thumb.filename)[1].lstrip('.')
            elif e.message == 'cannot read interlaced PNG files':
                message = _('Interlaced PNGs are not supported.')
            else:
                raise
开发者ID:,项目名称:,代码行数:47,代码来源:

示例8: _save_media_obj

    def _save_media_obj(self, name, email, title, description, tags, file, url):
        # create our media object as a status-less placeholder initially
        media_obj = Media()
        media_obj.author = Author(name, email)
        media_obj.title = title
        media_obj.slug = get_available_slug(Media, title)
        media_obj.description = description
        media_obj.notes = fetch_setting('wording_additional_notes')
        media_obj.set_tags(tags)

        # Create a media object, add it to the media_obj, and store the file permanently.
        if file is not None:
            media_file = _add_new_media_file(media_obj, file.filename, file.file)
        else:
            media_file = MediaFile()
            url = unicode(url)
            embed = parse_embed_url(url)
            if embed:
                media_file.type = embed['type']
                media_file.container = embed['container']
                media_file.embed = embed['id']
                media_file.display_name = '%s ID: %s' % \
                    (embed['container'].capitalize(), media_file.embed)
            else:
                # Check for types we can play ourselves
                ext = os.path.splitext(url)[1].lower()[1:]
                container = guess_container_format(ext)
                if container in accepted_extensions():
                    media_file.type = guess_media_type(container)
                    media_file.container = container
                    media_file.url = url
                    media_file.display_name = os.path.basename(url)
                else:
                    # Trigger a validation error on the whole form.
                    raise formencode.Invalid('Please specify a URL or upload a file below.', None, None)
            media_obj.files.append(media_file)

        # Add the final changes.
        media_obj.update_status()
        DBSession.add(media_obj)
        DBSession.flush()

        create_default_thumbs_for(media_obj)

        return media_obj
开发者ID:GunioRobot,项目名称:mediacore,代码行数:45,代码来源:upload.py

示例9: test_can_create_example_media

 def test_can_create_example_media(self):
     media = Media.example()
     
     assert_not_none(media.id)
     assert_equals(u'Foo Media', media.title)
     assert_equals(u'foo-media', media.slug)
     assert_equals(Author(u'Joe', u'[email protected]'), media.author)
     assert_length(0, media.files)
     
     assert_none(media.type)
     assert_none(media.podcast_id)
     
     assert_false(media.publishable)
     assert_false(media.reviewed)
     assert_false(media.encoded)
     assert_none(media.publish_on)
     assert_none(media.publish_until)
     assert_false(media.is_published)
开发者ID:Jpoudrier,项目名称:mediacore-community,代码行数:18,代码来源:media_example_test.py

示例10: uploadThumb

    def uploadThumb(self, thumb_file, podcastid, reviewed=False, **kwargs):
        """Save a thumbnail uploaded with :class:`~mediacore.forms.admin.ThumbForm`.
 
        :param file: The uploaded file
        :type file: :class:`cgi.FieldStorage` or ``None``
        :rtype: JSON dict
        :returns:
            success
                bool
            message
                Error message, if unsuccessful
            id
                The :attr:`~mediacore.model.media.Media.id` which is
                important if a new media has just been created.

        """ 
        media = Media() 
	media.author =  Author('user', '[email protected]')
	media.title = os.path.basename(thumb_file.filename)
	media.slug = get_available_slug(Media, '_stub_' + media.title)
	media.reviewed = reviewed
	media.views = podcastid
	DBSession.add(media)
	DBSession.flush() 
	
        try:
            # Create JPEG thumbs
            create_thumbs_for(media, thumb_file.file, thumb_file.filename)
            success = True
            message = None
        except IOError, e:
            success = False
            if id == 'new':
                DBSession.delete(media)
            if e.errno == 13:
                message = _('Permission denied, cannot write file')
            elif e.message == 'cannot identify image file':
                message = _('Unsupport image type: %s') \
                    % os.path.splitext(thumb_file.filename)[1].lstrip('.')
            elif e.message == 'cannot read interlaced PNG files':
                message = _('Interlaced PNGs are not supported.')
            else:
                raise
开发者ID:,项目名称:,代码行数:43,代码来源:

示例11: media_from_entry

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
开发者ID:MechanisM,项目名称:mediacore,代码行数:80,代码来源:rss_import.py

示例12: add_file

    def add_file(self, id, file=None, url=None, **kwargs):
        """Save action for the :class:`~mediacore.forms.admin.media.AddFileForm`.

        Creates a new :class:`~mediacore.model.media.MediaFile` from the
        uploaded file or the local or remote URL.

        :param id: Media ID. If ``"new"`` a new Media stub is created.
        :type id: :class:`int` or ``"new"``
        :param file: The uploaded file
        :type file: :class:`cgi.FieldStorage` or ``None``
        :param url: A URL to a recognizable audio or video file
        :type url: :class:`unicode` or ``None``
        :rtype: JSON dict
        :returns:
            success
                bool
            message
                Error message, if unsuccessful
            media_id
                The :attr:`~mediacore.model.media.Media.id` which is
                important if new media has just been created.
            file_id
                The :attr:`~mediacore.model.media.MediaFile.id` for the newly
                created file.
            edit_form
                The rendered XHTML :class:`~mediacore.forms.admin.media.EditFileForm`
                for this file.
            status_form
                The rendered XHTML :class:`~mediacore.forms.admin.media.UpdateStatusForm`

        """
        if id == 'new':
            media = Media()
            user = request.environ['repoze.who.identity']['user']
            media.author = Author(user.display_name, user.email_address)
            # Create a temp stub until we can set it to something meaningful
            timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            media.title = u'Temporary stub %s' % timestamp
            media.slug = get_available_slug(Media, '_stub_' + timestamp)
            media.reviewed = True
            DBSession.add(media)
            DBSession.flush()
        else:
            media = fetch_row(Media, id)

        media_file = add_new_media_file(media, file, url)
        if media.slug.startswith('_stub_'):
            media.title = media_file.display_name
            media.slug = get_available_slug(Media, '_stub_' + media.title)

        # The thumbs may have been created already by add_new_media_file
        if id == 'new' and not has_thumbs(media):
            create_default_thumbs_for(media)

        media.update_status()

        # Render some widgets so the XHTML can be injected into the page
        edit_form_xhtml = unicode(edit_file_form.display(
            action=url_for(action='edit_file', id=media.id),
            file=media_file))
        status_form_xhtml = unicode(update_status_form.display(
            action=url_for(action='update_status', id=media.id),
            media=media))

        data = dict(
            success = True,
            media_id = media.id,
            file_id = media_file.id,
            file_type = media_file.type,
            edit_form = edit_form_xhtml,
            status_form = status_form_xhtml,
            title = media.title,
            slug = media.slug,
            description = media.description,
            link = url_for(action='edit', id=media.id),
            duration = helpers.duration_from_seconds(media.duration),
        )

        return data
开发者ID:,项目名称:,代码行数:79,代码来源:

示例13: test_can_detect_audio_files

 def test_can_detect_audio_files(self, suffix):
     media = Media.example()
     assert_not_equals(AUDIO, media.type)
     self.add_external_file(media, suffix)
     media.update_status()
     assert_equals(AUDIO, media.type, message='did not detect %s as AUDIO type' % suffix)
开发者ID:Jpoudrier,项目名称:mediacore-community,代码行数:6,代码来源:media_status_test.py

示例14: createMediaItem

    def createMediaItem(
        self,
        title,
        author_email=None,
        author_name=None,
        slug=None,
        tags=None,
        podcast_id=None,
        category_ids=None,
        meta=None,
        **kwargs
    ):
        mediaItem = Media()
        log.info("createMediaItem({title})".format(title=title))

        if not slug:
            slug = title
        elif slug.startswith("_stub_"):
            slug = slug[len("_stub_") :]
        if slug != mediaItem.slug:
            mediaItem.slug = get_available_slug(Media, slug, mediaItem)

        if podcast_id:
            podcast_id = int(podcast_id)
        else:
            podcast_id = 0

        if not meta:
            meta = {}
        else:
            try:
                meta = json.loads(meta)
            except Exception as e:
                return {"success": False, "message": "Invalid JSON object given for `meta`"}

        mediaItem.title = title
        mediaItem.author = Author(author_name or "No Author", author_email or "No Email")
        mediaItem.podcast_id = podcast_id or None
        mediaItem.set_tags(tags)
        mediaItem.set_categories(category_ids)
        mediaItem.update_status()
        mediaItem.meta = meta

        DBSession.add(mediaItem)
        DBSession.flush()

        return {"success": True, "id": mediaItem.id}
开发者ID:catturavideo,项目名称:mediacore-ce-upload-plugin,代码行数:47,代码来源:uploader.py

示例15: test_can_override_example_data

 def test_can_override_example_data(self):
     media = Media.example(title=u'Bar Foo')
     
     assert_equals(u'Bar Foo', media.title)
     assert_equals(u'bar-foo', media.slug)
开发者ID:Jpoudrier,项目名称:mediacore-community,代码行数:5,代码来源:media_example_test.py


注:本文中的mediacore.model.Media类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。