Last active
September 18, 2019 02:38
-
-
Save aont/48561966b2221359f4af8aebe16c92c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| import sys | |
| import json | |
| import re | |
| import requests | |
| # import requests_cache | |
| import os | |
| import hashlib | |
| def get_chromecast_wallpapers(): | |
| # requests_cache.install_cache('chromecast') | |
| chromecast_home = 'https://clients3.google.com/cast/chromecast/home' | |
| sess = requests.session() | |
| result = sess.get(chromecast_home) | |
| json_pattern = re.compile("\'initialStateJson\', JSON[.]parse\\((\'(.*?)(?<!\\\\)\')\\)") | |
| json_match = json_pattern.search(result.text) | |
| if json_match is None: | |
| raise Exception('unexpected') | |
| json_str = eval(json_match.group(1)) | |
| js = json.loads(json_str) | |
| result_ary = [] | |
| for obj in js[0]: | |
| result_ary.append(obj[0]) | |
| return result_ary | |
| def download_wallpapers(wallpapers): | |
| sess = requests.session() | |
| for wallpaper in wallpapers: | |
| sys.stderr.write('[Info] downloading %s\n' % wallpaper) | |
| img_result = sess.get(wallpaper) | |
| save_path = hashlib.md5(img_result.content).hexdigest() + '.jpg' | |
| with open(save_path, 'wb') as save_file: | |
| save_file.write(img_result.content) | |
| if __name__ == '__main__': | |
| wallpapers = get_chromecast_wallpapers() | |
| sys.stderr.write('[Info] get %s results\n' % len(wallpapers)) | |
| # for wallpaper in wallpapers: | |
| # sys.stderr.write('[Info] %s\n' % wallpaper) | |
| download_wallpapers(wallpapers) | |
| exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment