2024-11-20 04:53:04 -04:00
|
|
|
import logging
|
2024-11-20 16:34:20 -04:00
|
|
|
from providers._provider import Provider
|
2024-11-20 04:53:04 -04:00
|
|
|
|
2024-11-20 16:34:20 -04:00
|
|
|
class Bing(Provider):
|
2024-11-20 04:53:04 -04:00
|
|
|
name = "Bing"
|
|
|
|
url = "https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US"
|
|
|
|
idx = 0
|
|
|
|
number = 2**31-1
|
|
|
|
|
|
|
|
def __init__(self, settings, session):
|
|
|
|
super().__init__(settings, session)
|
|
|
|
self.size = settings.get("size")
|
|
|
|
self.country = settings.get("country")
|
|
|
|
self.market = settings.get("market")
|
|
|
|
|
2024-11-20 16:34:20 -04:00
|
|
|
def get_image_info(self):
|
2024-11-20 04:53:04 -04:00
|
|
|
query = f"https://www.bing.com/HPImageArchive.aspx?format=js&idx={self.idx}&n={self.number}&mkt={self.market}"
|
|
|
|
logging.debug(f"Query: {query}")
|
|
|
|
|
|
|
|
response = self.session.get(query).json()
|
2024-11-20 16:34:20 -04:00
|
|
|
# logging.debug(f"Response: {response}")
|
2024-11-20 04:53:04 -04:00
|
|
|
|
|
|
|
image_url = response["images"][0]["urlbase"]
|
2024-11-20 16:34:20 -04:00
|
|
|
logging.debug(f"Image URL: {image_url}")\
|
2024-11-20 04:53:04 -04:00
|
|
|
|
2024-11-20 16:34:20 -04:00
|
|
|
title = response["images"][0]["title"]
|
2024-11-20 04:53:04 -04:00
|
|
|
|
2024-11-20 16:34:20 -04:00
|
|
|
image_url = f"https://www.bing.com{image_url}_{self.size}.jpg"
|
|
|
|
return image_url, title
|