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