Danbooru::URL: add #basename, #filename, and #file_ext utility methods.

Add `#basename`, `#filename`, and `#file_ext` utility methods to
Danbooru::URL and change a few places to use them. Simplifies parsing
filenames in source URLs in various places.
This commit is contained in:
evazion
2022-02-27 00:56:23 -06:00
parent fcf517834d
commit 926a8fa81f
13 changed files with 93 additions and 65 deletions

View File

@@ -48,14 +48,14 @@ class Source::URL::HentaiFoundry < Source::URL
@work_id = work_id
# http://pictures.hentai-foundry.com//s/soranamae/363663.jpg
in "pictures.hentai-foundry.com", _, username, /^\d+\.\w+$/ => filename
in "pictures.hentai-foundry.com", _, username, /^(\d+)\.\w+$/
@username = username
@work_id, @file_ext = filename.split(".")
@work_id = $1
# http://www.hentai-foundry.com/piccies/d/dmitrys/1183.jpg
in "www.hentai-foundry.com", "piccies", _, username, /^\d+\.\w+$/ => filename
in "www.hentai-foundry.com", "piccies", _, username, /^(\d+)\.\w+$/
@username = username
@work_id, @file_ext = filename.split(".")
@work_id = $1
# https://www.hentai-foundry.com/pictures/user/Afrobull/795025
# https://www.hentai-foundry.com/pictures/user/Afrobull/795025/kuroeda