そういえば Windows の MIME Type はどうなっているのだろう?
MIMEタイプの取得・判定 – Programming/Tips – 総武ソフトウェア推進所
ふむふむ、そうやるのか。
Windows の場合は拡張子が全てなので Python の mimetypes モジュールでよさげだが。
せっかくなので試してみよう。
# -*- coding: UTF-8 -*-
import clr
clr.AddReferenceByPartialName("PresentationCore")
clr.AddReferenceByPartialName("PresentationFramework")
clr.AddReferenceByPartialName("WindowsBase")
from System import *
from System.IO import *
from System.Windows import *
from System.Windows.Controls import *
from Microsoft.Win32 import *
class MimeTypeWindow(Window):
"""
Get MIME Type for Windows
"""
def __init__(self):
self.Width = 320
self.Height = 240
self.Title = "MimeTypeWindow"
self.AllowDrop = True
self.Drop += self.on_drop
self.textblock = TextBlock()
self.textblock.Text = "Drop"
self.Content = self.textblock
def on_drop(self, sender, e):
files = e.Data.GetData(DataFormats.FileDrop)
ext = Path.GetExtension(str(files[0]))
if ext:
key = Registry.ClassesRoot.OpenSubKey(ext)
if key:
s = key.GetValue("Content Type")
if s:
self.textblock.Text = s
else:
self.textblock.Text = "No MimeType"
else:
self.textblock.Text = "No Registry Key"
else:
self.textblock.Text = "No Extension Value"
if __name__ == "__main__":
a = Application()
a.Run(MimeTypeWindow())
今頃知ったけど .NET Framework の null は None でイイんだね。
これと Python の mimetypes モジュールとでどうなるか試す。
ぱぇぽぃ2 ? Blog Archive ? Get MIME Type and Description
で GNOME と違うのかもついでに、zip アーカイブを試す。
あら…
ついでに Opera は Linux 版なのに
なんというか、やっぱりアプリケーションによってバラバラだよ。

