Python Library Media
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

common.py 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import os
  2. import logging
  3. try:
  4. from config import APP_NAME as ROOT_LOGGER_NAME
  5. except ImportError:
  6. ROOT_LOGGER_NAME = 'root'
  7. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  8. # make module usable without discid dependency
  9. try:
  10. import discid
  11. except ModuleNotFoundError:
  12. logger.warning("Python module discid not installed")
  13. except OSError:
  14. logger.exception("You might install python3-libdiscid")
  15. KEY_ALBUM = 'album'
  16. KEY_APERTURE = 'aperture'
  17. KEY_ARTIST = 'artist'
  18. KEY_BITRATE = 'bitrate'
  19. KEY_CAMERA = 'camera'
  20. KEY_DURATION = 'duration'
  21. KEY_EXPOSURE_PROGRAM = 'exposure_program'
  22. KEY_EXPOSURE_TIME = 'exposure_time'
  23. KEY_FLASH = 'flash'
  24. KEY_FOCAL_LENGTH = 'focal_length'
  25. KEY_GENRE = 'genre'
  26. KEY_GPS = 'gps'
  27. KEY_HEIGHT = 'height'
  28. KEY_ISO = 'iso'
  29. KEY_ORIENTATION = 'orientation'
  30. KEY_RATIO = 'ratio'
  31. KEY_SIZE = 'size'
  32. KEY_TIME = 'time' # USE time.localtime(value) or datetime.fromtimestamp(value) to convert the timestamp
  33. KEY_TIME_IS_SUBSTITUTION = 'tm_is_subst'
  34. KEY_TITLE = 'title'
  35. KEY_TRACK = 'track'
  36. KEY_WIDTH = 'width'
  37. KEY_YEAR = 'year'
  38. FILETYPE_AUDIO = 'audio'
  39. FILETYPE_IMAGE = 'image'
  40. FILETYPE_VIDEO = 'video'
  41. FILETYPE_DISC = 'disc'
  42. CALLBACK_CDDB_CHOICE = 0
  43. CALLBACK_MAN_INPUT = 1
  44. EXTENTIONS_AUDIO = ['.mp3', ]
  45. EXTENTIONS_IMAGE = ['.jpg', '.jpeg', '.jpe', '.png', '.tif', '.tiff', '.gif', ]
  46. EXTENTIONS_VIDEO = ['.avi', '.mpg', '.mpeg', '.mpe', '.mov', '.qt', '.mp4', '.webm', '.ogv', '.flv', '.3gp', ]
  47. PREFIX_DISC = '/dev/'
  48. def get_filetype(full_path):
  49. ext = os.path.splitext(full_path.lower())[1]
  50. if ext in EXTENTIONS_AUDIO:
  51. return FILETYPE_AUDIO
  52. elif ext in EXTENTIONS_IMAGE:
  53. return FILETYPE_IMAGE
  54. elif ext in EXTENTIONS_VIDEO:
  55. return FILETYPE_VIDEO
  56. elif full_path.startswith(PREFIX_DISC):
  57. return FILETYPE_DISC
  58. def get_disc_device():
  59. return discid.get_default_device()