screenshot_to_farbfeld.lua 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. local msg = require "mp.msg"
  2. local utils = require "mp.utils"
  3. local opts = {
  4. bzip2 = "1",
  5. screen_subtitles = "s",
  6. screen_video = "S",
  7. screen_window = "Ctrl+s"
  8. }(require 'mp.options').read_options(opts, "screenshot_to_farbfeld")
  9. local home = os.getenv("HOME")
  10. local tempFile=home .. "/.cache/mpv_screen_tmp.png"
  11. local screenshotDir=mp.get_property("screenshot-directory")
  12. screenshotDir=mp.command_native({"expand-path", screenshotDir})
  13. if screenshotDir == "" or screenshotDir == nil then
  14. local popen=io.popen("xdg-user-dir PICTURES")
  15. local default_dir=popen:read("l")
  16. popen:close()
  17. if default_dir == nil then
  18. default_dir = home
  19. end
  20. screenshotDir = utils.join_path(default_dir, "mpv")
  21. os.execute("mkdir -p " .. screenshotDir)
  22. msg.log("warn", "No screenshot folder configured! Defaulting to " .. screenshotDir )
  23. end
  24. local function screenshotToFarbfeld(type)
  25. local error=false
  26. local filename = string.gsub(string.gsub(mp.get_property("filename"), "'", '"'), "%.%w*$", "") .. " " .. mp.get_property("playback-time") .. ".ff"
  27. local screenshotName = utils.join_path(screenshotDir, filename)
  28. mp.commandv("screenshot-to-file", tempFile, type)
  29. if os.execute("convert " .. tempFile .. " '" .. screenshotName .. "'") > 0 then
  30. error = true
  31. msg.log("error", "Could not make screenshot " .. filename)
  32. end
  33. if opts.bzip2 == "1" then
  34. if not (os.execute("bzip2 -f '" .. screenshotName .. "'") > 0) then
  35. filename = filename .. ".bz2"
  36. else
  37. msg.log("error", "Could not compress '" .. filename .. "'")
  38. error = true
  39. end
  40. end
  41. if error then
  42. mp.osd_message("Screenshot Failed", 5)
  43. else
  44. mp.osd_message("Screenshot Taken: " .. filename, 5)
  45. end
  46. os.remove(tempFile)
  47. end
  48. local function screenshotVideo()
  49. screenshotToFarbfeld("video")
  50. end
  51. local function screenshotSubtitles()
  52. screenshotToFarbfeld("subtitles")
  53. end
  54. local function screenshotWindow()
  55. screenshotToFarbfeld("window")
  56. end
  57. mp.add_key_binding(opts.screen_subtitles, "FFScreenub", screenshotSubtitles)
  58. mp.add_key_binding(opts.screen_video, "FFScreenVid", screenshotVideo)
  59. mp.add_key_binding(opts.screen_win, "FFScreenWin", screenshotWindow)