WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: minimalistic approach to MIME types / filetype associations  (Read 8730 times)

Online mocore

  • Hero Member
  • *****
  • Posts: 636
  • ~.~
Re: minimalistic approach to MIME types / filetype associations
« Reply #15 on: January 14, 2023, 05:09:34 AM »
thanks!!! ...

Well, just like the deep breath of clear air, thanks a lot!
+1

.. ftr the git hub link is mort

this is the current working url
https://gitlab.com/GNUser/tinyopen

perhaps this should/could be included in tinyopen.tcz.info

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1508
Re: minimalistic approach to MIME types / filetype associations
« Reply #16 on: January 14, 2023, 09:35:00 AM »
You're welcome, mocore. The latest version is 5.0 is available in the TCL13.1 x86_64 repository and has the correct (gitlab) url.
« Last Edit: January 14, 2023, 09:38:23 AM by GNUser »

Online mocore

  • Hero Member
  • *****
  • Posts: 636
  • ~.~
Re: minimalistic approach to MIME types / filetype associations
« Reply #17 on: October 02, 2024, 06:46:28 PM »
hi ... after some reading

@ https://joeyh.name/code/moreutils/

Quote
Rejected tools

(Some of these rejections may be reconsidered later.)

- mime

determines the mime type of a file using the gnome mine database

The File::MimeInfo perl module has a mimetype that works like this, and uses the freedesktop.org mime database, same as GNOME.

file -bi can do this too.

i wondered  if the line @ https://gitlab.com/GNUser/tinyopen/-/blob/master/tinyopen/tinyopen?ref_type=heads#L42
(coincidentally note the line number  :o )
Code: [Select]
mimetype="$(gio info "$1" | grep '::content-type' | cut -d' ' -f4)"

it might be possible?
 to replace
gio info "$1"  ...ect
with
file -bi "$1" ...?? (from file.tcz) ...
which apparently uses lib magic , and [1]appears to be smaller  :D

any one know ? (or care to investigate?? (s)trace?..)
what method dose the current gio solution use ? to get the mime

 ???

[1] https://forum.tinycorelinux.net/index.php/topic,27303.0.html
« Last Edit: October 02, 2024, 06:59:02 PM by mocore »

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1508
Re: minimalistic approach to MIME types / filetype associations
« Reply #18 on: October 02, 2024, 07:43:37 PM »
It's certainly possible to use  file  rather than  gio  to get the mimetype. I went with  gio  because glib2.tcz (which provides gio) seemed to me more likely to already be loaded on someone's machine than file.tcz.

I'm honestly not sure how  gio  does its job done. But it seems to always get it right.

Online mocore

  • Hero Member
  • *****
  • Posts: 636
  • ~.~
Re: minimalistic approach to MIME types / filetype associations
« Reply #19 on: October 03, 2024, 03:26:08 AM »
I went with  gio  because glib2.tcz (which provides gio) seemed to me more likely to already be loaded on someone's machine than file.tcz.

I'm honestly not sure how  gio  does its job done.
But it seems to always get it right.

ahh (i had not realized) that was the method used by linopen
https://github.com/Cloudef/PKGBUILDS/blob/master/linopen/open#L90
Code: [Select]
$(file -L -b --mime-type "$1")



I'm honestly not sure how  gio  does its job done.

any hints on how to find out
i had browsed and grep'ed the source a bit
and run strace ( which seams to indicate it try's a opening files (if they exists) containing some kind of db

which begs the question is a binary  (gio/file) dependency required to fine the mime of a file ??
so i started a topic  ;D https://forum.tinycorelinux.net/index.php/topic,27304.0.html

But it seems to always get it right.

i briefly compared file and gio and they did'nt reach the same conclusion (for a markdown file   'text/markdown' / 'text/plain' same difference relay)

though perhaps this discrepancy is explained by age of the data used ?idk
https://stackoverflow.com/questions/10701983/what-is-the-mime-type-for-markdown


« Last Edit: October 03, 2024, 03:56:11 AM by mocore »

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1508
Re: minimalistic approach to MIME types / filetype associations
« Reply #20 on: October 03, 2024, 08:47:25 AM »
Hi mocore. Right, linopen used file. When I forked it, I switched to gio. In rare situations, both methods get it right but spit out slightly different variants.

You can fork tinyopen to use file if you prefer it. The only important things for tinyopen to open a file as expected are:

1. The exact MIME type that your chosen backend (file or gio) is outputting needs to appear somewhere in /usr/local/share/tinyopen/mimeapps.list

2. MIME types in section 2 of ~/.config/tinyopen.conf need to match what your backend (file or gio) is outputting

any hints on how to find out [how gio works]
Not at the moment. But it's an interesting question. I'll do some investigation.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1508
Re: minimalistic approach to MIME types / filetype associations
« Reply #21 on: October 03, 2024, 08:56:00 AM »
It seems  gio  uses magic numbers, which is not surprising and probably the same approach that  file  uses. The real question is: Where is the database that  gio  uses to associate a magic number with a string such as text/plain?

Online mocore

  • Hero Member
  • *****
  • Posts: 636
  • ~.~
Re: minimalistic approach to MIME types / filetype associations
« Reply #22 on: October 16, 2024, 03:20:30 PM »