Improved steam icon 'detection'

This commit is contained in:
Maxim Stewart 2019-06-18 19:17:29 -05:00
parent f5464cd070
commit f147922ca8
5 changed files with 65 additions and 49 deletions

View File

@ -2,7 +2,7 @@
Pytop is a Gtk + Python gui to have a custom desktop interface.
# Notes
Need python 3
```sudo apt-get install python3 steamcmd
# TODO
<ul>

View File

@ -42,6 +42,9 @@ class Grid:
self.desktop.connect("item-activated", self.iconLeftClickEventManager)
self.desktop.connect("button_press_event", self.iconRightClickEventManager, (self.desktop,))
self.vidsList = ('.mkv', '.avi', '.flv', '.mov', '.m4v', '.mpg', '.wmv', '.mpeg', '.mp4', '.webm')
self.imagesList = ('.png', '.jpg', '.jpeg', '.gif', '.ico', '.tga')
self.setIconViewDir(newPath)
def setIconViewDir(self, path):
@ -49,6 +52,9 @@ class Grid:
self.currentPath = path
dirPaths = ['.', '..']
vids = []
images = []
desktop = []
files = []
for f in listdir(path):
@ -57,13 +63,24 @@ class Grid:
if f.startswith('.'):
continue
if isfile(file):
files.append(f)
if file.lower().endswith(self.vidsList):
vids.append(f)
elif file.lower().endswith(self.imagesList):
images.append(f)
elif file.lower().endswith((".desktop",)):
desktop.append(f)
else:
files.append(f)
else:
dirPaths.append(f)
dirPaths.sort()
vids.sort()
images.sort()
desktop.sort()
files.sort()
files = dirPaths + files
files = dirPaths + vids + images + desktop + files
self.generateDirectoryGrid(path, files)
@threaded

View File

@ -11,7 +11,6 @@ from xdg.DesktopEntry import DesktopEntry
# Python Imports
import os, subprocess, hashlib, threading
import urllib.request as urllib
from os.path import isdir, isfile, join
@ -33,9 +32,6 @@ class Icon:
self.systemIconImageWxH = settings.returnSystemIconImageWH()
self.viIconWxH = settings.returnVIIconWH()
user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3'
self.headers = { 'User-Agent' : user_agent }
def createIcon(self, dir, file):
fullPath = dir + "/" + file
@ -101,32 +97,27 @@ class Icon:
hashImgpth = steamIconsDir + fileHash + ".jpg"
if isfile(hashImgpth) == True:
return self.createIconImageBuffer(hashImgpth, self.systemIconImageWxH)
# Use video sizes since headers are bigger
return self.createIconImageBuffer(hashImgpth, self.viIconWxH)
execStr = xdgObj.getExec()
parts = execStr.split("steam://rungameid/")
id = parts[len(parts) - 1]
url = "https://steamdb.info/app/" + id + "/"
request = urllib.Request(url, None, self.headers)
response = urllib.urlopen(request)
page = response.read().decode("utf8")
response.close() # its always safe to close an open connection
imageHTML = ""
imageLink = ""
# NOTE: Can try this logic instead...
# if command exists use it instead of header image
# if "steamcmd app_info_print id":
# proc = subprocess.Popen(["steamcmd", "app_info_print", id])
# proc.wait()
# else:
# use the bottom logic
for line in page.split("\n"):
if "app-icon avatar" in line:
imageHTML = line.strip()
break
srcPart = imageHTML.split()
srcPart = srcPart[3].split("\"")
imageLink = srcPart[1]
proc = subprocess.Popen(["wget", "-O", hashImgpth, imageLink])
imageLink = "https://steamcdn-a.akamaihd.net/steam/apps/" + id + "/header.jpg"
proc = subprocess.Popen(["wget", "-O", hashImgpth, imageLink])
proc.wait()
return self.createIconImageBuffer(hashImgpth, self.systemIconImageWxH)
# Use video sizes since headers are bigger
return self.createIconImageBuffer(hashImgpth, self.viIconWxH)
elif os.path.exists(icon):
return self.createIconImageBuffer(icon, self.systemIconImageWxH)
else:

View File

@ -42,6 +42,9 @@ class Grid:
self.desktop.connect("item-activated", self.iconLeftClickEventManager)
self.desktop.connect("button_press_event", self.iconRightClickEventManager, (self.desktop,))
self.vidsList = ('.mkv', '.avi', '.flv', '.mov', '.m4v', '.mpg', '.wmv', '.mpeg', '.mp4', '.webm')
self.imagesList = ('.png', '.jpg', '.jpeg', '.gif', '.ico', '.tga')
self.setIconViewDir(newPath)
def setIconViewDir(self, path):
@ -49,6 +52,9 @@ class Grid:
self.currentPath = path
dirPaths = ['.', '..']
vids = []
images = []
desktop = []
files = []
for f in listdir(path):
@ -57,13 +63,24 @@ class Grid:
if f.startswith('.'):
continue
if isfile(file):
files.append(f)
if file.lower().endswith(self.vidsList):
vids.append(f)
elif file.lower().endswith(self.imagesList):
images.append(f)
elif file.lower().endswith((".desktop",)):
desktop.append(f)
else:
files.append(f)
else:
dirPaths.append(f)
dirPaths.sort()
vids.sort()
images.sort()
desktop.sort()
files.sort()
files = dirPaths + files
files = dirPaths + vids + images + desktop + files
self.generateDirectoryGrid(path, files)
@threaded

View File

@ -11,7 +11,6 @@ from xdg.DesktopEntry import DesktopEntry
# Python Imports
import os, subprocess, hashlib, threading
import urllib.request as urllib
from os.path import isdir, isfile, join
@ -33,9 +32,6 @@ class Icon:
self.systemIconImageWxH = settings.returnSystemIconImageWH()
self.viIconWxH = settings.returnVIIconWH()
user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3'
self.headers = { 'User-Agent' : user_agent }
def createIcon(self, dir, file):
fullPath = dir + "/" + file
@ -101,32 +97,27 @@ class Icon:
hashImgpth = steamIconsDir + fileHash + ".jpg"
if isfile(hashImgpth) == True:
return self.createIconImageBuffer(hashImgpth, self.systemIconImageWxH)
# Use video sizes since headers are bigger
return self.createIconImageBuffer(hashImgpth, self.viIconWxH)
execStr = xdgObj.getExec()
parts = execStr.split("steam://rungameid/")
id = parts[len(parts) - 1]
url = "https://steamdb.info/app/" + id + "/"
request = urllib.Request(url, None, self.headers)
response = urllib.urlopen(request)
page = response.read().decode("utf8")
response.close() # its always safe to close an open connection
imageHTML = ""
imageLink = ""
# NOTE: Can try this logic instead...
# if command exists use it instead of header image
# if "steamcmd app_info_print id":
# proc = subprocess.Popen(["steamcmd", "app_info_print", id])
# proc.wait()
# else:
# use the bottom logic
for line in page.split("\n"):
if "app-icon avatar" in line:
imageHTML = line.strip()
break
srcPart = imageHTML.split()
srcPart = srcPart[3].split("\"")
imageLink = srcPart[1]
proc = subprocess.Popen(["wget", "-O", hashImgpth, imageLink])
imageLink = "https://steamcdn-a.akamaihd.net/steam/apps/" + id + "/header.jpg"
proc = subprocess.Popen(["wget", "-O", hashImgpth, imageLink])
proc.wait()
return self.createIconImageBuffer(hashImgpth, self.systemIconImageWxH)
# Use video sizes since headers are bigger
return self.createIconImageBuffer(hashImgpth, self.viIconWxH)
elif os.path.exists(icon):
return self.createIconImageBuffer(icon, self.systemIconImageWxH)
else: