Beispiel #1
0
    def process_subimage (self, image_name, local_albumpath_rel,
        local_albumpath_abs):
        """Uses the given sub-image path and creates a AlbumImage model for it,
        including the creation of all necessary thumbnails and the check for
        whether the file is a Youtube video hook. Finally it appends the
        AlbumImg to the provided image list."""

        local_imagepath_abs = path.join(local_albumpath_abs, image_name)
        modified, _ = is_modified(
            local_imagepath_abs, True,
            pyntrest_config.MAX_AGE_OF_NEW_IMAGES_H,
            pyntrest_config.HIGHLIGHT_NEW_IMAGES)

        #######################################################################

        if pyntrest_config.IMAGE_FILE_PATTERN.match(
                                        local_imagepath_abs.lower()):

            static_fullsize_path_abs = path.join (
                    self.static_fullsize_path, local_albumpath_rel, image_name)
            static_thumb_path_abs = path.join (
                    self.static_ithumbs_path, local_albumpath_rel, image_name)

            # copy full size image to static folder
            if not path.exists(static_fullsize_path_abs):
                self.pil_handler.copy_with_rotation(local_imagepath_abs,
                    static_fullsize_path_abs)

            # calculate image size for masonry and copy to static folder
            width, height = (
                self.pil_handler.create_image_thumbnail_if_not_present(
                static_fullsize_path_abs, static_thumb_path_abs))

            latitude, longitude = (
                self.pil_handler.get_geo_coordinates( local_imagepath_abs ))
            geocoord = None
            if latitude and longitude:
                #print '{0}: {1}, {2}'.format(image_name, latitude, longitude)
                geocoord = '{0}, {1}'.format(latitude, longitude)

            # add image to template context
            albumimage = AlbumImage(type='img',
                location=path.join(local_albumpath_rel, image_name),
                title=image_name, width=width, height=height,
                modified=modified, geocoord=geocoord)
            return albumimage

        #######################################################################

        elif pyntrest_config.YOUTUBE_INI_FILE_PATTERN.match(
                        local_imagepath_abs):

            youtube_id = read_youtube_ini_file (local_imagepath_abs)
            # .75 is the fixed Youtube thumbnail width to height ratio
            thumb_height = int(
                float (pyntrest_config.IMAGE_THUMB_WIDTH) * 0.75)
            albumimage = AlbumImage(type='you', location=path.join(
                        local_albumpath_rel, image_name), title=image_name,
                        width=pyntrest_config.IMAGE_THUMB_WIDTH,
                        height=thumb_height, youtubeid=youtube_id,
                        modified=modified)
            return albumimage

        #######################################################################

        elif (pyntrest_config.TEXT_MD_FILE_PATTERN.match(
                                local_imagepath_abs.lower()) and
              not (pyntrest_config.INTRO_MD_FILE_PATTERN.match(
                                local_imagepath_abs.lower()))):

            html_content, title = get_html_content(local_imagepath_abs)

            divid="".join(choice('abcdefghijklmnopqrstuvwxyz') for _ in range(16))

            albumimage = AlbumImage(type='txt', location=path.join(
                        local_albumpath_rel, image_name), title=title,
                        width=pyntrest_config.IMAGE_THUMB_WIDTH,
                        height=pyntrest_config.IMAGE_THUMB_HEIGHT/2,
                        modified=modified, text_content=html_content,
                        divid=divid)
            return albumimage
Beispiel #2
0
    def process_subalbum (self, subalbums, subalbum_name, local_albumpath_rel,
        local_albumpath_abs):
        """Uses the given sub-album name and creates a Album model for it,
        including the search for optional descriptions and album covers and
        the creation of all necessary thumbnails. Finally it appends the Album
        to the provided sub-album list."""

        local_subalbumpath_abs = path.join(local_albumpath_abs, subalbum_name)
        modified, lastmodified = is_modified(
            local_subalbumpath_abs, False,
            pyntrest_config.MAX_AGE_OF_NEW_IMAGES_H,
            pyntrest_config.HIGHLIGHT_NEW_IMAGES,
            pyntrest_config.IMAGE_FILE_PATTERN)
        meta_title, meta_description, meta_cover, _, _, _, _ = (
            read_optional_album_metadata (local_subalbumpath_abs,
                            pyntrest_config.META_INI_FILE_PATTERN))

        local_subalbumcover_abs = None

        # find and set cover image

        # If sub album cover manually set..
        if meta_cover:
            # Check for existence..
            cover_candidate = path.join(local_subalbumpath_abs, meta_cover)
            # on windows we also allow uncased matches (or .. lower())
            if path.exists(cover_candidate) or path.exists(cover_candidate.lower()):
                local_subalbumcover_abs = cover_candidate

        # if no album cover was set manually or if it did not exist...
        if not local_subalbumcover_abs:
            # ... get first in folder
            for cover_candidate in listdir(local_subalbumpath_abs):
                if pyntrest_config.IMAGE_FILE_PATTERN.match(
                    cover_candidate.lower()):
                    local_subalbumcover_abs = path.join(
                    local_subalbumpath_abs,
                    cover_candidate)
                    break

        subalbum_webpath = path.join(local_albumpath_rel, subalbum_name)
        subalbum_webpath = '/' + sub('\\\\', '/', subalbum_webpath)

        # If still no album cover was found then this is an empty album hence
        # we need to let the template use a default image
        if not local_subalbumcover_abs:

            # setup template context
            subalbum = Album(title=meta_title, description=meta_description,
                      path=subalbum_webpath,
                      width=pyntrest_config.IMAGE_THUMB_WIDTH,
                      height=pyntrest_config.IMAGE_THUMB_HEIGHT, cover=None,
                      modified=modified, last_modified=lastmodified)

        else:
            # otherwise prepare it for static serving
            image_basename = path.basename(local_subalbumcover_abs)
            local_thumbnail_folder_abs = path.join (
                self.static_athumbs_path, local_albumpath_rel, subalbum_name)
            thumbnail_webpath = path.join (local_albumpath_rel, subalbum_name,
                                           image_basename)
            target_file = path.join(local_thumbnail_folder_abs, image_basename)
            mkdirs(local_thumbnail_folder_abs)
            self.pil_handler.create_album_thumbnail_if_not_present(
                local_subalbumcover_abs, target_file)

            # setup template context
            subalbum = Album(   title=meta_title,
                                description=meta_description,
                                path=subalbum_webpath,
                                width=pyntrest_config.IMAGE_THUMB_WIDTH,
                                height=pyntrest_config.IMAGE_THUMB_HEIGHT,
                                cover=thumbnail_webpath,
                                modified=modified,
                                last_modified=lastmodified)

        # append subalbum to context
        subalbums.append(subalbum)