You are not logged in.

#1 2023-05-14 02:33:41

Joel
Member
From: Tijuana, BC, México
Registered: 2011-12-21
Posts: 128

Advance batch filerenamer

Sorry if my question belonngs elsewhere.

I'm looking for a way to rename subtitles files with different names to match their counterpart media file, for example:

tv.show.e01.srt from tv.show.e01.avi

All media files have the same name, for example:

tv.show.e01.avi
tv.show.e02.avi
tv.show.e03.avi
...

But the downloaded subtitles have different names and thunar batch file renamer doesn't have such feature as I want it.
Any ideas?


* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.
* AUR contributor.

Offline

#2 2023-05-14 02:42:12

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,520
Website

Re: Advance batch filerenamer

What are the "different" names?  And what is the logic of how those different names should be matched to the appropriate media file?


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2023-05-14 03:37:35

Joel
Member
From: Tijuana, BC, México
Registered: 2011-12-21
Posts: 128

Re: Advance batch filerenamer

Trilby wrote:

What are the "different" names?  And what is the logic of how those different names should be matched to the appropriate media file?

I have subtitles names like:

tvshow.e01.by-TM.srt
tv-show.e02.Galaxy.srt
tvshow.e03.someuser.srt

and all media files have this same spec format name:

tv.show.e01.avi
tv.show.e02.avi
tv.show.e03.avi
...

* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.
* AUR contributor.

Offline

#4 2023-05-14 03:59:45

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,520
Website

Re: Advance batch filerenamer

And ...

Trilby wrote:

And what is the logic of how those different names should be matched to the appropriate media file?

If it is just the number, and the numbers are unique, then the following would do:

#!/bin/sh

for f in *.srt; do
	mv $f tv.show.e$(echo $f | tr -cd '[0-9]').srt
done

But assuming you've not precisely described the goal, you should have backups before you make any attempts.

Last edited by Trilby (2023-05-14 04:01:13)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2023-05-14 04:58:28

SimonJ
Member
From: Spain
Registered: 2021-05-11
Posts: 378
Website

Re: Advance batch filerenamer

I don't know which DE you use, but Thunar has a bulk rename plugin which does just that.

https://docs.xfce.org/xfce/thunar/bulk-renamer/start

Last edited by SimonJ (2023-05-14 04:59:01)


Rlu: 222126

Offline

#6 2023-05-14 11:44:07

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 714

Re: Advance batch filerenamer

Another option is to use edir to bring all the files up within your favorite editor and hand edit and/or globally replace characters to make all the file names consistent. I use vim so using column selection, repeat commands, macros, undo etc I find I can rename many inconsistent files very quickly. Once you can see all the files are named as you want then the changes are not actioned until you quit your editor so it is hard to make a mistake. edir is available in the AUR.

Offline

#7 2023-05-14 11:50:33

Stefan Husmann
Member
From: Germany
Registered: 2007-08-07
Posts: 1,391

Re: Advance batch filerenamer

emacs has such a feature built in (wdired-change-to-wdired-mode).

Offline

#8 2023-05-14 12:52:17

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,833

Re: Advance batch filerenamer

Stefan Husmann wrote:

emacs has such a feature built in

https://xkcd.com/378/

Offline

#9 2023-05-14 20:51:11

Joel
Member
From: Tijuana, BC, México
Registered: 2011-12-21
Posts: 128

Re: Advance batch filerenamer

SimonJ wrote:

I don't know which DE you use, but Thunar has a bulk rename plugin which does just that.

https://docs.xfce.org/xfce/thunar/bulk-renamer/start

Yes, I know, but I don't know how to match my intended task, for example:
Before:

tvshow.e01.by-TM.srt
tv-show.e02.Galaxy.srt
tvshow.e03.someuser.srt

After:

tv.show.e01.srt
tv.show.e03.srt
tv.show.e03.srt

* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.
* AUR contributor.

Offline

#10 2023-05-14 21:17:08

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,833

Re: Advance batch filerenamer

What's wrong w/ Tilby's script?

If this is bash and you're concerned about digits showing up in other places and ".e[0-9]*." is a solid pattern you can (safely) preview the renaming w/

for name in *.srt; do [[ $name =~ \.e[0-9]*\. ]]; echo "$name => tv.show${BASH_REMATCH}srt"; done

Offline

#11 2023-05-14 21:36:43

stanczew
Member
Registered: 2021-03-02
Posts: 114

Re: Advance batch filerenamer

It depends on how many files you have, and how repeatable are the name patterns; but you're probably looking for a regexp + manual cleanup of stragglers.

For both of those things I'll suggest qmv from the renameutils package. Call it like that:

qmv -f do *.srt

This will open you editor with the list of .srt files in current directory.
You can then change the filenames to desired ones, either manually or using your editor's search and replace functionality.
Once you're done, just save and close the editor, and qmv will rename all the files to what you entered.

As for the patterns: I assume "tv.show" in your examples is just a placeholder, and the files have actual show names there, just with different punctuation.
In such case, you should be able to select all filenames for a specific show, and use a regexp replace from something like

.*(e[0-9]+).*\.srt

to

<name>.\1.srt

where '<name>' is the desired show name.

Offline

#12 2023-05-15 15:12:55

Joel
Member
From: Tijuana, BC, México
Registered: 2011-12-21
Posts: 128

Re: Advance batch filerenamer

seth wrote:

What's wrong w/ Tilby's script?

If this is bash and you're concerned about digits showing up in other places and ".e[0-9]*." is a solid pattern you can (safely) preview the renaming w/

for name in *.srt; do [[ $name =~ \.e[0-9]*\. ]]; echo "$name => tv.show${BASH_REMATCH}srt"; done

OK. I'll try it.


* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.
* AUR contributor.

Offline

Board footer

Powered by FluxBB