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.

41 lines
1.2 KiB

  1. #!/usr/bin/env python
  2. from __future__ import unicode_literals
  3. import json
  4. import os
  5. import re
  6. import sys
  7. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  8. from youtube_dl.compat import (
  9. compat_print,
  10. compat_urllib_request,
  11. )
  12. from youtube_dl.utils import format_bytes
  13. def format_size(bytes):
  14. return '%s (%d bytes)' % (format_bytes(bytes), bytes)
  15. total_bytes = 0
  16. releases = json.loads(compat_urllib_request.urlopen(
  17. 'https://api.github.com/repos/rg3/youtube-dl/releases').read().decode('utf-8'))
  18. for release in releases:
  19. compat_print(release['name'])
  20. for asset in release['assets']:
  21. asset_name = asset['name']
  22. total_bytes += asset['download_count'] * asset['size']
  23. if all(not re.match(p, asset_name) for p in (
  24. r'^youtube-dl$',
  25. r'^youtube-dl-\d{4}\.\d{2}\.\d{2}(?:\.\d+)?\.tar\.gz$',
  26. r'^youtube-dl\.exe$')):
  27. continue
  28. compat_print(
  29. ' %s size: %s downloads: %d'
  30. % (asset_name, format_size(asset['size']), asset['download_count']))
  31. compat_print('total downloads traffic: %s' % format_size(total_bytes))