podcasts-match.lua 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env lua
  2. --[[
  3. -- Copyright (c) 2013-2016 Marcus Rohrmoser, http://purl.mro.name/recorder
  4. --
  5. -- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
  6. -- associated documentation files (the "Software"), to deal in the Software without restriction,
  7. -- including without limitation the rights to use, copy, modify, merge, publish, distribute,
  8. -- sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
  9. -- furnished to do so, subject to the following conditions:
  10. --
  11. -- The above copyright notice and this permission notice shall be included in all copies or
  12. -- substantial portions of the Software.
  13. --
  14. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
  15. -- NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. -- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
  17. -- OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  18. -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. --
  20. -- MIT License http://opensource.org/licenses/MIT
  21. ]]
  22. if os.getenv('HTTP_HOST') then
  23. io.write('HTTP/1.1 400 Bad Request', '\n')
  24. io.write('Content-Type: text/plain', '\n')
  25. io.write('Server: RadioPi 2013/lua', '\n')
  26. io.write('\n', 'I\'m not supposed to be run as cgi')
  27. io.write('\n')
  28. io.flush()
  29. os.exit(1)
  30. end
  31. -- ensure Recorder.lua (next to this file) is found:
  32. package.path = arg[0]:gsub("/[^/]+/?$", '') .. "/?.lua;" .. package.path
  33. require'Recorder'
  34. Recorder.chdir2app_root( arg[0] )
  35. if arg[1] == nil or arg[1] == '-?' or arg[1] == '-h'or arg[1] == '--help' then
  36. io.write([[re-match
  37. Usage:
  38. $ app/podcast-match.lua [--dry-run] enclosures/b2/2013/01/20/1405\ musikWelt
  39. ]])
  40. os.exit(0)
  41. end
  42. local dry_run = arg[1] == '--dry-run'
  43. local bcs = {}
  44. for i,bc_id in ipairs(arg) do
  45. local bc = Broadcast.from_file( bc_id )
  46. if bc then table.insert(bcs, bc) end
  47. end
  48. for i,bc in ipairs(bcs) do
  49. io.write('checkng ', bc.id, "\n")
  50. bc:match_podcasts()
  51. for _,pc in pairs( bc:podcasts() ) do
  52. io.write('matched ', pc.id, "\n")
  53. end
  54. if not dry_run then bc:save() end
  55. end