Example #1
0
async def withTag(tags, id):
    id = str(UUID(id))
    #media = MediaWarehouse.getMetadata(id=id)
    media = Media.select(Media.id, Media.extension, Media.mainDescription, Media.additionalData, Media.created, Media.lastHit, Media.sourceType, Media.source).where(Media.id==id).get()
    '''url = MediaWarehouse.convertURL(media['id'])
    thumb = MediaWarehouse.convertThumbnailURL(media['id'])
    thumbRetina = MediaWarehouse.convertThumbnailRetinaURL(media['id'])
    pixiv = json.loads(media['additionalData'])['pixiv_v2']
    now = datetime.datetime.now().timestamp()
    popularTags, tagToCount = MediaWarehouse.popularTags(20)'''
    url = MediaWarehouse.convertURL(media.id)
    thumb = MediaWarehouse.convertThumbnailURL(media.id)
    thumbRetina = MediaWarehouse.convertThumbnailRetinaURL(media.id)
    pixiv = json.loads(media.additionalData)['pixiv_v2']
    now = datetime.datetime.now().timestamp()
    popularTags, tagToCount = MediaWarehouse.popularTags(20)
    return await render_template("pixiv_bytag.html",
    pixiv=pixiv,
    url=url,
    thumb=thumb,
    thumbRetina=thumbRetina,
    source=media.source,
    now=now,
    tags=tags.split(" ") if len(tags) > 0 else [""],
    popularTags=popularTags,
    tagToCount=tagToCount)
Example #2
0
class Tag(Model):
    name = CharField(default="")
    media = ForeignKeyField(Media, backref='tags')

    class Meta:
        database = db
        primary_key = False


def datetimeWrapper(date):
    return datetime.datetime.fromtimestamp(date) if isinstance(date,
                                                               float) else date


if __name__ == '__main__':
    #db.create_tables([Media, Tag])
    for media in tqdm(OldMedia.select(), total=OldMedia.select().count()):
        if Media.select().where(Media.id == media.id).exists():
            continue
        newmedia = Media.create(id=media.id,
                                extension=media.extension,
                                mainDescription=media.mainDescription,
                                additionalData=media.additionalData,
                                created=datetimeWrapper(media.created),
                                lastHit=datetimeWrapper(media.lastHit),
                                data=media.data,
                                thumbnail=media.thumbnail,
                                sourceType=media.sourceType,
                                source=media.source)
        for tag in OldTag.select(OldTag.name).where(OldTag.media == media):
            Tag.create(name=tag.name, media=newmedia)
Example #3
0
if __name__ == '__main__':
    '''# encoding
    for media_id in tqdm(Media.select(Media.id).where(Media.sourceType=='PIXIV'), total=Media.select(Media.id).where(Media.sourceType=='PIXIV').count()):
        media = Media.get(id=media_id)
        if len(media.datas) == 0:
            OriginalImage.create(media=media, data=HEICEncode(media._data))'''
    '''backupPath = "/CityLand02/PixivDump/"
    for media_id in tqdm(Media.select(Media.id).where(Media.sourceType=='PIXIV'), total=Media.select(Media.id).where(Media.sourceType=='PIXIV').count()):
        media = Media.get(id=media_id)
        if media._data is not None and len(media.datas)>0:
            with open(os.path.join(backupPath, "{}.{}".format(media.mainDescription, media.extension)), "wb") as img:
                img.write(media._data)
            media._data = None
            media.save()'''
    for media_id in tqdm(Media.select(Media.id).where(
            Media.sourceType == 'PIXIV' and Media.extension == 'png'),
                         total=Media.select(Media.id).where(
                             Media.sourceType == 'PIXIV'
                             and Media.extension == 'png').count()):
        media = Media.get(id=media_id)
        imgBuffer = io.BytesIO(media.thumbnail)
        imgObj = Image.open(imgBuffer)
        if imgObj.format in ['JPEG', 'jpeg']:
            continue
        imgObj = imgObj.convert('RGB')
        thumb = io.BytesIO()
        imgObj.save(thumb, format="jpeg", quality=85, optimize=True)
        media.thumbnail = thumb.getvalue()
        if media.thumbnail2x is not None:
            imgBuffer = io.BytesIO(media.thumbnail2x)
            imgObj = Image.open(imgBuffer)
Example #4
0
    degree = 0
    if hasattr(im_obj, '_getexif'):
        info = im_obj._getexif()
        ret = dict()
        degree_dict = {1: 0, 3: 180, 6: -90, 8: 90}
        if info:
            orientation = info.get(274, 0)
            degree = degree_dict.get(orientation, 0)
    return degree


if __name__ == '__main__':
    #sourceTypes = ["MIKU", "GANBARU", "YOGIOH_WAKE", "LOLI", "ERK"]
    sourceTypes = ["YUGIOH_WAKE"]
    for id in tqdm(
            Media.select(Media.id).where(Media.sourceType << sourceTypes),
            total=Media.select(
                Media.id).where(Media.sourceType << sourceTypes).count()):
        media = Media.get(id=id)
        imgBuffer = io.BytesIO(media.data)
        img = Image.open(imgBuffer)
        format = img.format
        img = img.rotate(get_rotate_degree(img))
        width, height = img.size
        twidth = min([width, 1600])
        theight = floor((twidth / width) * height + 0.5)
        img.thumbnail((twidth, theight), resample=Image.ANTIALIAS)
        thumb = io.BytesIO()
        img.save(thumb, format=format, quality=100)
        media.thumbnailRetina = thumb.getvalue()
Example #5
0
from MediaWarehouse import Media, MediaToTag, Tag, Tagv2
from tqdm import tqdm
import json
import gc

if __name__ == '__main__':
    '''for tag in tqdm(Tag.select().iterator(), total=Tag.select().count()):
        tagv2, _ = Tagv2.get_or_create(name=tag.name)
        MediaToTag.get_or_create(tag=tagv2, media_id=tag.media_id)'''
    for media in tqdm(Media.select(
            Media.id,
            Media.additionalData).where(Media.disabled == False).iterator(),
                      total=Media.select(
                          Media.id).where(Media.disabled == False).count()):
        if media.additionalData is not None and media.additionalData is not '':
            data = json.loads(media.additionalData)
            if 'pixiv_v2' not in data:
                print(media.id, media.additionalData)
                continue
            for tag in data['pixiv_v2']['tags']:
                tagv2, _ = Tagv2.get_or_create(name=tag)
                MediaToTag.get_or_create(tag=tagv2, media_id=media.id)