Ok, so I am trying to create a program that allows the background of my Gnome desktop to tap into the stream of wallpapers used by Google's chromecast devices.
(好的,所以我正在尝试创建一个程序,该程序允许Gnome桌面的背景利用Google chromecast设备使用的壁纸流。)
Currently I use a loop function in Python that uses selenium and a Chrome webdriver to get the images that are dynamically displayed here:
(目前,我在Python中使用一个使用硒的循环函数和一个Chrome网络驱动程序来获取在此处动态显示的图像:)
https://clients3.google.com/cast/chromecast/home/
(https://clients3.google.com/cast/chromecast/home/)
My function works exactly like I want it to.
(我的功能完全像我想要的那样工作。)
However the problem is > whenever I visit this website in a browser it starts displaying random wallpapers in a random order, there seems to be a big selection of possible wallpapers, but whenever you reload the page it always shows only about 5 (max) different wallpapers.. since my script reloads the page in each loop, I only get about 5 different wallpapers out of it, while there should be a multitude of that available via the website. (但是问题是 >每当我在浏览器中访问该网站时,它就会开始以随机顺序显示随机壁纸,似乎有很多可能的壁纸可供选择,但是每当您重新加载页面时,它总是仅显示大约5(最大)个不同墙纸..由于我的脚本在每个循环中都会重新加载页面,因此我只能从中获得大约5种不同的墙纸,而网站上应该有大量可用的墙纸。)
That leads me to question : Can I use selenium for Python to somehow trick the website into thinking I've been around longer then just a few seconds and thereby maybe showing me a different wallpaper?
(这就引出了一个问题 :我可以使用Selenium for Python欺骗网站,让我认为自己待了更长的时间才几秒钟,从而可能给我展示了不同的墙纸吗?)
NB : I know I could also get the wallpapers from non-dynamic websites such as this one , I already got that one to work, but the goal now is to actually tap into the live Chromecast stream.
(NB :我知道我也可以从非动态网站(例如该网站)获取壁纸,我已经可以使用它了,但是现在的目标是实际使用实时Chromecast流。)
I've searched if there might be an API somewhere for it, but couldn't find one so decided to go with my current approach. (我搜索了某个地方是否有API,但是找不到一个决定使用我当前方法的API。)
My current code:
(我当前的代码:)
import io
import os
from PIL import Image
from pyvirtualdisplay import Display
from random import shuffle
import requests
import sched
from selenium import webdriver
import subprocess
import time
s = sched.scheduler(time.time, time.sleep)
def change_desktop():
display = Display(visible=0, size=(800, 600))
display.start()
browser = webdriver.Chrome()
urllist = ["https://clients3.google.com/cast/chromecast/home/v/c9541b08", "https://clients3.google.com/cast/chromecast/home"]
shuffle(urllist)
browser.get(urllist[0])
element = browser.find_element_by_id("picture-background")
image_source = element.get_attribute("src")
browser.quit()
display.stop()
request = requests.get(image_source)
image = Image.open(io.BytesIO(request.content))
image_format = image.format
current_dir = os.path.dirname(os.path.realpath(__file__))
temp_local_image_location = current_dir + "/interactive_wallpaper." + image_format
image.save(temp_local_image_location)
subprocess.Popen(["/usr/bin/gsettings", "set", "org.gnome.desktop.background", "picture-uri", "'" + temp_local_image_location + "'"], stdout=subprocess.PIPE)
s.enter(30, 1, change_desktop())
s.enter(30, 1, change_desktop())
s.run()
ask by Montmons translate from so