def test_audiodesc_video_url_media(self): """Media with both Audio files and Video files attatched should be Video type.""" try: # Create the media object media = self._new_publishable_media(u'description-video', u'(Audio Description + Video)') DBSession.add(media) # Add an audio description media_file = add_new_media_file(media, None, u'http://fakesite.com/fakefile.mp3') media_file.type = AUDIO_DESC media.update_status() # Add a video file media_file = add_new_media_file(media, None, u'http://fakesite.com/fakefile.m4v') media.update_status() # Commit + test DBSession.commit() assert media.type == VIDEO, \ "A Media object with a .m4v file and an Audio Description " \ "was not labelled as a video type; it was labelled %s" % \ (t, media.type) except SQLAlchemyError, e: DBSession.rollback() raise e
def test_audiodesc_video_url_media(self): """Media with both Audio files and Video files attatched should be Video type.""" try: # Create the media object media = self._new_publishable_media( u'description-video', u'(Audio Description + Video)') DBSession.add(media) # Add an audio description media_file = add_new_media_file( media, None, u'http://fakesite.com/fakefile.mp3') media_file.type = AUDIO_DESC media.update_status() # Add a video file media_file = add_new_media_file( media, None, u'http://fakesite.com/fakefile.m4v') media.update_status() # Commit + test DBSession.commit() assert media.type == VIDEO, \ "A Media object with a .m4v file and an Audio Description " \ "was not labelled as a video type; it was labelled %s" % \ (t, media.type) except SQLAlchemyError, e: DBSession.rollback() raise e
def video_status_update(self, media_file, video_id=None): # If no ID is specified, update all associated videos! if video_id is None: video_ids = self.list_associated_video_ids(media_file) for video_id in video_ids: self.video_status_update(media_file, video_id) return v = self.client.get_video(video_id) encodings = self.client.get_encodings(video_id=video_id) # Only proceed if the video has completed all encoding steps successfully. if any(e['status'] != 'success' for e in encodings): return profiles = self.get_profile_ids_names() # For each successful encoding (and the original file), create a new MediaFile display_name, orig_ext = os.path.splitext(media_file.display_name) v['display_name'] = "(%s) %s%s" % ('original', display_name, v['extname']) url = PANDA_URL_PREFIX + simplejson.dumps(v) new_mf = add_new_media_file(media_file.media, url=url) for e in encodings: # Panda reports multi-bitrate http streaming encodings as .ts file # but the associated playlist is the only thing ipods, etc, can read. if e['extname'] == '.ts': e['extname'] = '.m3u8' e['display_name'] = "(%s) %s%s" % (profiles[e['profile_id']].replace('_', ' '), display_name, e['extname']) url = PANDA_URL_PREFIX + simplejson.dumps(e) new_mf = add_new_media_file(media_file.media, url=url) self.disassociate_video_id(media_file, v['id'])
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
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
def _import_video(self, entry): player_url = self._player_url_from_entry(entry) if not player_url: log.debug('Video Feed Error: No player URL? %s' % entry) return None if self._has_media_file_for(player_url): return None media = fetch_row(Media, u'new') media.author = Author(self.user.display_name, self.user.email_address) media.reviewed = True media.title = unicode(entry.media.title.text, "utf-8") if entry.media.description.text: encoded_description = unicode(entry.media.description.text, "utf-8") media.description = clean_xhtml(encoded_description) media.slug = get_available_slug(Media, media.title, media) if self.tags: media.set_tags(unicode(self.tags)) if self.categories: media.set_categories(self.categories) try: media_file = add_new_media_file(media, url=player_url) except StorageError, e: log.debug('Video Feed Error: Error storing video: %s at %s' \ % (e.message, player_url)) return None
def _get_media(self, unique): """Return the media/mediafiles required for the Helpers tests""" try: media = self._new_publishable_media(u'media-selection-%s' % unique, u'Media Selection Test (%s)' % unique) DBSession.add(media) media_files = {} for t in ['oga', 'ogv', 'm4a', 'm4v', 'flv', 'mp3', 'xml']: media_files[t] = add_new_media_file(media, None, u'http://fakesite.com/fakefile.%s' % t) media_files['youtube'] = add_new_media_file(media, None, u'http://www.youtube.com/watch?v=3RsbmjNLQkc') media.update_status() DBSession.commit() except SQLAlchemyError, e: DBSession.rollback() raise e
def get_videos_from_feed(feed): for entry in feed.entry: # Occasionally, there are issues with a video in a feed # not being available (region restrictions, etc) # If this happens, just move along. if not entry.media.player: log.debug('Video Feed Error: No player URL? %s' % entry) continue video_url = unicode(entry.media.player.url, "utf-8") if video_already_has_media_file(video_url): continue categories = kwargs.get('youtube.categories', None) tags = kwargs.get('youtube.tags', None) media = fetch_row(Media, u'new') user = request.environ['repoze.who.identity']['user'] media.author = Author(user.display_name, user.email_address) media.reviewed = True media.title = unicode(entry.media.title.text, "utf-8") if entry.media.description.text: encoded_description = unicode(entry.media.description.text, "utf-8") media.description = clean_xhtml(encoded_description) media.slug = get_available_slug(Media, media.title, media) if tags: media.set_tags(unicode(tags)) if categories: if not isinstance(categories, list): categories = [categories] media.set_categories(categories) try: media_file = add_new_media_file(media, url=video_url) except StorageError, e: log.debug('Video Feed Error: Error storing video: %s at %s' \ % e.message, video_url) continue if not has_thumbs(media): create_default_thumbs_for(media) media.title = media_file.display_name media.update_status() if auto_publish: media.reviewed = 1 media.encoded = 1 media.publishable = 1 media.created_on = datetime.now() media.modified_on = datetime.now() media.publish_on = datetime.now() DBSession.add(media) DBSession.flush()
def test_captioned_url_media(self): """Media with only subtitles attatched should be None type.""" try: for t in self.caption_types: media = self._new_publishable_media( u'caption-%s' % t, u'%s (Captioned)' % t.upper()) DBSession.add(media) media_file = add_new_media_file( media, None, u'http://fakesite.com/fakefile.%s' % t) media.update_status() DBSession.commit() assert media.type == None, \ "A Media object with only an .%s file associated was " \ "not labelled as a 'None' type; it was labelled %s" % \ (t, media.type) except SQLAlchemyError, e: DBSession.rollback() raise e
def test_captioned_url_media(self): """Media with only subtitles attatched should be None type.""" try: for t in self.caption_types: media = self._new_publishable_media(u'caption-%s' % t, u'%s (Captioned)' % t.upper()) DBSession.add(media) media_file = add_new_media_file(media, None, u'http://fakesite.com/fakefile.%s' % t) media.update_status() DBSession.commit() assert media.type == None, \ "A Media object with only an .%s file associated was " \ "not labelled as a 'None' type; it was labelled %s" % \ (t, media.type) except SQLAlchemyError, e: DBSession.rollback() raise e
def test_audio_description_url_media(self): """Media with only Audio Descriptions attatched should be None type.""" try: for t in self.audio_types: media = self._new_publishable_media(u'description-%s' % t, u'%s (Audio Description)' % t.upper()) DBSession.add(media) media_file = add_new_media_file(media, None, u'http://fakesite.com/fakefile.%s' % t) media_file.type = AUDIO_DESC media.update_status() DBSession.commit() assert media.type == None, \ "A Media object with only an Audio Description file " \ "associated was not labelled as a None type; it " \ "was labelled %s" % (t, media.type) except SQLAlchemyError, e: DBSession.rollback() raise e
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