-
Notifications
You must be signed in to change notification settings - Fork 254
/
PixivUtil2.py
1808 lines (1587 loc) · 77.2 KB
/
PixivUtil2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# flake8: noqa:E501,E128,E127
import codecs
import datetime
import gc
import getpass
import os
import platform
import re
import subprocess
import sys
import traceback
from optparse import OptionParser
import colorama
from colorama import Back, Fore, Style
import PixivArtistHandler
import PixivBatchHandler
import PixivBookmarkHandler
import PixivBrowserFactory
import PixivConfig
import PixivConstant
import PixivFanboxHandler
import PixivHelper
import PixivImageHandler
import PixivListHandler
import PixivModelFanbox
import PixivNovelHandler
import PixivRankingHandler
import PixivSketchHandler
import PixivTagsHandler
from PixivDBManager import PixivDBManager
from PixivException import PixivException
from PixivTags import PixivTags
colorama.init()
DEBUG_SKIP_PROCESS_IMAGE = False
DEBUG_SKIP_DOWNLOAD_IMAGE = False
if platform.system() == "Windows":
# patch getpass.getpass() for windows to show '*'
def win_getpass_with_mask(prompt='Password: ', stream=None):
"""Prompt for password with echo off, using Windows getch()."""
if sys.stdin is not sys.__stdin__:
return getpass.fallback_getpass(prompt, stream)
import msvcrt
for c in prompt:
msvcrt.putch(c.encode())
pw = ""
while 1:
c = msvcrt.getch().decode()
if c == '\r' or c == '\n':
break
if c == '\003':
raise KeyboardInterrupt
if c == '\b':
pw = pw[:-1]
print("\b \b", end="")
else:
pw = pw + c
print("*", end="")
msvcrt.putch('\r'.encode())
msvcrt.putch('\n'.encode())
return pw
getpass.getpass = win_getpass_with_mask
platform_encoding = 'utf-8-sig'
else:
platform_encoding = 'utf-8'
script_path = PixivHelper.module_path()
op = ''
ERROR_CODE = 0
UTF8_FS = None
__config__ = PixivConfig.PixivConfig()
configfile = "config.ini"
__dbManager__ = None
__br__: PixivBrowserFactory.PixivBrowser = None
__blacklistTags = list()
__suppressTags = list()
__log__ = None
__errorList = list()
__blacklistMembers = list()
__blacklistTitles = list()
__valid_options = ()
__seriesDownloaded = []
start_iv = False
dfilename = ""
def header():
PADDING = 60
print("┌" + "".ljust(PADDING - 2, "─") + "┐")
print("│ " + Fore.YELLOW + Back.BLACK + Style.BRIGHT + f"PixivDownloader2 version {PixivConstant.PIXIVUTIL_VERSION}".ljust(PADDING - 3, " ") + Style.RESET_ALL + "│")
print("│ " + Fore.CYAN + Back.BLACK + Style.BRIGHT + PixivConstant.PIXIVUTIL_LINK.ljust(PADDING - 3, " ") + Style.RESET_ALL + "│")
print("│ " + Fore.YELLOW + Back.BLACK + Style.BRIGHT + f"Donate at {Fore.CYAN}{Style.BRIGHT}{PixivConstant.PIXIVUTIL_DONATE}".ljust(PADDING + 6, " ") + Style.RESET_ALL + "│")
print("└" + "".ljust(PADDING - 2, "─") + "┘")
def get_start_and_end_page_from_options(options):
''' Try to parse start and end page from options.'''
page_num = 1
if options.start_page is not None:
try:
page_num = int(options.start_page)
print(f"Start Page = {page_num}")
except BaseException:
print(f"Invalid page number: {options.start_page}")
raise
end_page_num = 0
if options.end_page is not None:
try:
end_page_num = int(options.end_page)
print(f"End Page = {end_page_num}")
except BaseException:
print(f"Invalid end page number: {options.end_page}")
raise
elif options.number_of_pages is not None:
end_page_num = options.number_of_pages
else:
end_page_num = __config__.numberOfPage
if page_num > end_page_num and end_page_num != 0:
print(f"Start Page ({page_num}) is bigger than End Page ({end_page_num}), assuming as page count ({page_num + end_page_num}).")
end_page_num = page_num + end_page_num
return page_num, end_page_num
def get_list_file_from_options(options, default_list_file):
list_file_name = default_list_file
if options.list_file is not None:
if os.path.isabs(options.list_file):
test_file_name = options.list_file
else:
test_file_name = __config__.downloadListDirectory + os.sep + options.list_file
test_file_name = os.path.abspath(test_file_name)
if os.path.exists(test_file_name):
list_file_name = test_file_name
else:
PixivHelper.print_and_log("warn", f"The given list file [{test_file_name}] doesn't exists, using default list file [{list_file_name}].")
return list_file_name
def menu():
PADDING = 60
set_console_title()
header()
print(Style.BRIGHT + '── Pixiv '.ljust(PADDING, "─") + Style.RESET_ALL)
print(' 1. Download by member_id')
print(' 2. Download by image_id')
print(' 3. Download by tags')
print(' 4. Download from list')
print(' 5. Download from followed artists (/bookmark.php?type=user)')
print(' 6. Download from bookmarked images (/bookmark.php)')
print(' 7. Download from tags list')
print(' 8. Download new illust from bookmarked members (/bookmark_new_illust.php)')
print(' 9. Download by Title/Caption')
print(' 10. Download by Tag and Member Id')
print(' 11. Download Member Bookmark (/bookmark.php?id=)')
print(' 12. Download by Group Id')
print(' 13. Download by Manga Series Id')
print(' 14. Download by Novel Id')
print(' 15. Download by Novel Series Id')
print(' 16. Download by Rank')
print(' 17. Download by Rank R-18')
print(' 18. Download by New Illusts')
print(' 19. Download by Unlisted image_id')
print(Style.BRIGHT + '── FANBOX '.ljust(PADDING, "─") + Style.RESET_ALL)
print(' f1. Download from supporting list (FANBOX)')
print(' f2. Download by artist/creator id (FANBOX)')
print(' f3. Download by post id (FANBOX)')
print(' f4. Download from following list (FANBOX)')
print(' f5. Download from custom list (FANBOX)')
print(' f6. Download Pixiv by FANBOX Artist ID')
print(Style.BRIGHT + '── Sketch '.ljust(PADDING, "─") + Style.RESET_ALL)
print(' s1. Download by creator id (Sketch)')
print(' s2. Download by post id (Sketch)')
print(Style.BRIGHT + '── Batch Download '.ljust(PADDING, "─") + Style.RESET_ALL)
print(' b. Batch Download from batch_job.json (experimental)')
print(Style.BRIGHT + '── Others '.ljust(PADDING, "─") + Style.RESET_ALL)
print(' d. Manage database')
print(' l. Export local database.')
print(' e. Export online followed artist.')
print(' m. Export online other\'s followed artist.')
print(' p. Export online image bookmarks.')
print(' i. Import list file')
print(' u. Ugoira re-encode')
print(' r. Reload config.ini')
print(' c. Print config.ini')
print(' x. Exit')
read_lists()
sel = input('Input: ').rstrip("\r")
return sel
def menu_download_by_member_id(opisvalid, args, options):
__log__.info('Member id mode (1).')
current_member = 1
page = 1
end_page = 0
include_sketch = False
member_ids = list()
if opisvalid and len(args) > 0:
include_sketch = options.include_sketch
if include_sketch:
print("Including Pixiv Sketch.")
(page, end_page) = get_start_and_end_page_from_options(options)
for member_id in args:
if member_id.isdigit():
member_ids.append(int(member_id))
else:
print(f"Possible invalid member id = {member_id}")
else:
member_ids = input('Member ids: ').rstrip("\r")
(page, end_page) = PixivHelper.get_start_and_end_number(total_number_of_page=options.number_of_pages)
skipSketchPrompt = __config__.defaultSketchOption
if skipSketchPrompt.lower() == 'y':
print("Including Pixiv Sketch.")
include_sketch = True
elif skipSketchPrompt.lower() == 'n':
print("Excluding Pixiv Sketch.")
else:
include_sketch_ask = input('Include Pixiv Sketch [y/n, default is no]? ').rstrip("\r") or 'n'
if include_sketch_ask.lower() == 'y':
include_sketch = True
member_ids = PixivHelper.get_ids_from_csv(member_ids)
PixivHelper.print_and_log('info', f"Member IDs: {member_ids}")
for member_id in member_ids:
try:
prefix = f"[{current_member} of {len(member_ids)}] "
PixivArtistHandler.process_member(sys.modules[__name__],
__config__,
member_id,
page=page,
end_page=end_page,
title_prefix=prefix)
# Issue #793
if include_sketch:
# fetching artist token...
(artist_model, _) = __br__.getMemberPage(member_id)
prefix = f"[{current_member} ({artist_model.artistToken}) of {len(member_ids)}] "
PixivSketchHandler.process_sketch_artists(sys.modules[__name__],
__config__,
artist_model.artistToken,
page,
end_page,
title_prefix=prefix)
current_member = current_member + 1
except PixivException as ex:
PixivHelper.print_and_log('error', f"Member ID: {member_id} is not valid")
global ERROR_CODE
ERROR_CODE = -1
continue
def menu_download_by_member_bookmark(opisvalid, args, options):
__log__.info('Member Bookmark mode (11).')
page = 1
end_page = 0
i = 0
current_member = 1
if opisvalid and len(args) > 0:
valid_ids = list()
for member_id in args:
print("%d/%d\t%f %%" % (i, len(args), 100.0 * i / float(len(args))))
i += 1
try:
test_id = int(member_id)
valid_ids.append(test_id)
except BaseException:
PixivHelper.print_and_log('error', f"Member ID: {member_id} is not valid")
global ERROR_CODE
ERROR_CODE = -1
continue
if __br__._myId in valid_ids:
PixivHelper.print_and_log('error', f"Member ID: {__br__._myId} is your own id, use option 6 instead.")
for mid in valid_ids:
prefix = f"[{current_member} of {len(valid_ids)}] "
PixivArtistHandler.process_member(sys.modules[__name__],
__config__,
mid,
page=page,
end_page=end_page,
bookmark=True,
tags=None,
title_prefix=prefix)
current_member = current_member + 1
else:
member_id = input('Member id: ').rstrip("\r")
tags = input('Filter Tags: ').rstrip("\r")
(page, end_page) = PixivHelper.get_start_and_end_number(total_number_of_page=options.number_of_pages)
if __br__._myId == int(member_id):
PixivHelper.print_and_log('error', f"Member ID: {member_id} is your own id, use option 6 instead.")
else:
PixivArtistHandler.process_member(sys.modules[__name__],
__config__,
member_id.strip(),
page=page,
end_page=end_page,
bookmark=True,
tags=tags)
def menu_download_by_image_id(opisvalid, args, options):
__log__.info('Image id mode (2).')
if opisvalid and len(args) > 0:
for image_id in args:
try:
test_id = int(image_id)
PixivImageHandler.process_image(sys.modules[__name__],
__config__,
artist=None,
image_id=test_id,
useblacklist=False)
except BaseException:
PixivHelper.print_and_log('error', f"Image ID: {image_id} is not valid")
global ERROR_CODE
ERROR_CODE = -1
continue
else:
image_ids = input('Image ids: ').rstrip("\r")
image_ids = PixivHelper.get_ids_from_csv(image_ids)
for image_id in image_ids:
PixivImageHandler.process_image(sys.modules[__name__],
__config__,
artist=None,
image_id=int(image_id),
useblacklist=False)
def menu_download_by_tags(opisvalid, args, options):
__log__.info('Tags mode (3).')
page = 1
end_page = 0
start_date = None
end_date = None
bookmark_count = None
# oldest_first = False
sort_order = 'date_d'
wildcard = False
type_mode = "a"
if opisvalid and len(args) > 0:
wildcard = options.use_wildcard_tag
sort_order = options.tag_sort_order
start_date = options.start_date
end_date = options.end_date
bookmark_count = options.bookmark_count_limit
(page, end_page) = get_start_and_end_page_from_options(options)
tags = " ".join(args)
else:
tags = input('Tags: ').rstrip("\r")
bookmark_count = input('Bookmark Count: ').rstrip("\r") or None
wildcard = input('Use Partial Match (s_tag) [y/n, default is no]: ').rstrip("\r") or 'n'
if wildcard.lower() == 'y':
wildcard = True
else:
wildcard = False
# Issue #834
if __br__._isPremium:
msg = 'Sorting Order [date_d|date|popular_d|popular_male_d|popular_female_d]? '
sort_order = input(msg).rstrip("\r") or 'date_d'
else:
oldest_first = input('Oldest first[y/n, default is no]: ').rstrip("\r") or 'n'
if oldest_first.lower() == 'y':
sort_order = 'date'
(page, end_page) = PixivHelper.get_start_and_end_number(total_number_of_page=options.number_of_pages)
(start_date, end_date) = PixivHelper.get_start_and_end_date()
while True:
type_mode = input("Search type [a-all|i-Illustration and Ugoira|m-manga, default is all: ").rstrip("\r") or "a"
if type_mode in {'a', 'i', 'm'}:
break
else:
print("Valid values are 'a', 'i', or 'm'.")
if bookmark_count is not None and bookmark_count != -1 and len(bookmark_count) > 0:
bookmark_count = int(bookmark_count)
PixivTagsHandler.process_tags(sys.modules[__name__],
__config__,
tags.strip(),
page=page,
end_page=end_page,
wild_card=wildcard,
start_date=start_date,
end_date=end_date,
use_tags_as_dir=__config__.useTagsAsDir,
bookmark_count=bookmark_count,
sort_order=sort_order,
type_mode=type_mode)
def menu_download_by_title_caption(opisvalid, args, options):
__log__.info('Title/Caption mode (9).')
page = 1
end_page = 0
start_date = None
end_date = None
if opisvalid and len(args) > 0:
start_date = options.start_date
end_date = options.end_date
(page, end_page) = get_start_and_end_page_from_options(options)
tags = " ".join(args)
else:
tags = input('Title/Caption: ').rstrip("\r")
(page, end_page) = PixivHelper.get_start_and_end_number(total_number_of_page=options.number_of_pages)
(start_date, end_date) = PixivHelper.get_start_and_end_date()
PixivTagsHandler.process_tags(sys.modules[__name__],
__config__,
tags.strip(),
page=page,
end_page=end_page,
wild_card=False,
title_caption=True,
start_date=start_date,
end_date=end_date,
use_tags_as_dir=__config__.useTagsAsDir)
def menu_download_by_tag_and_member_id(opisvalid, args, options):
__log__.info('Tag and MemberId mode (10).')
member_id = 0
tags = None
page = 1
end_page = 0
if opisvalid and len(args) >= 2:
(page, end_page) = get_start_and_end_page_from_options(options)
try:
member_id = int(args[0])
except BaseException:
PixivHelper.print_and_log('error', f"Member ID: {member_id} is not valid")
global ERROR_CODE
ERROR_CODE = -1
return
tags = " ".join(args[1:])
PixivHelper.safePrint(f"Looking tags: {tags} from memberId: {member_id}")
else:
member_id = input('Member Id: ').rstrip("\r")
tags = input('Tag : ').rstrip("\r")
(page, end_page) = PixivHelper.get_start_and_end_number(total_number_of_page=options.number_of_pages)
PixivTagsHandler.process_tags(sys.modules[__name__],
__config__,
tags.strip(),
page=page,
end_page=end_page,
use_tags_as_dir=__config__.useTagsAsDir,
member_id=int(member_id))
def menu_download_from_list(opisvalid, args, options):
__log__.info('Batch mode from list (4).')
global op
global __config__
include_sketch = False
list_file_name = __config__.downloadListDirectory + os.sep + 'list.txt'
tags = None
if opisvalid:
include_sketch = options.include_sketch
list_file_name = get_list_file_from_options(options, list_file_name)
# get one tag from input parameter
if len(args) > 0:
tags = args[0]
else:
test_tags = input('Tag : ').rstrip("\r")
include_sketch_ask = input('Include Pixiv Sketch [y/n, default is no]? ').rstrip("\r") or 'n'
if include_sketch_ask.lower() == 'y':
include_sketch = True
if len(test_tags) > 0:
tags = test_tags
PixivListHandler.process_list(sys.modules[__name__],
__config__,
list_file_name=list_file_name,
tags=tags,
include_sketch=include_sketch)
def menu_download_from_online_user_bookmark(opisvalid, args, options):
__log__.info('User Bookmarked Artist mode (5).')
start_page = 1
end_page = 0
hide = 'n'
bookmark_count = None
if opisvalid:
if options.bookmark_flag is not None:
hide = options.bookmark_flag.lower()
if hide not in ('y', 'n', 'o'):
PixivHelper.print_and_log("error", f"Invalid args for bookmark_flag: {args}, valid values are [y/n/o].")
return
(start_page, end_page) = get_start_and_end_page_from_options(options)
bookmark_count = options.bookmark_count_limit
else:
arg = input("Include Private bookmarks [y/n/o, default is no]: ").rstrip("\r") or 'n'
arg = arg.lower()
if arg == 'y' or arg == 'n' or arg == 'o':
hide = arg
else:
print("Invalid args: ", arg)
return
(start_page, end_page) = PixivHelper.get_start_and_end_number(total_number_of_page=options.number_of_pages)
bookmark_count = input('Bookmark Count: ').rstrip("\r") or None
if bookmark_count is not None and bookmark_count != -1 and len(bookmark_count) > 0:
bookmark_count = int(bookmark_count)
PixivBookmarkHandler.process_bookmark(sys.modules[__name__],
__config__,
hide,
start_page,
end_page,
bookmark_count=bookmark_count)
def menu_download_from_online_image_bookmark(opisvalid, args, options):
__log__.info("User's Image Bookmark mode (6).")
start_page = 1
end_page = 0
hide = 'n'
tag = ''
use_image_tag = False
if opisvalid:
if len(args) > 0:
tag = args[0]
(start_page, end_page) = get_start_and_end_page_from_options(options)
if options.bookmark_flag is not None:
hide = options.bookmark_flag.lower()
if hide not in ('y', 'n', 'o'):
PixivHelper.print_and_log("error", f"Invalid args for bookmark_flag: {args}, valid values are [y/n/o].")
return
use_image_tag = options.use_image_tag
else:
hide = input("Include Private bookmarks [y/n/o, default is no]: ").rstrip("\r") or 'n'
hide = hide.lower()
if hide not in ('y', 'n', 'o'):
print("Invalid args: ", hide)
return
tag = input("Tag (press enter for all images): ").rstrip("\r") or ''
(start_page, end_page) = PixivHelper.get_start_and_end_number(total_number_of_page=options.number_of_pages)
if tag != '':
use_image_tag = input("Use Image Tags as the filter [y/n, default is no]? ").rstrip("\r") or 'n'
use_image_tag = use_image_tag.lower()
use_image_tag = True if use_image_tag == 'y' else False
PixivBookmarkHandler.process_image_bookmark(sys.modules[__name__],
__config__,
hide=hide,
start_page=start_page,
end_page=end_page,
tag=tag,
use_image_tag=use_image_tag)
def menu_download_from_tags_list(opisvalid, args, options):
__log__.info('Taglist mode (7).')
page = 1
end_page = 0
sort_order = 'date_d'
wildcard = False
bookmark_count = None
start_date = None
end_date = None
if opisvalid:
filename = get_list_file_from_options(options=options, default_list_file='./tags.txt')
sort_order = options.tag_sort_order
wildcard = options.use_wildcard_tag
start_date = options.start_date
end_date = options.end_date
(page, end_page) = get_start_and_end_page_from_options(options)
bookmark_count = options.bookmark_count_limit
else:
filename = input("Tags list filename [tags.txt]: ").rstrip("\r") or './tags.txt'
wildcard = input('Use Wildcard[y/n, default is no]: ').rstrip("\r") or 'n'
if wildcard.lower() == 'y':
wildcard = True
else:
wildcard = False
# Issue #834
if __br__._isPremium:
msg = 'Sorting Order [date_d|date|popular_d|popular_male_d|popular_female_d, default is date_d]? '
sort_order = input(msg).rstrip("\r") or 'date_d'
else:
oldest_first = input('Oldest first [y/n, default is no]: ').rstrip("\r") or 'n'
if oldest_first.lower() == 'y':
sort_order = 'date'
bookmark_count = input('Bookmark Count: ').rstrip("\r") or None
(page, end_page) = PixivHelper.get_start_and_end_number(total_number_of_page=options.number_of_pages)
(start_date, end_date) = PixivHelper.get_start_and_end_date()
if bookmark_count is not None and bookmark_count != -1 and len(bookmark_count) > 0:
bookmark_count = int(bookmark_count)
PixivListHandler.process_tags_list(sys.modules[__name__],
__config__,
filename,
page,
end_page,
wild_card=wildcard,
sort_order=sort_order,
bookmark_count=bookmark_count,
start_date=start_date,
end_date=end_date)
def menu_download_new_illust_from_bookmark(opisvalid, args, options):
__log__.info('New Illust from Bookmark mode (8).')
bookmark_count = None
if opisvalid:
(page_num, end_page_num) = get_start_and_end_page_from_options(options)
bookmark_count = options.bookmark_count_limit
else:
(page_num, end_page_num) = PixivHelper.get_start_and_end_number(total_number_of_page=options.number_of_pages)
bookmark_count = input('Bookmark Count: ').rstrip("\r") or None
if bookmark_count is not None and bookmark_count != -1 and len(bookmark_count) > 0:
bookmark_count = int(bookmark_count)
PixivBookmarkHandler.process_new_illust_from_bookmark(sys.modules[__name__],
__config__,
page_num=page_num,
end_page_num=end_page_num,
bookmark_count=bookmark_count)
def menu_download_by_manga_series_id(opisvalid, args, options):
__log__.info('Manga Series mode (13).')
manga_series_ids = []
start_page = 1
end_page = 0
if opisvalid:
(start_page, end_page) = get_start_and_end_page_from_options(options)
for manga_series_id in args:
if manga_series_id.isdigit():
manga_series_ids.append(int(manga_series_id))
else:
print(f"Possible invalid manga series id = {manga_series_id}")
else:
manga_series_ids = input('Manga Series IDs: ').rstrip("\r")
(start_page, end_page) = PixivHelper.get_start_and_end_number(total_number_of_page=options.number_of_pages)
manga_series_ids = PixivHelper.get_ids_from_csv(manga_series_ids)
PixivHelper.print_and_log('info', f"Manga Series IDs: {manga_series_ids}")
for manga_series_id in manga_series_ids:
PixivImageHandler.process_manga_series(sys.modules[__name__],
__config__,
manga_series_id=manga_series_id,
start_page=start_page,
end_page=end_page)
def menu_download_by_novel_id(opisvalid, args, options):
__log__.info('Novel mode (14).')
novel_ids = input('Novel IDs: ').rstrip("\r")
novel_ids = PixivHelper.get_ids_from_csv(novel_ids)
PixivHelper.print_and_log('info', f"Novel IDs: {novel_ids}")
for novel_id in novel_ids:
PixivNovelHandler.process_novel(sys.modules[__name__],
__config__,
novel_id)
def menu_download_by_novel_series_id(opisvalid, args, options):
__log__.info('Novel Series mode (15).')
start_page = 1
end_page = 0
novel_series_ids = input('Novel Series IDs: ').rstrip("\r")
(start_page, end_page) = PixivHelper.get_start_and_end_number(total_number_of_page=options.number_of_pages)
novel_series_ids = PixivHelper.get_ids_from_csv(novel_series_ids)
PixivHelper.print_and_log('info', f"Novel Series IDs: {novel_series_ids}")
for novel_series_id in novel_series_ids:
PixivNovelHandler.process_novel_series(sys.modules[__name__],
__config__,
novel_series_id,
start_page=start_page,
end_page=end_page)
def menu_download_by_group_id(opisvalid, args, options):
__log__.info('Group mode (12).')
process_external = False
limit = 0
if opisvalid and len(args) > 0:
group_id = args[0]
limit = int(args[1])
if args[2].lower() == 'y':
process_external = True
else:
group_id = input("Group Id: ").rstrip("\r")
limit = int(input("Limit: ").rstrip("\r"))
arg = input("Process External Image [y/n, default is no]: ").rstrip("\r") or 'n'
arg = arg.lower()
if arg == 'y':
process_external = True
PixivBookmarkHandler.process_from_group(sys.modules[__name__],
__config__,
group_id,
limit=limit,
process_external=process_external)
def menu_download_by_unlisted_image_id(opisvalid, args, options):
__log__.info('Unlisted ID mode (19).')
if opisvalid and len(args) > 0:
for image_id in args:
try:
PixivImageHandler.process_image(sys.modules[__name__],
__config__,
artist=None,
image_id=image_id,
useblacklist=False,
is_unlisted=True)
except BaseException:
PixivHelper.print_and_log('error', f"Image ID: {image_id} is not valid")
global ERROR_CODE
ERROR_CODE = -1
continue
else:
image_ids = input('Image ids: ').rstrip("\r")
image_ids = PixivHelper.get_ids_from_csv(image_ids, is_string=True)
for image_id in image_ids:
PixivImageHandler.process_image(sys.modules[__name__],
__config__,
artist=None,
image_id=image_id,
useblacklist=False,
is_unlisted=True)
def menu_ugoira_reencode(opisvalid, args, options):
__log__.info('Re-encode Ugoira (u)')
msg = Fore.YELLOW + Style.NORMAL + 'WARNING: THIS ACTION CANNOT BE UNDO !' + Style.RESET_ALL
PixivHelper.print_and_log(None, msg)
msg = Fore.YELLOW + Style.NORMAL + 'You are about to re-encode and overwrite all of your stored ugoira and its related files (gif, webm ...).' + Style.RESET_ALL
PixivHelper.print_and_log(None, msg)
arg = input(Fore.YELLOW + Style.BRIGHT + 'Do you really want to proceed ? [y/n, default is no]: ' + Style.RESET_ALL).rstrip("\r") or 'n'
sure = arg.lower()
if sure not in ('y', 'n'):
PixivHelper.print_and_log("error", f"Invalid args for ugoira reencode: {arg}, valid values are [y/n].")
return
if __config__.overwrite:
arg = input(Fore.YELLOW + Style.BRIGHT + 'Overwrite option is set to True, all animated files will be re-download from Pixiv and not re-encode locally. Do you still want to proceed ? [y/n, default is no]: ' + Style.RESET_ALL).rstrip("\r") or 'n'
sure = arg.lower()
if sure not in ('y', 'n'):
PixivHelper.print_and_log("error", f"Invalid args for ugoira reencode: {arg}, valid values are [y/n].")
return
if sure == 'y':
PixivImageHandler.process_ugoira_local(sys.modules[__name__], __config__)
def menu_export_database_images(opisvalid, args, options):
__log__.info('Export local database (l)')
use_pixiv = "n" # y|n|o
use_fanbox = "n" # y|n|o
use_sketch = "n" # y|n|o
filename = "export-database.txt"
if opisvalid:
if options.export_filename is not None:
filename = options.export_filename
if options.use_pixiv is not None:
use_pixiv = options.use_pixiv
if use_pixiv not in ('y', 'n', 'o'):
PixivHelper.print_and_log("error", f"Invalid args for Pixiv database: {use_pixiv}, valid values are [y/n/o].")
return
if options.use_fanbox is not None:
use_fanbox = options.use_fanbox
if use_fanbox not in ('y', 'n', 'o'):
PixivHelper.print_and_log("error", f"Invalid args for Fanbox database: {use_fanbox}, valid values are [y/n/o].")
return
if options.use_sketch is not None:
use_sketch = options.use_sketch
if use_sketch not in ('y', 'n', 'o'):
PixivHelper.print_and_log("error", f"Invalid args for Sketch database: {use_sketch}, valid values are [y/n/o].")
return
else:
filename = input("Filename: ").rstrip("\r") or filename
arg = input("Include Pixiv database [y/n/o, default is no]: ").rstrip("\r") or 'n'
use_pixiv = arg.lower()
if use_pixiv not in ('y', 'n', 'o'):
PixivHelper.print_and_log("error", f"Invalid args for Fanbox database: {arg}, valid values are [y/n/o].")
return
arg = input("Include Fanbox database [y/n/o, default is no]: ").rstrip("\r") or 'n'
use_fanbox = arg.lower()
if use_fanbox not in ('y', 'n', 'o'):
PixivHelper.print_and_log("error", f"Invalid args for Fanbox database: {arg}, valid values are [y/n/o].")
return
arg = input("Include Sketch database [y/n/o, default is no]: ").rstrip("\r") or 'n'
use_sketch = arg.lower()
if use_sketch not in ('y', 'n', 'o'):
PixivHelper.print_and_log("error", f"Invalid args for Sketch database: {arg}, valid values are [y/n/o].")
return
PixivBookmarkHandler.export_image_table(sys.modules[__name__], filename, use_pixiv, use_fanbox, use_sketch)
def menu_export_online_bookmark(opisvalid, args, options):
__log__.info('Export Followed Artists mode (e).')
hide = "y" # y|n|o
filename = "export.txt"
if opisvalid:
if options.export_filename is not None:
filename = options.export_filename
if options.bookmark_flag is not None:
hide = options.bookmark_flag.lower()
if hide not in ('y', 'n', 'o'):
PixivHelper.print_and_log("error", f"Invalid args for bookmark_flag: {hide}, valid values are [y/n/o].")
return
else:
filename = input("Filename: ").rstrip("\r")
arg = input("Include Private bookmarks [y/n/o, default is no]: ").rstrip("\r") or 'n'
hide = arg.lower()
if hide not in ('y', 'n', 'o'):
PixivHelper.print_and_log("error", f"Invalid args for bookmark_flag: {arg}, valid values are [y/n/o].")
return
PixivBookmarkHandler.export_bookmark(sys.modules[__name__], __config__, filename, hide)
def menu_export_online_user_bookmark(opisvalid, args, options):
__log__.info('Export Other\'s Followed Artist mode (m).')
member_id = ''
filename = "export-user.txt"
if opisvalid and len(args) > 0:
arg = args[0] # member id
if options.export_filename is not None:
filename = options.export_filename
else:
filename = f"export-user-{arg}.txt"
else:
filename = input("Filename: ").rstrip("\r") or filename
arg = input("Member Id: ").rstrip("\r") or ''
arg = arg.lower()
if arg.isdigit():
member_id = arg
else:
print("Invalid args, member id is expected: ", arg)
return
PixivBookmarkHandler.export_bookmark(sys.modules[__name__], __config__, filename, 'n', 1, 0, member_id)
def menu_export_from_online_image_bookmark(opisvalid, args, options):
__log__.info("Export User's Image Bookmark mode (p).")
start_page = 1
end_page = 0
hide = 'n'
tag = ''
use_image_tag = False
filename = "Exported_images.txt"
if opisvalid:
if len(args) > 0:
tag = args[0]
(start_page, end_page) = get_start_and_end_page_from_options(options)
if options.bookmark_flag is not None:
hide = options.bookmark_flag.lower()
if hide not in ('y', 'n', 'o'):
PixivHelper.print_and_log("error", f"Invalid args for bookmark_flag: {options.bookmark_flag}, valid values are [y/n/o].")
return
use_image_tag = options.use_image_tag
if options.export_filename is not None:
filename = options.export_filename
else:
hide = input("Include Private bookmarks [y/n/o, default is no]: ").rstrip("\r") or 'n'
hide = hide.lower()
if hide not in ('y', 'n', 'o'):
print("Invalid args: ", hide)
return
tag = input("Tag (press enter for all images): ").rstrip("\r") or ''
(start_page, end_page) = PixivHelper.get_start_and_end_number(total_number_of_page=options.number_of_pages)
if tag != '':
use_image_tag = input("Use Image Tags as the filter [y/n, default is no]? ").rstrip("\r") or 'n'
use_image_tag = use_image_tag.lower()
use_image_tag = True if use_image_tag == 'y' else False
filename = input(f"Filename (default is '{filename}'): ").rstrip("\r") or filename
PixivBookmarkHandler.export_image_bookmark(sys.modules[__name__],
__config__,
hide=hide,
start_page=start_page,
end_page=end_page,
tag=tag,
use_image_tag=use_image_tag,
filename=filename)
def menu_fanbox_download_from_list(op_is_valid, via, args, options):
via_type = ""
if via == PixivModelFanbox.FanboxArtist.SUPPORTING:
via_type = "supporting"
elif via == PixivModelFanbox.FanboxArtist.FOLLOWING:
via_type = "following"
elif via == PixivModelFanbox.FanboxArtist.CUSTOM:
via_type = "custom"
__log__.info(f'Download FANBOX {via_type.capitalize()} list mode (f1/f4/f5).')
if op_is_valid:
(page, end_page) = get_start_and_end_page_from_options(options)
else:
end_page = int(input("End Page (default is 0) = ").rstrip("\r") or 0)
ids = list()
if via in [PixivModelFanbox.FanboxArtist.SUPPORTING, PixivModelFanbox.FanboxArtist.FOLLOWING]:
ids = __br__.fanboxGetArtistList(via)
elif via == PixivModelFanbox.FanboxArtist.CUSTOM:
list_file_name = __config__.listPathFanbox
if op_is_valid:
list_file_name = get_list_file_from_options(options, list_file_name)
if os.path.isfile(list_file_name):
with PixivHelper.open_text_file(list_file_name) as reader:
while True:
line = reader.readline()
if not line:
break
line = line.strip()
if line.startswith("#"):
continue
ids.append(line)
if not ids:
PixivHelper.print_and_log("info", f"No artist in {via_type} list!")
return
PixivHelper.print_and_log("info", f"Found {len(ids)} artist(s) in {via_type} list")
PixivHelper.print_and_log(None, f"{ids}")
for index, artist_id in enumerate(ids, start=1):
# Issue #567
try:
PixivFanboxHandler.process_fanbox_artist_by_id(sys.modules[__name__],
__config__,
artist_id,
end_page,
title_prefix=f"{index} of {len(ids)}")
except KeyboardInterrupt:
choice = input("Keyboard Interrupt detected, continue to next artist (Y/N)").rstrip("\r")
if choice.upper() == 'N':
PixivHelper.print_and_log("info", f"Artist id: {artist_id}, processing aborted")
break
else:
continue
except PixivException as pex:
PixivHelper.print_and_log("error", f"Error processing FANBOX Artist in {via_type} list: {artist_id} ==> {pex.message}")
def menu_fanbox_download_by_post_id(op_is_valid, args, options):
__log__.info('Download FANBOX by post id mode (f3).')
if op_is_valid and len(args) > 0:
post_ids = args
else:
post_ids = input("Post ids = ").rstrip("\r")
post_ids = PixivHelper.get_ids_from_csv(post_ids)
for post_id in post_ids:
try:
post = __br__.fanboxGetPostById(post_id)