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.

47 lines
1.3 KiB

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