downloads.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import sys, os
  2. from plugins.plugin import Plugin
  3. sys.path.append("..")
  4. from src.video import Video
  5. from src.config import Config
  6. from src.history import History
  7. class Downloads(Plugin):
  8. def __init__(self, history: History=History(), config: Config=Config()) -> None:
  9. super().__init__(history, config)
  10. self.history = history
  11. self.config = config
  12. self.name = "[+] Downloads"
  13. self.category = "Downloads"
  14. self.query_description = """"""
  15. self.params = {
  16. "path" : False
  17. }
  18. self.flag = "-d"
  19. self.full_flag = "--downloads"
  20. self.flag_help = "show rosen downloads list"
  21. self.flag_action = "store_true"
  22. self.extensions = ('.mp3', '.mp4', '.mkv', '.webm', '.m3u')
  23. def get_downloads(self, path):
  24. items = []
  25. path = os.path.expanduser('~') + "/" + path
  26. for filename in os.listdir(path):
  27. if filename.endswith(self.extensions):
  28. video = Video(playlist_title=filename,
  29. url=path+"/"+filename)
  30. items.append(video.to_json())
  31. return items
  32. def get_items(self, params):
  33. path = "Downloads"
  34. if 'path' in params:
  35. path = params['path']
  36. return self.get_downloads(path)