Beispiel #1
0
 def download_img(self):
     try:
         self.img_set[self.img_idx]
     except IndexError:
         self.get_all_img()
         if self.father.switch_frame.abort:
             return
     try:
         data = self.img_set[self.img_idx]
     except IndexError:
         return
     url = ('https://wallpapersite.com/images/wallpapers/' + sub('-', '-1920x1080-', data, count=1))[:-4] + 'jpg'
     tile = 'jpg'
     id_ = search(r'-(\d*)\.jpg$', url).group(1)
     if self.father.config['category'] == '随机':
         self.img_idx += 3
     else:
         self.img_idx += 1
     # 筛选: 不在黑名单
     if id_ not in self.father.data["api"][self.name]['hate_list']:
         # 加上屏幕分辨率裁剪请求
         try:
             img = get(url, stream=True, timeout=3)
         except:
             if not self.father.switch_frame.abort:
                 self.download_img()
             return
         try:
             length = int(img.headers['Content-Length'])
         except KeyError:
             length = 1024
         # 传输正常且大小正常
         if img.ok and length / 1000000 <= self.father.config['length']:
             download_rate = 0
             with open('image/wall.' + tile, 'wb') as fp:
                 try:
                     for part in img.iter_content(length // 100):
                         # 中断
                         if self.father.switch_frame.abort:
                             fp.close()
                             return
                         fp.write(part)
                         download_rate += 1
                         self.father.switch_frame.white_label.move(0, -download_rate // 2)
                 except:
                     self.father.switch_frame.abort = True
                     return
                 fp.close()
                 im = im_open('image/wall.' + tile)
                 process_img(im, self.father.resolving)
                 self.father.last_api = self.name
                 self.current_id = id_
                 self.current_data = data
         else:
             self.download_img()
     else:
         self.download_img()
Beispiel #2
0
 def download_img(self):
     try:
         self.img_set[self.img_idx]
     except IndexError:
         self.get_all_img()
         if self.father.switch_frame.abort:
             return
     try:
         data = self.img_set[self.img_idx]
     except IndexError:
         return
     width, height, url, id_ = data
     tile = search(r'.*\.([a-zA-Z]{3,4})$', url).group(1)
     if self.father.config['category'] == '随机':
         self.img_idx += 3
     else:
         self.img_idx += 1
     # 筛选: 分辨率比屏幕大, 不在黑名单
     if id_ not in self.father.data["api"][self.name]['hate_list'] and int(width) >= self.father.resolving[0] and int(height) >= self.father.resolving[1]:
         # 加上屏幕分辨率裁剪请求
         try:
             img = get(url + '?crop=entropy&cs=srgb&fit=crop&fm=jpg&h=%s&w=%s' % (self.father.resolving[1], self.father.resolving[0]), stream=True, timeout=3)
         except:
             if not self.father.switch_frame.abort:
                 self.download_img()
             return
         try:
             length = int(img.headers['Content-Length'])
         except KeyError:
             length = 1024
         # 传输正常且大小正常
         if img.ok and length / 1000000 <= self.father.config['length']:
             download_rate = 0
             with open('image/wall.' + tile, 'wb') as fp:
                 try:
                     for part in img.iter_content(length // 100):
                         # 中断
                         if self.father.switch_frame.abort:
                             fp.close()
                             return
                         fp.write(part)
                         download_rate += 1
                         self.father.switch_frame.white_label.move(0, -download_rate // 2)
                 except:
                     self.father.switch_frame.abort = True
                     return
                 fp.close()
                 im = im_open('image/wall.' + tile)
                 process_img(im, self.father.resolving)
                 self.father.last_api = self.name
                 self.current_id = id_
                 self.current_data = data
         else:
             self.download_img()
     else:
         self.download_img()
Beispiel #3
0
 def static_download(self):
     if not self.father.data['api'][self.name]['like_list']:
         return False
     else:
         data = choice(self.father.data['api']['Unsplash']['like_list'])[1]
         id_, width, height, url = data
         tile = 'jpg'
         # 加上屏幕分辨率裁剪请求
         try:
             img = get(
                 url +
                 '?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&fit=crop&h=%s&w=%s&cs=srgb.jpg'
                 % (self.father.resolving[1], self.father.resolving[0]),
                 stream=True,
                 timeout=3)
         except:
             if not self.father.switch_frame.abort:
                 self.static_download()
             return True
         try:
             length = int(img.headers['Content-Length'])
         except KeyError:
             length = 1024
         # 传输正常
         if img.ok:
             download_rate = 0
             with open('image/wall.' + tile, 'wb') as fp:
                 try:
                     for part in img.iter_content(length // 100):
                         # 中断
                         if self.father.switch_frame.abort:
                             fp.close()
                             return
                         fp.write(part)
                         download_rate += 1
                         self.father.switch_frame.white_label.move(
                             0, -download_rate // 2)
                 except:
                     self.father.switch_frame.abort = True
                     return
                 fp.close()
                 im = im_open('image/wall.' + tile)
                 process_img(im, self.father.resolving)
                 self.father.last_api = self.name
                 self.current_id, self.current_data = id_, data
                 return True
         else:
             self.static_download()
Beispiel #4
0
 def static_download(self):
     if not self.father.data['api'][self.name]['like_list']:
         return False
     else:
         data = choice(self.father.data['api']['Pixabay']['like_list'])[1]
         url = data
         id_ = search(r'.*?(\d*)$', url).group(1)
         try:
             img = get('https://pixabay.com/tr/images/download/' + url +
                       '_1920.jpg?attachment',
                       headers=self.header,
                       stream=True,
                       timeout=3)
         except:
             if not self.father.switch_frame.abort:
                 self.static_download()
             return True
         tile = 'jpg'
         try:
             length = int(img.headers['Content-Length'])
         except KeyError:
             length = 1024
         # 传输正常
         if img.ok:
             download_rate = 0
             with open('image/wall.' + tile, 'wb') as fp:
                 try:
                     for part in img.iter_content(length // 100):
                         # 中断
                         if self.father.switch_frame.abort:
                             fp.close()
                             return
                         fp.write(part)
                         download_rate += 1
                         self.father.switch_frame.white_label.move(
                             0, -download_rate // 2)
                 except:
                     self.father.switch_frame.abort = True
                     return
                 fp.close()
                 im = im_open('image/wall.' + tile)
                 process_img(im, self.father.resolving)
                 self.father.last_api = self.name
                 self.current_id, self.current_data = id_, data
                 return True
         else:
             self.static_download()
Beispiel #5
0
 def static_download(self):
     if not self.father.data['api'][self.name]['like_list']:
         return False
     else:
         data = choice(self.father.data['api']['Baidu']['like_list'])[1]
         url, width, height, id_ = data
         try:
             img = get(url, stream=True, timeout=3)
             tile = search('.*?/([a-zA-Z]{3,4})$',
                           img.headers['Content-Type']).group(1)
         except:
             if not self.father.switch_frame.abort and self.repeat <= 20:
                 self.repeat += 1
                 self.static_download()
             return True
         try:
             length = int(img.headers['Content-Length'])
         except KeyError:
             length = 1024
         # 传输正常且大小正常
         if img.ok:
             download_rate = 0
             with open('image/wall.' + tile, 'wb') as fp:
                 try:
                     for part in img.iter_content(length // 100):
                         # 中断
                         if self.father.switch_frame.abort:
                             fp.close()
                             return
                         fp.write(part)
                         download_rate += 1
                         self.father.switch_frame.white_label.move(
                             0, -download_rate // 2)
                 except:
                     self.father.switch_frame.abort = True
                     return
                 fp.close()
                 im = im_open('image/wall.' + tile)
                 process_img(im, self.father.resolving)
                 self.father.last_api = self.name
                 self.current_id, self.current_data = id_, data
                 self.repeat = 0
                 return True
         else:
             self.static_download()
Beispiel #6
0
 def static_download(self):
     if not self.father.data['api'][self.name]['like_list']:
         return False
     else:
         data = choice(self.father.data['api']['Pexels']['like_list'])[1]
         url = ('https://wallpapersite.com/images/wallpapers/' + sub('-', '-1920x1080-', data, count=1))[:-4] + 'jpg'
         tile = 'jpg'
         id_ = search(r'-(\d*)\.jpg$', url).group(1)
         try:
             img = get(url, stream=True, timeout=3)
         except:
             if not self.father.switch_frame.abort:
                 self.static_download()
             return True
         try:
             length = int(img.headers['Content-Length'])
         except KeyError:
             length = 1024
         # 传输正常且大小正常
         if img.ok:
             download_rate = 0
             with open('image/wall.' + tile, 'wb') as fp:
                 try:
                     for part in img.iter_content(length // 100):
                         # 中断
                         if self.father.switch_frame.abort:
                             fp.close()
                             return
                         fp.write(part)
                         download_rate += 1
                         self.father.switch_frame.white_label.move(0, -download_rate // 2)
                 except:
                     self.father.switch_frame.abort = True
                     return
                 fp.close()
                 im = im_open('image/wall.' + tile)
                 process_img(im, self.father.resolving)
                 self.father.last_api = self.name
                 self.current_id, self.current_data = id_, data
                 return True
         else:
             self.static_download()
Beispiel #7
0
 def download_img(self):
     try:
         self.img_set[self.img_idx]
     except IndexError:
         self.get_all_img()
         if self.father.switch_frame.abort:
             return
     try:
         data = self.img_set[self.img_idx]
     except IndexError:
         return
     url = data
     id_ = search(r'.*?(\d*)$', url).group(1)
     try:
         img = get('https://pixabay.com/tr/images/download/' + url +
                   '_1920.jpg?attachment',
                   headers=self.header,
                   stream=True,
                   timeout=3)
     except:
         if not self.father.switch_frame.abort:
             self.download_img()
         return
     tile = 'jpg'
     if self.father.config['category'] == '随机':
         self.img_idx += 3
     else:
         self.img_idx += 1
     # 筛选: 不在黑名单
     if id_ not in self.father.data["api"][self.name]['hate_list']:
         try:
             length = int(img.headers['Content-Length'])
         except KeyError:
             length = 1024
         # 传输正常且大小正常
         if img.ok and length / 1000000 <= self.father.config['length']:
             download_rate = 0
             with open('image/wall.' + tile, 'wb') as fp:
                 try:
                     for part in img.iter_content(length // 100):
                         # 中断
                         if self.father.switch_frame.abort:
                             fp.close()
                             return
                         fp.write(part)
                         download_rate += 1
                         self.father.switch_frame.white_label.move(
                             0, -download_rate // 2)
                 except:
                     self.father.switch_frame.abort = True
                     return
                 fp.close()
                 im = im_open('image/wall.' + tile)
                 process_img(im, self.father.resolving)
                 self.father.last_api = self.name
                 self.current_id = id_
                 self.current_data = data
         else:
             self.download_img()
     else:
         self.download_img()
Beispiel #8
0
 def download_img(self):
     try:
         self.img_set[self.img_idx]
     except IndexError:
         self.get_all_img()
         if self.father.switch_frame.abort:
             return
     try:
         data = self.img_set[self.img_idx]
     except IndexError:
         return
     url, id_ = data
     if self.father.config['category'] == '随机':
         self.img_idx += 3
     else:
         self.img_idx += 1
     # 筛选: 分辨率比屏幕大, 不在黑名单
     if id_ not in self.father.data["api"][self.name]['hate_list']:
         try:
             img = get(url, stream=True, timeout=3)
             tile = search('.*?/([a-zA-Z]{3,4})$', img.headers['Content-Type']).group(1)
         except:
             if not self.father.switch_frame.abort and self.repeat <= 20:
                 self.repeat += 1
                 self.download_img()
             return
         try:
             length = int(img.headers['Content-Length'])
         except KeyError:
             length = 1024
         # 传输正常且大小正常
         if img.ok and length / 1000000 <= self.father.config['length']:
             download_rate = 0
             with open('image/wall.' + tile, 'wb') as fp:
                 try:
                     for part in img.iter_content(length // 100):
                         # 中断
                         if self.father.switch_frame.abort:
                             fp.close()
                             return
                         fp.write(part)
                         download_rate += 1
                         self.father.switch_frame.white_label.move(0, -download_rate // 2)
                 except:
                     self.father.switch_frame.abort = True
                     return
                 fp.close()
                 im = im_open('image/wall.' + tile)
                 if im.width >= self.father.resolving[0] and im.height >= self.father.resolving[1]:
                     process_img(im, self.father.resolving)
                 else:
                     self.download_img()
                     return
                 self.father.last_api = self.name
                 self.current_id = id_
                 self.current_data = data
                 self.repeat = 0
         else:
             self.download_img()
     else:
         self.download_img()