darkdragn / party

A quick *.party downloader
84 stars 12 forks source link

Sequential filename renaming (Feature Request) #17

Closed muge closed 8 months ago

muge commented 9 months ago

Hi, been using this tool for a bit, I'd like to request the ability for the tool to rename files in the order that they are ordered in the actual post. I'm not sure if I'm missing something, but downloaded files have the "hashed" filenames, like so: 8q60e129-83d0-4108-a4dc-17b41f230d91.jpg

These don't really sort nicely. I see there is an option to prepend the post ID before the filename via --post-id, which helps, but some posts have multiple images in them, like comic pages, and even with the post ID these pages may not sort properly due to the random nature of the filenames.

  1. Page 1: 123456_f70613de-5279-469a-acb7-64e56eqf6093.png
  2. Page 2: 123456_c8b52368-fff3-4f3c-q69c-6678d1443817.png

As above, images named like so will result in page 2 coming before page 1.

My request would be just an option of some sort, maybe --ordered that is used in conjunction with --post-id that pre-pends the image's order in the post so the filenames becomes like something of the following:

Hope that is clear, thanks!

darkdragn commented 8 months ago

Oh, yeah. That would literally be like 2 lines of code. It's actually really easy. I should have some down time tomorrow or over the weekend to add that.

Sorry it took me so long to get back to you, I have some family issues going on so I've been in and out of the hospital with my son for the last long while.

Drop a reply back on here to let me know you're still interested in this, and I'll add it to a task list so I don't forget before the weekend. (I'm about to crash right now)

muge commented 8 months ago

Yeah, I'd still be interested for this to be added. Having been in and out of a hospital earlier this year myself, I can sympathize with the things that follow that... Take care, hope things go well for you and your family

darkdragn commented 8 months ago

Here's what I just threw together. It is a bit more of a re-working of the CLI than I anticipated, but still easy.

darkdragn@dragnDesk [06:37:43 AM] [/media/dumpCrypt/Documents/src/personal/party] [main *]
-> % party kemono patreon Creux --file-format "{ref.post_id}_{ref.index:03}.{ref.extension}" --limit 5 
2023-11-03 06:37:50.092 | DEBUG    | party.cli:pull_user:91 - Excluded Extensions: []
⠙ User found: creux; parsing posts...Duplicate files found, recommend using post_id
Embedded objects found; saving to creux/.embedded
Downloading from user: creux
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 16/16 [00:14<00:00,  1.14it/s]
2023-11-03 06:38:16.414 | INFO     | party.cli:pull_user:176 - Output status: Counter({<StatusEnum.SUCCESS: 1>: 16})                                                                      
darkdragn@dragnDesk [06:38:16 AM] [/media/dumpCrypt/Documents/src/personal/party] [main *]
-> % party kemono patreon Creux --file-format "{ref.post_id}_{ref.index:03}.{ref.extension}" --limit 5 
2023-11-03 06:38:33.976 | DEBUG    | party.cli:pull_user:91 - Excluded Extensions: []
⠧ User found: creux; parsing posts...Duplicate files found, recommend using post_id
Embedded objects found; saving to creux/.embedded
Downloading from user: creux
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 16/16 [00:00<00:00, 13249.53it/s]
2023-11-03 06:38:46.537 | INFO     | party.cli:pull_user:176 - Output status: Counter({<StatusEnum.EXISTS: 5>: 16})
darkdragn@dragnDesk [06:38:46 AM] [/media/dumpCrypt/Documents/src/personal/party] [main *]
-> % party kemono patreon Creux --file-format "{ref.post_id}_{ref.post_title}_{ref.base_name}.{ref.extension}" --limit 5 
2023-11-03 06:39:02.598 | DEBUG    | party.cli:pull_user:91 - Excluded Extensions: []
⠹ User found: creux; parsing posts...Duplicate files found, recommend using post_id
Embedded objects found; saving to creux/.embedded
Downloading from user: creux
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 11/11 [00:10<00:00,  1.08it/s]
2023-11-03 06:39:24.859 | INFO     | party.cli:pull_user:176 - Output status: Counter({<StatusEnum.SUCCESS: 1>: 11})                                                                      
darkdragn@dragnDesk [06:39:24 AM] [/media/dumpCrypt/Documents/src/personal/party] [main *]
-> % ls creux 
 86307825_000.jpg                                                              '86462263_Lois Lane - Strip game - Part 2_LoisLane_StripGame02_1_Twitter.jpg'
 86307825_001.jpg                                                              '86462263_Lois Lane - Strip game - Part 2_LoisLane_StripGame02_2_Twitter.jpg'
 86307825_002.jpg                                                              '86462263_Lois Lane - Strip game - Part 2_LoisLane_StripGame02_3_Patreon.jpg'
'86307825_Bex - Yellow Jacket_Bex_YellowJacket_1_Twitter.jpg'                   88614838_000.jpg
'86307825_Bex - Yellow Jacket_Bex_YellowJacket_2_Patreon.jpg'                   88614838_001.jpg
 86410843_000.jpg                                                               88614838_002.jpg
 86410843_001.jpg                                                              '88614838_Bex & Keit - Medium Support_Bex_MediumSupport_1_Twitter.jpg'
 86410843_002.jpg                                                              '88614838_Bex & Keit - Medium Support_Bex_MediumSupport_2_Patreon.jpg'
'86410843_Lois Lane - Strip game - Part 1_LoisLane_StripGame01_1_Twitter.jpg'   88831815_000.jpg
'86410843_Lois Lane - Strip game - Part 1_LoisLane_StripGame01_2_Patreon.jpg'   88831815_001.jpg
 86462263_000.jpg                                                               88831815_002.jpg
 86462263_001.jpg                                                              '88831815_Lucia - Concept Sheet_Splatball_Lucia_1_Twitter.jpg'
 86462263_002.jpg                                                              '88831815_Lucia - Concept Sheet_Splatball_Lucia_2_Patreon.jpg'

There are 3 separate runs, with three different format options. Notice that the last one had less files gathered. This is because an attachment and a file object on the post had the same name, so not having an index meant they were considered identical when filtering to write to disk. The basic request you had is fulfilled by the simple option --ordered-short. But, I had fun and added the ability to fully format the output filenames.

A little comment on --ordered-short, I'm only applying it to jpg and png files. It didn't feel right to apply it to videos or zips. I'm about to commit and push, just wanted to see what you thought.

darkdragn commented 8 months ago

@muge if you get a chance, let me know what you think about the robust filenaming change. Also, check out #24 and let me know what you think about that update!

muge commented 7 months ago

Hey, late reply, had a chance to try this out... working nicely! Thanks a bunch