kieraneglin / pinchflat

Your next YouTube media manager
GNU Affero General Public License v3.0
793 stars 16 forks source link

[FR] Substitute specific characters in filenames #369

Closed user-566 closed 3 weeks ago

user-566 commented 3 weeks ago

Is your feature request related to a problem? Please describe. Some media containing special characters will get incorrectly created by Pinchflat. From https://github.com/kieraneglin/pinchflat/pull/193#issue-2249138080 it seems like Pinchflat uses the --windows-filenames argument but in some cases it does not seem to work correctly, for example if I download media with a forward slash (/) in the title the file created will have ⧸ instead.

I think it would be neat if users could chose which characters they want substituted with what depending on their usecase and the filesystem they use.

Describe the solution you'd like Maybe as an option in the media profile configuration GUI or just a setting in the config that would let users specify which characters get substituted with what during file creation.

Describe alternatives you've considered Reading through the wiki, it seems like it could be possible to pass arguments directly to yt-dlp through the base-config.txt file, so it's possible that what I want to do is already feasible (I'm just not sure how exactly).

Additional context N/A

user-566 commented 3 weeks ago

After a lot of trial and error, I actually got this to work exactly how I wanted using the base-config.txt file as mentionned in the original post.

Here's the config I went with for those interested:

--replace-in-metadata title "\." ""
--replace-in-metadata title "\|" ""
--replace-in-metadata title "<" ""
--replace-in-metadata title ">" ""
--replace-in-metadata title "/" ""
--replace-in-metadata title "\\\\" ""
--replace-in-metadata title "\?" ""
--replace-in-metadata title "\*" ""
--replace-in-metadata title ":" ""
--replace-in-metadata title "\"" ""
--replace-in-metadata title "\[" "("
--replace-in-metadata title "\]" ")"
--replace-in-metadata title "          " " "
--replace-in-metadata title "         " " "
--replace-in-metadata title "        " " "
--replace-in-metadata title "       " " "
--replace-in-metadata title "      " " "
--replace-in-metadata title "     " " "
--replace-in-metadata title "    " " "
--replace-in-metadata title "   " " "
--replace-in-metadata title "  " " "

It removes all Windows illegal filename characters instead of letting yt-dlp trying to swap it for other ASCII characters (which don't seem to render correctly on the filesystem I'm using), substitutes brackets with parentheses, and removes any extra spaces.

I'm not sure if having a "proper" place to configure it in the configuration/settings would be worth it in terms of increased user experience though, I'd be interested to hear others opinion on this!

kieraneglin commented 3 weeks ago

Hey there! I'm glad you found a solution, but I think there might be an easier way. Since that flag can take a regular expression as an argument, you can combine pretty much everything except for the left and right brackets onto a single line. Look up "python regex match special characters" or "python regex match multiple characters". If you set that up, it'll match any one of the specified characters and replace/delete it as needed.

Sorry I can't provide a better example since I'm on my phone, but I can actually test and recommend something proper tomorrow once I'm on my computer. For all of its faults, this is also something that ChatGPT is decent at

kieraneglin commented 3 weeks ago

Untested, but this should do what you need with fewer rules!

--replace-in-metadata title "[\.|\||<|>|/|\\\\|\?|\*|:|\"]" ""
--replace-in-metadata title "\[" "("
--replace-in-metadata title "\]" ")"
--replace-in-metadata title "\s+" " "