johanneszab / TumblThree

A Tumblr Blog Backup Application
https://www.jzab.de/content/tumblthree
MIT License
922 stars 130 forks source link

[Feature Request] File rename function #119

Open xmoer opened 7 years ago

xmoer commented 7 years ago

At the moment, the downloaded image file arrangement is disorderly. It is recommended to add file rename function, which can be numbered according to post.

johanneszab commented 7 years ago

The LastWriteTime/date modified is set to the posts time. Thus, you can do it with Windows Powershell like this:

$files = Get-ChildItem .\Blogs\Myblog | sort LastWriteTime
$x = 1
ForEach ($file in $files) {
    Rename-Item -Path $file.FullName -NewName (($file.Directory.FullName) + "\" + $x + "_" + $file.Name)
    $x++
}

Or any other program you like.

It sorts all the files in Blogs\Myblog by its date modified date and then adds a increasing number and underscore before the filename. Eg. tumblr_l52miZDt1qzk5l4o1_1280 -> 1_tumblr_l52miZDt1qzk5l4o1_1280

xmoer commented 7 years ago

I know this method and actually tried it. The results are still inaccurate, especially in the same post. There is also a problem: the naming process often prompts the file to be occupied, resulting in an error.

As long as you look closely, you'll find that each image has a "o?_1280" character at the end of the filename. The "o?" character is the actual order in the same post.

TumblThree has the function of saving download information, and also contains post information. Why not use post information to rename it?

johanneszab commented 7 years ago

You can add it for yourself, or commit code if you want. I'm happy for any code contributions..

I probably won't add it right now, and maybe never. I'm polishing the code right now in the hope that someone else might have fun to contribute code. And I can already see that implementing this will end up in spending hours and borderline code additions, because the next one comes along and only wants to have renamed images, but no videos. Or videos and each picture kind separately with a increasing number. Then someone else wants only the post number, but not tumblr_ and of course different for each blog or maybe at the end. Sure, it's all doable, but it's probably the best if you add it for yourself right now. Adding a sole number might be a quick hack, I don't know.

Also note the downloads are not necessarily in order since the crawler as well as the downloader each run different tasks and concurrently, thus I have to introduce some kind of state between each downloader instances to sync the number(s) depending on the settings. And this is seldom a trivial task to do.