Gentoo Archives: gentoo-user

From: Frank Steinmetzger <Warp_7@×××.de>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Dolphin and adding a option, if it exists.
Date: Sun, 23 Oct 2022 11:58:15
Message-Id: Y1UsR1uwCR48dyZM@kern
In Reply to: Re: [gentoo-user] Dolphin and adding a option, if it exists. by Dale
1 Am Sun, Oct 23, 2022 at 06:16:04AM -0500 schrieb Dale:
2 > Frank Steinmetzger wrote:
3 > > Am Sun, Oct 23, 2022 at 01:35:55AM -0500 schrieb Dale:
4 > >
5 > >> Well, I ran into a slight problem.  This isn't much of a problem with
6 > >> Linux but I'm not sure how this would work on windoze tho.  The problem,
7 > >> if it is one, is the file extension.  Let's say I have a mp4 file that
8 > >> is the older original file that I intend to replace.  If the file I
9 > >> intend to put in its place is a .mkv file, mv uses the .mp4 extension
10 > >> because all it cares about is the name of the file, not what it is or
11 > >> its content.  So, I end up with a .mkv file that has a .mp4 extension. 
12 > >> It works here on Linux but not sure about windoze and such.
13 > > It’s not a problem for as long as the application you open the file with
14 > > does its own detection. I.e. you feed mp4 to mpv, but it recognises by
15 > > itself that it’s mp4 and can handle it.
16 >
17 > That is true on Linux.  Most linux software could care less what the
18 > extension is or if it even has one.
20 Mpv or Vlc on Windows will probably just work™, too.
22 > Heck, you could likely change a
23 > .mp4 to .txt and it would open with a video player just by clicking on
24 > it.  Thing is, if I share a file with someone who uses windoze, I'm not
25 > sure if it would work the same way.  A wrong extension could cause
26 > problems, either not opening at all or crashing something.  It's
27 > windoze, one can't expect much.  ROFL 
29 Now you’re talking about double-clicking in a file manager and open the
30 registered application. That’s the same—to some extent—on Linux file
31 managers. I was referring to an application that could work out the details.
33 > I thought about looking to see if there is a way to "scan" a directory
34 > and look at each file and if needed, change the extension to the correct
35 > one.  Thing is, I couldn't write a fancy script if my life depended on
36 > it.  I also looked into using Krename to do it but it refuses to change
37 > a extension.  Doing it one file at a time manually puts me back to where
38 > it is easier to change the file the old way.  Time consuming but works. 
40 Well, ther is the `file` tool, plus maybe `mediainfo` or `identify` for
41 images. But their output may not always be sufficient.
43 > > If you still want to stick to a terminal solution akin to mv, then there
44 > > is no way around a little script which wraps mv by extracting the
45 > > extension and filename base.
47 > Hmmmm.  I get a little of that but then I get lost.
49 The script first checks wheter it receives exactly two arguments, and exits
50 otherwise. In theory it should also check whether both paths exist and are
51 files. First rule of programming: always sanitise your inputs!
53 Now it gets the extension of the source file and the base part (i.e.
54 everything without the extension) from the destination. Then it deletes the
55 original destination file and finally moves the source by concatenating the
56 original destination’s base part with the source’s extension part.
59 >   Just how does that work and how would I use it?
61 I have a lot of little helper scripts. I collect them in ~/usr/bin, to which
62 my PATH is expanded in ~/.bashrc with export PATH=~/usr/bin:$PATH. Actually,
63 I keep the script files in git repositories under ~/dev, and then put
64 symlinks into ~/usr/bin, which point to the repository file.
66 > I think I would save that as a file, make it executable and then run it
67 > with whatever name I give it.
69 Exactly.
71 > I'm not sure exactly how to tell it what files to move tho.  Same as mv
72 > maybe? 
74 Yes. You give it two arguments. That’s what $1 and $2 are for in the script.
75 I always write my scripts so that they can handle spaces in filenames. I
76 find it an anachronism to still use underscores or dots in filenames where
77 spaces would go in normal language. File systems have been able to deal with
78 spaces for decades now.
80 > Currently, I move to the main directory that files are in when I am in
81 > Konsole and running as my user, so file permissions don't switch to root. 
83 That’s the proper way to do it. I also have a root console open all the
84 time, but don’t do normal file operations in there. The risk is too big that
85 I may be typing too fast for my own good.
87 > My process on file organizing goes a little like this.  I have a set of
88 > videos that go together.  When I have a new version of one or more videos,
89 > I place them in a sub-directory until they are named properly or something
90 > so I can move to the main directory.  Like this:
91 >
92 > Main Directory  #Permanent location for files ----- Sub-directory 
93 > #Temporary location for files needing names changed etc.  Once done, they
94 > move up to main directory.
96 I don’t quite understand the formatting of that line. But basically, you
97 have a directory for your videos, and in a subdiractory of that, you collect
98 your temporary files?
100 > A typical command for mv would be like this.
101 >
102 > mv sub-directory/<file name of new file> <file name of old file in main
103 > directory>
105 OK. That could actually be automated in a way. How many files per directory
106 are we talking about? Because one approach I can think of is a managament
107 script. It goes through all the files in your temp subdir, and for each file
108 it asks you which file to overwrite in the main directory. It then moves the
109 file, but keeps the extension as in my first script. But this isn’t
110 practical if there are dozens of files in the main dir, because you would
111 have to scroll through the big selection ist.
113 As an example, let’s assume we have the following file tree:
115 main
116 ├── episode 1.mkv
117 ├── episode 2.mpeg
118 ├── episode 3.avi
119 └── temp
120 └── episode 2 with better quality.mkv
122 You cd into main, and start the script. It checks for the presence of the
123 temp dir and, if it exists, asks for each of its files what to do:
125 main$ VideoCleanupScript
126 Select file to overwrite with 'episode 2 with better quality.mkv':
127 1) episode 1.mkv
128 2) episode 2.mpeg
129 3) episode 3.avi
130 #? 2
131 Removing 'episode 2.mpeg'
132 Moving file 'episode 2 with better quality.mkv' -> 'episode 2.mkv'
134 > Just trying to follow this and figure out how to use it.  ;-)  I've said
135 > this before, my scripting skills are so small it isn't funny.  :/
137 I could write the above script in probably half an hour. Just say when. ;-)
139 I, too, have a few scripts that move files around. For example when I edit
140 photo albums, I do a final re-encoding of those images in different JPEG
141 quality levels as a trade-off between quality and storage space. For that I
142 have a script that asks me which level to keep whilst I look at the
143 different versions in a viewer. I then decide for one and the script picks
144 the appropriate file and moves it into the final folder. The other choices
145 are moved away so that if I halt the script midway, I can call it again and
146 pick up where I left it.
148 --
149 Grüße | Greetings | Salut | Qapla’
150 Please do not share anything from, with or about me on any social network.
152 Of all the people I’ve met you’re certainly one of them.


File name MIME type
signature.asc application/pgp-signature