Finding file details...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kalibr

    Finding file details...

    I've been trying to figure out how to find the details of files
    (specifically music for now) for a little sorting script I'm making,
    My aim is to get details on the artist, album, and genre for mp3 and
    wma files (possibly more in the future). My closest match was when I
    stumbled accross PyMedia, but it only supports up to 2.4 (I have 2.5).
    Now I see a bit mentioned on GetFileVersionI nfo, but that doesn't seem
    to help (and most of it went over my head). Is there any module I can
    use to find this sort of data? I'm trying to not make it specialised
    in music, because I may want to extend this to picture, movie, text
    etc. files in the future. Any ideas how I could go about this?
  • Tim Golden

    #2
    Re: Finding file details...

    Kalibr wrote:
    I've been trying to figure out how to find the details of files
    (specifically music for now) for a little sorting script I'm making,
    My aim is to get details on the artist, album, and genre for mp3 and
    wma files (possibly more in the future). My closest match was when I
    stumbled accross PyMedia, but it only supports up to 2.4 (I have 2.5).
    Now I see a bit mentioned on GetFileVersionI nfo, but that doesn't seem
    to help (and most of it went over my head). Is there any module I can
    use to find this sort of data? I'm trying to not make it specialised
    in music, because I may want to extend this to picture, movie, text
    etc. files in the future. Any ideas how I could go about this?
    You don't say, but I assume you're on Windows since you mention
    GetFileVersionI nfo (which doesn't have anything to do with media
    files, by the way) and WMA. There may be packages out there
    to do all this already but if not you'll need to pull in a few disparate
    modules and mix'n'match.

    While ID3 readers (which determine the metadata for MP3) are reasonably
    common few of them come ready-compiled for Windows. I've used Ned
    Batchelder's id3reader [1] successfully for simple tasks so you might try
    that. On the WMA side, you can automate Windows Media Player to get
    metadata. (And it might work for .mp3; I've not tried).

    <code>
    import win32com.client

    player = win32com.client .gencache.Ensur eDispatch ("WMPlayer.OCX" )
    wmedia = player.mediaCol lection.add (r"c:\temp\bell s.mp3")
    try:
    artist = wmedia.getItemI nfo ("Artist")
    finally:
    player.mediaCol lection.remove (wmedia, False)

    print "bells.mp3 has artist", artist

    </code>

    You're going to have to dig around for docs on this one. And it's not
    pretty. Try starting from:



    TJG

    [1] http://nedbatchelder.com/code/modules/id3reader.html

    Comment

    • Kalibr

      #3
      Re: Finding file details...

      On May 29, 7:55 pm, Tim Golden <m...@timgolden .me.ukwrote:
      >
      You don't say, but I assume you're on Windows since you mention
      GetFileVersionI nfo (which doesn't have anything to do with media
      files, by the way) and WMA. There may be packages out there
      to do all this already but if not you'll need to pull in a few disparate
      modules and mix'n'match.
      >
      While ID3 readers (which determine the metadata for MP3) are reasonably
      common few of them come ready-compiled for Windows. I've used Ned
      Batchelder's id3reader [1] successfully for simple tasks so you might try
      that. On the WMA side, you can automate Windows Media Player to get
      metadata. (And it might work for .mp3; I've not tried).
      >
      <code>
      import win32com.client
      >
      player = win32com.client .gencache.Ensur eDispatch ("WMPlayer.OCX" )
      wmedia = player.mediaCol lection.add (r"c:\temp\bell s.mp3")
      try:
      artist = wmedia.getItemI nfo ("Artist")
      finally:
      player.mediaCol lection.remove (wmedia, False)
      >
      print "bells.mp3 has artist", artist
      >
      </code>
      >
      You're going to have to dig around for docs on this one. And it's not
      pretty. Try starting from:
      >

      >
      TJG
      >
      [1]http://nedbatchelder.c om/code/modules/id3reader.html
      Hmm, thanks for the info. Yes, I am using Winders (Vista to be exact)
      and I just assumed that there must be a way to programmaticall y get
      the stuff you get from choosing properties in the right click menu.
      But I guess there isn't (hard to believe, because I can't see MS hard-
      coding each and every file format's metadata into it's OS). I might
      have to learn more about the command prompt ( I hear there is a module
      for fiddling with it) and work from there.

      Cheers for the links though, I will be checking them out :)

      Comment

      • Tim Golden

        #4
        Re: Finding file details...

        Kalibr wrote:
        On May 29, 7:55 pm, Tim Golden <m...@timgolden .me.ukwrote:
        >You don't say, but I assume you're on Windows since you mention
        >GetFileVersion Info (which doesn't have anything to do with media
        >files, by the way) and WMA. There may be packages out there
        >to do all this already but if not you'll need to pull in a few disparate
        >modules and mix'n'match.
        >>
        >While ID3 readers (which determine the metadata for MP3) are reasonably
        >common few of them come ready-compiled for Windows. I've used Ned
        >Batchelder's id3reader [1] successfully for simple tasks so you might try
        >that. On the WMA side, you can automate Windows Media Player to get
        >metadata. (And it might work for .mp3; I've not tried).
        >>
        ><code>
        >import win32com.client
        >>
        >player = win32com.client .gencache.Ensur eDispatch ("WMPlayer.OCX" )
        >wmedia = player.mediaCol lection.add (r"c:\temp\bell s.mp3")
        >try:
        > artist = wmedia.getItemI nfo ("Artist")
        >finally:
        > player.mediaCol lection.remove (wmedia, False)
        >>
        >print "bells.mp3 has artist", artist
        >>
        ></code>
        >>
        >You're going to have to dig around for docs on this one. And it's not
        >pretty. Try starting from:
        >>
        >http://msdn.microsoft.com/en-us/libr...09(VS.85).aspx
        >>
        >TJG
        >>
        >[1]http://nedbatchelder.c om/code/modules/id3reader.html
        >
        Hmm, thanks for the info. Yes, I am using Winders (Vista to be exact)
        and I just assumed that there must be a way to programmaticall y get
        the stuff you get from choosing properties in the right click menu.
        Ah. You didn't quite say that. Well, the thing is that the stuff in
        the right-click menu (I think this is the case) comes from several
        different sources. Some of it's held in Alternate
        Data Streams. Some is Structured Storage within the docs themselves.
        Some is simply, eg, ID3 data held in an MP3 file etc. I don't
        think it all comes from one place. Again, I think.
        But I guess there isn't (hard to believe, because I can't see MS hard-
        coding each and every file format's metadata into it's OS). I might
        have to learn more about the command prompt ( I hear there is a module
        for fiddling with it) and work from there.
        If you come up with useful info, do post back here. It's an area several
        people have enquired about.

        TJG

        Comment

        • Mike Driscoll

          #5
          Re: Finding file details...

          On May 29, 5:26 am, Kalibr <space.captain. f...@gmail.comw rote:
          On May 29, 7:55 pm, Tim Golden <m...@timgolden .me.ukwrote:
          >
          >
          >
          >
          >
          You don't say, but I assume you're on Windows since you mention
          GetFileVersionI nfo (which doesn't have anything to do with media
          files, by the way) and WMA. There may be packages out there
          to do all this already but if not you'll need to pull in a few disparate
          modules and mix'n'match.
          >
          While ID3 readers (which determine the metadata for MP3) are reasonably
          common few of them come ready-compiled for Windows. I've used Ned
          Batchelder's id3reader [1] successfully for simple tasks so you might try
          that. On the WMA side, you can automate Windows Media Player to get
          metadata. (And it might work for .mp3; I've not tried).
          >
          <code>
          import win32com.client
          >
          player = win32com.client .gencache.Ensur eDispatch ("WMPlayer.OCX" )
          wmedia = player.mediaCol lection.add (r"c:\temp\bell s.mp3")
          try:
            artist = wmedia.getItemI nfo ("Artist")
          finally:
            player.mediaCol lection.remove (wmedia, False)
          >
          print "bells.mp3 has artist", artist
          >
          </code>
          >
          You're going to have to dig around for docs on this one. And it's not
          pretty. Try starting from:
          >>
          TJG
          >
          [1]http://nedbatchelder.c om/code/modules/id3reader.html
          >
          Hmm, thanks for the info. Yes, I am using Winders (Vista to be exact)
          and I just assumed that there must be a way to programmaticall y get
          the stuff you get from choosing properties in the right click menu.
          But I guess there isn't (hard to believe, because I can't see MS hard-
          coding each and every file format's metadata into it's OS). I might
          have to learn more about the command prompt ( I hear there is a module
          for fiddling with it) and work from there.
          >
          Cheers for the links though, I will be checking them out :)
          You might also check out the ID3 library:



          It doesn't look like it's been updated for a few years. I tested it on
          XP and it seems to work though.

          I also found this snippet, but it's pretty rudimentary:



          Finally, check out the ID3 Handling section on this site:



          -------
          Mike

          Blog: http://blog.pythonlibrary.org/

          Comment

          • Roger Upole

            #6
            Re: Finding file details...


            Kalibr wrote:
            I've been trying to figure out how to find the details of files
            (specifically music for now) for a little sorting script I'm making,
            My aim is to get details on the artist, album, and genre for mp3 and
            wma files (possibly more in the future). My closest match was when I
            stumbled accross PyMedia, but it only supports up to 2.4 (I have 2.5).
            Now I see a bit mentioned on GetFileVersionI nfo, but that doesn't seem
            to help (and most of it went over my head). Is there any module I can
            use to find this sort of data? I'm trying to not make it specialised
            in music, because I may want to extend this to picture, movie, text
            etc. files in the future. Any ideas how I could go about this?
            You can use the shell COM objects to access media properties
            as shown by Explorer.

            import win32com.client
            sh=win32com.cli ent.Dispatch('S hell.Applicatio n')

            folder= r'M:\Music\Bob Dylan\Highway 61 Revisited'
            ns=sh.NameSpace (folder)

            ## the column index for Artist may vary from folder to folder
            for c in range(0,255):
            colname=ns.GetD etailsOf(None, c)
            if colname=='Artis ts': ## This shows up as just Artist on XP
            for i in ns.Items():
            artist=ns.GetDe tailsOf(i, c)
            if artist:
            print ns.GetDetailsOf (i, 0), artist
            break


            Roger



            Comment

            • Kalibr

              #7
              Re: Finding file details...

              On May 30, 1:41 am, "Roger Upole" <rup...@hotmail .comwrote:
              >
              You can use the shell COM objects to access media properties
              as shown by Explorer.
              >
              import win32com.client
              sh=win32com.cli ent.Dispatch('S hell.Applicatio n')
              >
              folder= r'M:\Music\Bob Dylan\Highway 61 Revisited'
              ns=sh.NameSpace (folder)
              >
              ## the column index for Artist may vary from folder to folder
              for c in range(0,255):
              colname=ns.GetD etailsOf(None, c)
              if colname=='Artis ts': ## This shows up as just Artist on XP
              for i in ns.Items():
              artist=ns.GetDe tailsOf(i, c)
              if artist:
              print ns.GetDetailsOf (i, 0), artist
              break
              >
              Roger
              I shall give that a go. (is the module you reference this one?
              http://python.net/crew/mhammond/win32/Downloads.html )

              Comment

              • Kam-Hung Soh

                #8
                Re: Finding file details...

                Roger Upole wrote:
                Kalibr wrote:
                >I've been trying to figure out how to find the details of files
                >(specificall y music for now) for a little sorting script I'm making,
                >My aim is to get details on the artist, album, and genre for mp3 and
                >wma files (possibly more in the future). My closest match was when I
                >stumbled accross PyMedia, but it only supports up to 2.4 (I have 2.5).
                >Now I see a bit mentioned on GetFileVersionI nfo, but that doesn't seem
                >to help (and most of it went over my head). Is there any module I can
                >use to find this sort of data? I'm trying to not make it specialised
                >in music, because I may want to extend this to picture, movie, text
                >etc. files in the future. Any ideas how I could go about this?
                I think GetFileVersionI nfo() only provides version information for DLL
                and EXE files.

                See: http://msdn.microsoft.com/en-us/library/ms646981.aspx
                >
                You can use the shell COM objects to access media properties
                as shown by Explorer.
                >
                import win32com.client
                sh=win32com.cli ent.Dispatch('S hell.Applicatio n')
                >
                folder= r'M:\Music\Bob Dylan\Highway 61 Revisited'
                ns=sh.NameSpace (folder)
                >
                ## the column index for Artist may vary from folder to folder
                for c in range(0,255):
                colname=ns.GetD etailsOf(None, c)
                if colname=='Artis ts': ## This shows up as just Artist on XP
                for i in ns.Items():
                artist=ns.GetDe tailsOf(i, c)
                if artist:
                print ns.GetDetailsOf (i, 0), artist
                break
                >
                >
                Roger
                Great tip, Roger! This solution works for WMA files (I don't have any
                MP3 files handy), so I think it would work for any media files in Windows.

                --
                Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>

                Comment

                • Roger Upole

                  #9
                  Re: Finding file details...

                  Kalibr wrote:
                  On May 30, 1:41 am, "Roger Upole" <rup...@hotmail .comwrote:
                  >>
                  >You can use the shell COM objects to access media properties
                  >as shown by Explorer.
                  >>
                  >import win32com.client
                  >sh=win32com.cl ient.Dispatch(' Shell.Applicati on')
                  >>
                  >folder= r'M:\Music\Bob Dylan\Highway 61 Revisited'
                  >ns=sh.NameSpac e(folder)
                  >>
                  >## the column index for Artist may vary from folder to folder
                  >for c in range(0,255):
                  > colname=ns.GetD etailsOf(None, c)
                  > if colname=='Artis ts': ## This shows up as just Artist on XP
                  > for i in ns.Items():
                  > artist=ns.GetDe tailsOf(i, c)
                  > if artist:
                  > print ns.GetDetailsOf (i, 0), artist
                  > break
                  >>
                  > Roger
                  >
                  I shall give that a go. (is the module you reference this one?
                  http://python.net/crew/mhammond/win32/Downloads.html )
                  --
                  That's the one.

                  Roger



                  Comment

                  • Kam-Hung Soh

                    #10
                    Re: Finding file details...

                    Kalibr wrote:
                    On May 30, 1:41 am, "Roger Upole" <rup...@hotmail .comwrote:
                    >You can use the shell COM objects to access media properties
                    >as shown by Explorer.
                    >>
                    >import win32com.client
                    >sh=win32com.cl ient.Dispatch(' Shell.Applicati on')
                    >>
                    >folder= r'M:\Music\Bob Dylan\Highway 61 Revisited'
                    >ns=sh.NameSpac e(folder)
                    >>
                    >## the column index for Artist may vary from folder to folder
                    >for c in range(0,255):
                    > colname=ns.GetD etailsOf(None, c)
                    > if colname=='Artis ts': ## This shows up as just Artist on XP
                    > for i in ns.Items():
                    > artist=ns.GetDe tailsOf(i, c)
                    > if artist:
                    > print ns.GetDetailsOf (i, 0), artist
                    > break
                    >>
                    > Roger
                    >
                    I shall give that a go. (is the module you reference this one?
                    http://python.net/crew/mhammond/win32/Downloads.html )
                    If you installed ActiveState's Python, the win32com module should be
                    installed.

                    --
                    Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>

                    Comment

                    • Kalibr

                      #11
                      Re: Finding file details...

                      On May 30, 3:03 pm, Kam-Hung Soh <kamhung....@gm ail.comwrote:
                      Kalibr wrote:
                      On May 30, 1:41 am, "Roger Upole" <rup...@hotmail .comwrote:
                      You can use the shell COM objects to access media properties
                      as shown by Explorer.
                      >
                      import win32com.client
                      sh=win32com.cli ent.Dispatch('S hell.Applicatio n')
                      >
                      folder= r'M:\Music\Bob Dylan\Highway 61 Revisited'
                      ns=sh.NameSpace (folder)
                      >
                      ## the column index for Artist may vary from folder to folder
                      for c in range(0,255):
                      colname=ns.GetD etailsOf(None, c)
                      if colname=='Artis ts': ## This shows up as just Artist on XP
                      for i in ns.Items():
                      artist=ns.GetDe tailsOf(i, c)
                      if artist:
                      print ns.GetDetailsOf (i, 0), artist
                      break
                      >
                      Roger
                      >
                      I shall give that a go. (is the module you reference this one?
                      http://python.net/crew/mhammond/win32/Downloads.html)
                      >
                      If you installed ActiveState's Python, the win32com module should be
                      installed.
                      >
                      --
                      Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>
                      I gave your program a go, and it works magnificently.
                      Now I have to figure out how tro use it on a song by song basis
                      (I still suck at using classes).
                      Thanks so much for your help.

                      Comment

                      Working...