ó
    î�‹jÇ  ã                   óX   • S r SSKrSSKrSSKrSSKJr   " S S5      rS\S\S-  4S	 jr	g)
u  
Source adapter for Drake Scans (drakecomic.org).

Manga pages link their chapters as
    https://drakecomic.org/<manga-slug>-chapter-<num>/
Chapter pages embed their reader config:
    ts_reader.run({"post_id":..., "sources":[{"images":[url, ...]}]})
That list is the chapter's canonical page set and reading order.

Note: some chapter posts on the site have extra images from other manga
attached to them (the site's own reader shows them). We deliberately do
NOT filter those out â€” we recreate exactly what the site's reader lists.
é    Né   )Úcorec                   ó”   • \ rS rSrSrSrSS\S-  4S jjrS\SS	4S
 jrS\S\4S jr	S\S\
\\\\4      4S jrS\S\
\   4S jrSrg)ÚDrakeScansSourceé   Údrakezhttps://drakecomic.orgNÚ
manga_slugc                 ó$   • U=(       d    SU l         g )Nzdisastrous-necromancer©r	   )Úselfr	   s     Ú</home/nathan/projects/ai/drake_scans_download/manga/drake.pyÚ__init__ÚDrakeScansSource.__init__   s   € à$×@Ð(@ˆ�ó    Ú	manga_urlÚreturnz	core.Pathc                 óB   • [         R                  " U R                  5      $ ©N)r   ÚPathr	   )r   r   s     r   Ú
output_dirÚDrakeScansSource.output_dir   s   € Ü�yŠy˜Ÿ™Ó)Ð)r   Úch_idc                 ó    • S[        U5      S 3$ )NÚchapter_Ú03d©Úint)r   r   s     r   Úchapter_dirnameÚ DrakeScansSource.chapter_dirname!   s   € Øœ#˜e›* SÐ)Ð*Ð*r   c                 ó  • [         R                  " U5      nUc  [        R                  " S5        [        R
                  " S[        R                  " U R                  5      -   S-   [        R                  " U R                  5      -   S-   5      n/ nUR                  U5       HM  nUR                  S5      [        UR                  S5      5      pvUR                  [        U5      USU 345        MO     UR                  S S	9  U$ )
z--> [(ch_id, ch_url, label)] in reading order.zCould not fetch manga page.zhref="(z/[^"]*z-chapter-(\d+)/)"r   é   zChapter c                 ó   • [        U S   5      $ )Nr   r   )Úcs    r   Ú<lambda>Ú/DrakeScansSource.get_chapters.<locals>.<lambda>2   s   € ¤C¨¨!©¤Ir   )Úkey)r   Ú
fetch_htmlÚsysÚexitÚreÚcompileÚescapeÚsiter	   ÚfinditerÚgroupr   ÚappendÚstrÚsort)r   r   ÚhtmlÚlink_reÚchaptersÚmÚurlÚnums           r   Úget_chaptersÚDrakeScansSource.get_chapters$   sÖ   € ä�Š˜yÓ)ˆØ‰<Ü�HŠHÐ2Ô3ô —*’*ØœŸš 4§9¡9Ó-Ñ-°	Ñ9Ü�iŠi˜Ÿ™Ó(ñ)Ø+?ñ@óAˆð ˆØ×!Ñ! $Ö'ˆAØ—w‘w˜q“z¤3 q§w¡w¨q£z£?�Ø�O‰OœS ›X s¨h°s°eÐ,<Ð=Ö>ñ (ð 	�‰Ñ-ˆÑ.Øˆr   Úchapter_urlc                 ó   • [         R                  " U5      nUc  / $ [        U5      nU(       d  [         R                  " S5        / $ [	        S UR                  S5      =(       d    /  5       / 5      nU(       d  [         R                  " S5        U$ )Nu9     ts_reader config not found â€” layout may have changed.c              3   ó„   #   • U  H6  oR                  S 5      (       d  M  UR                  S 5      =(       d    / v •  M8     g7f)ÚimagesN)Úget)Ú.0Úss     r   Ú	<genexpr>Ú-DrakeScansSource.get_pages.<locals>.<genexpr>=   s2   é € ð MÚ7˜¿E¹EÀ(¿Oó +�Q—U‘U˜8“_×*¨Ô*Ú7ùs
   ‚A Ÿ!A Úsourcesz  no images in reader config.)r   r'   Úextract_ts_reader_jsonÚlogÚnextr?   )r   r;   r3   ÚcfgÚurlss        r   Ú	get_pagesÚDrakeScansSource.get_pages5   s|   € Ü�Š˜{Ó+ˆØ‰<ØˆIÜ$ TÓ*ˆÞÜ�HŠHÐPÔQØˆIÜñ MØ"Ÿw™w yÓ1×7°RÐ7óMØNPóRˆæÜ�HŠHÐ4Ô5Øˆr   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Únamer-   r1   r   r   r   ÚlistÚtupler9   rJ   Ú__static_attributes__© r   r   r   r      s~   † Ø€DØ#€DñA 3¨¡:õ Að* Cð *¨Kô *ð+ Sð +¨Sô +ð cð ¨d°5¸¸cÀ3¸Ñ3GÑ.Hô ð" Sð ¨T°#©Y÷ r   r   r3   r   c                 ó¾  • U R                  S5      nUS:X  a  gU R                  SU5      S-   nSu  p4n[        U[        U 5      5       Hw  nX   nU(       a!  U(       a  SnM  US:X  a  S	nM#  US
:X  a  SnM-  M/  US
:X  a  S	nM9  US:X  a  US-  nMF  US:X  d  MN  US-  nUS:X  d  M[   [        R                  " XUS-    5      s  $    g! [        R
                   a       gf = f)zGExtract the ts_reader.run({...}) JSON object (string-aware brace scan).zts_reader.run(éÿÿÿÿNÚ(r   )r   FFFÚ\TÚ"Ú{Ú}r   )ÚfindÚrangeÚlenÚjsonÚloadsÚJSONDecodeError)r3   ÚidxÚstartÚdepthÚin_strÚescÚir#   s           r   rE   rE   D   sí   € à
�)‰)Ð$Ó
%€CØ
ˆbƒyØØ�I‰I�c˜3Ó !Ñ#€EØ(Ñ€E�3Ü�5œ#˜d›)Ö$ˆØ‰GˆÞÞØ’Ø�d“Ø’Ø�c“Ø’ñ à�#‹XØŠFØ�#‹XØ�Q‰JŠEØ�#�XØ�Q‰JˆEØ˜�zð ÜŸ:š: d°°Q±Ð&7Ó8Ò8ñ# %ð( øô ×+Ñ+ó  Úð ús   Â$CÃCÃC)
Ú__doc__r_   r*   r(   Ú r   r   r1   ÚdictrE   rT   r   r   Ú<module>rk      s:   ðñó Û 	Û 
å ÷+ñ +ð\ ð ¨°©õ r   