Python Forum
How to get a removable disc type in drive
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get a removable disc type in drive
#12
(Feb-08-2024, 06:35 AM)Gribouillis Wrote:
(Feb-08-2024, 05:56 AM)Daring_T Wrote: Also here is what a blue-ray looks like with running dict(dev.properties):
The property ID_CDROM_MEDIA_BD tells you that there is a blueray disk

If anyone needs it, I have also added support for CD-ROMS as shown below.

def get_drive_type(drive_name="sr0"):
    '''Returns the type of Disc in Drive'''

    context = pyudev.Context()
    a = context.list_devices(sys_name=drive_name)
    dev = next(iter(a))

    disc_type = None

    if dev.properties.get("ID_CDROM_MEDIA_CD", False):
        if dev.properties.get('ID_FS_USAGE', False):
            disc_type = "CDROM"
        else:
            disc_type = "CDAUDIO"

    elif dev.properties.get("ID_CDROM_MEDIA_DVD", False):
        disc_type = "DVD"

    elif dev.properties.get("ID_CDROM_MEDIA_BD", False):
        disc_type = "BLUERAY"
    
    return disc_type


if __name__ == "__main__":
    disc_type = get_drive_type(drive_name="sr0")

    print(f"Drive: {drive_name} contains a: {disc_type}.")
Reply


Messages In This Thread
RE: How to get a removable disc type in drive - by Daring_T - Feb-11-2024, 07:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  open python files in other drive akbarza 1 761 Aug-24-2023, 01:23 PM
Last Post: deanhystad
  Integrating Google Drive in App Lahearle 0 506 Jul-19-2023, 05:51 PM
Last Post: Lahearle
  code to send attachments contained on the drive. stefanoste78 1 932 Oct-12-2022, 02:16 AM
Last Post: Larz60+
  access is denied error 5 for network drive mapping ? ahmedbarbary 2 1,868 Aug-17-2022, 10:09 PM
Last Post: ahmedbarbary
  Cant Access D: Drive kucingkembar 4 1,444 Jul-28-2022, 04:53 PM
Last Post: kucingkembar
  Calling exe on network drive GrahamL 4 2,666 Jan-21-2022, 12:01 PM
Last Post: GrahamL
  Failing to copy file from a network to a local drive tester_V 4 7,294 Jan-20-2021, 07:40 AM
Last Post: tester_V
  Type hinting - return type based on parameter micseydel 2 2,555 Jan-14-2020, 01:20 AM
Last Post: micseydel
  Nested Subdirectory within current sub on shared network drive Agregware 1 1,984 Jun-19-2019, 10:07 PM
Last Post: Gribouillis
  trouble with os.listdir on a network drive lconner 10 19,326 Jun-04-2019, 07:16 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020