def download_thread(target,directory,app):
    try:
        app.event_queue.put({'type':'progress', 'data':(0,1)})
        app.event_queue.put({'type':'status', 'data':"Getting data..."})
        session_id=pixivdl.get_session_config()
        p=Pixiv(session_id)
        works=p.get_works_all(target)
        for i in range(len(works)):
            work=works[i]
            app.event_queue.put({'type':'progress', 'data':(i,len(works))})
            pixivdl.download_work(work,directory)
            if app.cancel_download.is_set():
                app.cancel_download.clear()
                app.event_queue.put({'type':'state', 'data':"waiting"})
                app.event_queue.put({'type':'status', 'data':"Download cancelled"})
                print "\nCancelled"
                return 0
        pickle.dump(works,open(directory+"/metadata.pickle",'wb'))
        print ''
        app.event_queue.put({'type':'function', 'data':app.progress_indicator.complete})
        app.event_queue.put({'type':'state', 'data':"waiting"})
    except:
        app.event_queue.put({'type':'error', 'data':"An unknown error occured!"})
        app.event_queue.put({'type':'status', 'data':"Unknown error occured"})
        app.event_queue.put({'type':'state', 'data':"waiting"})
Exemple #2
0
def main():
    print_welcome()
    check_version()
    if len(sys.argv)<2:
        print_usage()
        sys.exit()
    artist_id=sys.argv[1]
    session_id=get_session_config()
    p=Pixiv(session_id)
    works=p.get_works_all(artist_id)
    if len(sys.argv)==3:
        directory=sys.argv[2]
    else:
        if works:
            directory = "./img/{}-(ID_{})".format(works[0].artist_nickname,artist_id)
            try:
                os.makedirs(directory)
                os.makedirs(directory)
            except OSError as exception:
                if exception.errno != errno.EEXIST:
                    raise
        else:
            print 'This request is empty.'
            sys.exit()
    for work in works:
        download_work(work,directory)
    pickle.dump(works,open(directory+"/metadata.pickle",'wb'))
    print ''
def main():
    print_welcome()
    check_version()
    if len(sys.argv)<2:
        print_usage()
        sys.exit()
    artist_id=sys.argv[1]
    if len(sys.argv)==3:
        directory=sys.argv[2]
    else:
        directory='.'
    session_id=get_session_config()
    p=Pixiv(session_id)
    works=p.get_works_all(artist_id)
    for work in works:
        download_work(work,directory)
    pickle.dump(works,open(directory+"/metadata.pickle",'wb'))
    print ''