Exemplo n.º 1
0
def get(url,**argv):
    url = detect_album_path(url)
    if url:
        album = HupuAlbum(url)
        # login
        if argv:
            if album.login(argv['username'],argv['password']):
                print "登录成功"
            else:
                print "登陆失败,请检查用户名和密码"
                return 0
        # get album info
        info = album.get_info()
        album.title = album.title.encode('utf-8') # str encode
        if info.state == 302:
            print "请确认,在没有登陆的情况下依旧可以访问此相册吗?"
            return 0
        elif info.state == 0:
            print "抓不到图片"
            return 0
        else:            
            print '《%s》此相册有%d张、%d页' %(album.title,album.pics,album.pages)
            album.down()
            print '抓取到%d张图片' %(album.get_pics)
            return album
    else:
        print '此URL不能识别\n请输入单个相册的页面地址!'
        return 0
Exemplo n.º 2
0
def url():
    url = request.form['url']
    page = detect_album_path(url)
    if page:
        start = time.time()
        album = HupuAlbum(url)
        album.save()
        spend = time.time() - start
        # save info
        imgBase64=''
        if album.stat==200:
            # store cover
            cover = album.session.get(album.cover).content
            ext = album.cover.split('.')[-1]
            cover_id = store_img(app.config['COVERS'],cover,ext)
            imgBase64 = img_base64(cover,ext)
            # store the data
            g.db.update(album.url,album.title,cover_id,album.pics,album.get_pics,album.pics_urls)
        return jsonify(
            stat = album.stat,
            homepage = album.url,
            title = album.title,
            cover = album.cover,
            pics = album.pics,
            get_pics = album.get_pics,
            pics_urls = album.pics_urls,
            imgBase64 = imgBase64,
            time = spend
        )
    else:
        return jsonify(stat = 2)
Exemplo n.º 3
0
def get(url, **argv):
    url = detect_album_path(url)
    if url:
        album = HupuAlbum(url)
        # login
        if argv:
            if album.login(argv['username'], argv['password']):
                print "登录成功"
            else:
                print "登陆失败,请检查用户名和密码"
                return 0
        # get album info
        info = album.get_info()
        album.title = album.title.encode('utf-8')  # str encode
        if info.state == 302:
            print "请确认,在没有登陆的情况下依旧可以访问此相册吗?"
            return 0
        elif info.state == 0:
            print "抓不到图片"
            return 0
        else:
            print '《%s》此相册有%d张、%d页' % (album.title, album.pics, album.pages)
            album.down()
            print '抓取到%d张图片' % (album.get_pics)
            return album
    else:
        print '此URL不能识别\n请输入单个相册的页面地址!'
        return 0
Exemplo n.º 4
0
def get(url, username, password):
    url = detect_album_path(url)
    if url:
        album = HupuAlbum(url)
        # login
        if album.login(username, password):
            print "登录成功"
        else:
            tips = {
                302: "请确认登录用户可以访问此相册吗?",
                403: "登陆失败,请检查用户名和密码",
                501: "暂不支持加密相册"
            }
            print tips[album.state] # tips
            return None
        # get album info
        info = album.get_info()
        album.title = album.title.encode('utf-8') # str encode
        if info.state == 0:
            print "《%s》是空相册抓不到图片" %album.title
            print album.homepage
            return None
        else:            
            print '《%s》此相册有%d张、%d页' %(album.title,album.pics,album.pages)
            album.down()
            print '抓取到%d张图片' %(album.get_pics)
            return album
    else:
        print '此URL不能识别\n请输入单个相册的页面地址!'
        return None
Exemplo n.º 5
0
def url():
    url = request.form['url']
    page = detect_album_path(url)
    if page:
        start = time.time()
        album = HupuAlbum(url)
        album.save()
        spend = time.time() - start
        # save info
        imgBase64 = ''
        if album.stat == 200:
            # store cover
            cover = album.session.get(album.cover).content
            ext = album.cover.split('.')[-1]
            cover_id = store_img(app.config['COVERS'], cover, ext)
            imgBase64 = img_base64(cover, ext)
            # store the data
            g.db.update(album.url, album.title, cover_id, album.pics,
                        album.get_pics, album.pics_urls)
        return jsonify(stat=album.stat,
                       homepage=album.url,
                       title=album.title,
                       cover=album.cover,
                       pics=album.pics,
                       get_pics=album.get_pics,
                       pics_urls=album.pics_urls,
                       imgBase64=imgBase64,
                       time=spend)
    else:
        return jsonify(stat=2)
Exemplo n.º 6
0
def get_album(url, username='', password=''):
    url = detect_album_path(url)
    if not url:
        print('此URL不能识别\n请输入单个相册的页面地址!')
        return None
    if not username:
        cookie = Cookie()
        try:
            username = cookie.config.sections()[0]
        except IndexError:
            username, password = enter_name_pwd()
        del cookie
    album = HupuAlbum(url)
    if album.login(username, password):
        print("登录成功")
    else:
        tips = {
            302: "请确认登录用户可以访问此相册吗?",
            403: "登陆失败,请检查用户名和密码",
            501: "暂不支持加密相册"
        }
        print(tips[album.state])  # tips
        return None
    # get album info
    info = album.get_info()
    album.title = album.title.encode('utf-8')  # str encode
    if info.state == 0:
        print("《%s》是空相册抓不到图片" % album.title)
        print(album.homepage)
        return None
    else:
        print('《%s》此相册有%d张、%d页' % (album.title, album.pics, album.pages))
        album.down()
        print('抓取到%d张图片' % album.get_pics)
        return album
Exemplo n.º 7
0
def get():
    start = time.time()
    url = request.form['url']
    if not detect_album_path(url):
        return jsonify(state=-1)
    user, pwd = LUSER, LPWD
    uid = session.get('uid')
    if uid:
        g.cur.execute("""SELECT `uid` FROM `users` where `uid` = %s""",
                      (uid, ))
        if g.cur.fetchone():
            user = request.form.get('user')
            pwd = request.form.get('password')
            if not user or not pwd:
                user, pwd = LUSER, LPWD
        else:
            return jsonify(state=4)  # uid non-existent
    # get pics
    album = HupuAlbum(url)
    if not album.login(user, pwd):
        return jsonify(state=album.state)
    album.save()
    coverimg = ''  # album.cover img to base64
    if album.state == 1:
        # store cover img with base 64
        # cover = album.session.get(album.cover).content
        # ext = album.cover.split('.')[-1]
        # coverimg = img_base64(cover,ext)
        # store cover img with url
        coverimg = album.cover
        g.cur.execute(
            ''' INSERT INTO  `albums` (`url`,`title`,`cover`,`pics`,`getPics`,`picsUrls`) VALUES (%s,%s,%s,%s,%s,%s)\
            ON DUPLICATE KEY UPDATE `title`=%s,`cover`=%s,`pics`=%s,`getPics`=%s,`picsUrls`=%s,`times`=`times`+1 ''',
            (album.homepage, album.title, coverimg, album.pics, album.get_pics,
             album.pics_urls, album.title, coverimg, album.pics,
             album.get_pics, album.pics_urls))
        g.db.commit()
    return jsonify(state=album.state,
                   homepage=album.homepage,
                   title=album.title,
                   cover=coverimg,
                   pics=album.pics,
                   get_pics=album.get_pics,
                   pics_urls=album.pics_urls,
                   time=time.time() - start)
Exemplo n.º 8
0
def get():
    start = time.time()
    url = request.form['url']
    if not detect_album_path(url):
        return jsonify(state=-1)
    user, pwd = LUSER, LPWD
    uid = session.get('uid')
    if uid:
        g.cur.execute("""SELECT `uid` FROM `users` where `uid` = %s""", (uid,))
        if g.cur.fetchone():
            user = request.form.get('user')
            pwd = request.form.get('password')
            if not user or not pwd:
                user, pwd = LUSER, LPWD
        else:
            return jsonify(state=4)  # uid non-existent
    # get pics
    album = HupuAlbum(url)
    if not album.login(user, pwd):
        return jsonify(state=album.state)
    album.save()
    coverimg = ''  # album.cover img to base64
    if album.state == 1:
        # store cover img with base 64
        # cover = album.session.get(album.cover).content
        # ext = album.cover.split('.')[-1]
        # coverimg = img_base64(cover,ext)
        # store cover img with url
        coverimg = album.cover
        g.cur.execute(''' INSERT INTO  `albums` (`url`,`title`,`cover`,`pics`,`getPics`,`picsUrls`) VALUES (%s,%s,%s,%s,%s,%s)\
            ON DUPLICATE KEY UPDATE `title`=%s,`cover`=%s,`pics`=%s,`getPics`=%s,`picsUrls`=%s,`times`=`times`+1 ''',
                      (album.homepage, album.title, coverimg, album.pics, album.get_pics, album.pics_urls,
                       album.title, coverimg, album.pics, album.get_pics, album.pics_urls))
        g.db.commit()
    return jsonify(
        state=album.state,
        homepage=album.homepage,
        title=album.title,
        cover=coverimg,
        pics=album.pics,
        get_pics=album.get_pics,
        pics_urls=album.pics_urls,
        time=time.time() - start
    )