__init__.py 725 B

12345678910111213141516171819202122232425262728
  1. import asyncio
  2. import config
  3. from .download import download_playlist, download_video
  4. from .intervals import get_intervals
  5. from .info import get_video
  6. async def download(url, path, filename=None):
  7. """ Download a given url to path
  8. if url is video you may set output filename
  9. """
  10. is_video = "watch?" in url or ".be/" in url
  11. is_playlist = "playlist?" in url
  12. if is_playlist:
  13. return (await download_playlist(url, path)), None
  14. elif is_video:
  15. if config.tracklist:
  16. description = config.tracklist
  17. else:
  18. video = await get_video(url, path)
  19. description = video["description"]
  20. intervals = get_intervals(description)
  21. task = asyncio.create_task(download_video(url, path, filename))
  22. return [task], intervals