Improved steam icon 'detection'
This commit is contained in:
parent
f5464cd070
commit
f147922ca8
@ -2,7 +2,7 @@
|
|||||||
Pytop is a Gtk + Python gui to have a custom desktop interface.
|
Pytop is a Gtk + Python gui to have a custom desktop interface.
|
||||||
|
|
||||||
# Notes
|
# Notes
|
||||||
Need python 3
|
```sudo apt-get install python3 steamcmd
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -42,6 +42,9 @@ class Grid:
|
|||||||
self.desktop.connect("item-activated", self.iconLeftClickEventManager)
|
self.desktop.connect("item-activated", self.iconLeftClickEventManager)
|
||||||
self.desktop.connect("button_press_event", self.iconRightClickEventManager, (self.desktop,))
|
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)
|
self.setIconViewDir(newPath)
|
||||||
|
|
||||||
def setIconViewDir(self, path):
|
def setIconViewDir(self, path):
|
||||||
@ -49,6 +52,9 @@ class Grid:
|
|||||||
|
|
||||||
self.currentPath = path
|
self.currentPath = path
|
||||||
dirPaths = ['.', '..']
|
dirPaths = ['.', '..']
|
||||||
|
vids = []
|
||||||
|
images = []
|
||||||
|
desktop = []
|
||||||
files = []
|
files = []
|
||||||
|
|
||||||
for f in listdir(path):
|
for f in listdir(path):
|
||||||
@ -57,13 +63,24 @@ class Grid:
|
|||||||
if f.startswith('.'):
|
if f.startswith('.'):
|
||||||
continue
|
continue
|
||||||
if isfile(file):
|
if isfile(file):
|
||||||
|
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)
|
files.append(f)
|
||||||
else:
|
else:
|
||||||
dirPaths.append(f)
|
dirPaths.append(f)
|
||||||
|
|
||||||
dirPaths.sort()
|
dirPaths.sort()
|
||||||
|
vids.sort()
|
||||||
|
images.sort()
|
||||||
|
desktop.sort()
|
||||||
files.sort()
|
files.sort()
|
||||||
files = dirPaths + files
|
|
||||||
|
files = dirPaths + vids + images + desktop + files
|
||||||
self.generateDirectoryGrid(path, files)
|
self.generateDirectoryGrid(path, files)
|
||||||
|
|
||||||
@threaded
|
@threaded
|
||||||
|
@ -11,7 +11,6 @@ from xdg.DesktopEntry import DesktopEntry
|
|||||||
|
|
||||||
# Python Imports
|
# Python Imports
|
||||||
import os, subprocess, hashlib, threading
|
import os, subprocess, hashlib, threading
|
||||||
import urllib.request as urllib
|
|
||||||
|
|
||||||
from os.path import isdir, isfile, join
|
from os.path import isdir, isfile, join
|
||||||
|
|
||||||
@ -33,9 +32,6 @@ class Icon:
|
|||||||
self.systemIconImageWxH = settings.returnSystemIconImageWH()
|
self.systemIconImageWxH = settings.returnSystemIconImageWH()
|
||||||
self.viIconWxH = settings.returnVIIconWH()
|
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):
|
def createIcon(self, dir, file):
|
||||||
fullPath = dir + "/" + file
|
fullPath = dir + "/" + file
|
||||||
@ -101,32 +97,27 @@ class Icon:
|
|||||||
|
|
||||||
hashImgpth = steamIconsDir + fileHash + ".jpg"
|
hashImgpth = steamIconsDir + fileHash + ".jpg"
|
||||||
if isfile(hashImgpth) == True:
|
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()
|
execStr = xdgObj.getExec()
|
||||||
parts = execStr.split("steam://rungameid/")
|
parts = execStr.split("steam://rungameid/")
|
||||||
id = parts[len(parts) - 1]
|
id = parts[len(parts) - 1]
|
||||||
|
|
||||||
url = "https://steamdb.info/app/" + id + "/"
|
# NOTE: Can try this logic instead...
|
||||||
request = urllib.Request(url, None, self.headers)
|
# if command exists use it instead of header image
|
||||||
response = urllib.urlopen(request)
|
# if "steamcmd app_info_print id":
|
||||||
page = response.read().decode("utf8")
|
# proc = subprocess.Popen(["steamcmd", "app_info_print", id])
|
||||||
response.close() # its always safe to close an open connection
|
# proc.wait()
|
||||||
imageHTML = ""
|
# else:
|
||||||
imageLink = ""
|
# use the bottom logic
|
||||||
|
|
||||||
for line in page.split("\n"):
|
imageLink = "https://steamcdn-a.akamaihd.net/steam/apps/" + id + "/header.jpg"
|
||||||
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])
|
proc = subprocess.Popen(["wget", "-O", hashImgpth, imageLink])
|
||||||
proc.wait()
|
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):
|
elif os.path.exists(icon):
|
||||||
return self.createIconImageBuffer(icon, self.systemIconImageWxH)
|
return self.createIconImageBuffer(icon, self.systemIconImageWxH)
|
||||||
else:
|
else:
|
||||||
|
@ -42,6 +42,9 @@ class Grid:
|
|||||||
self.desktop.connect("item-activated", self.iconLeftClickEventManager)
|
self.desktop.connect("item-activated", self.iconLeftClickEventManager)
|
||||||
self.desktop.connect("button_press_event", self.iconRightClickEventManager, (self.desktop,))
|
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)
|
self.setIconViewDir(newPath)
|
||||||
|
|
||||||
def setIconViewDir(self, path):
|
def setIconViewDir(self, path):
|
||||||
@ -49,6 +52,9 @@ class Grid:
|
|||||||
|
|
||||||
self.currentPath = path
|
self.currentPath = path
|
||||||
dirPaths = ['.', '..']
|
dirPaths = ['.', '..']
|
||||||
|
vids = []
|
||||||
|
images = []
|
||||||
|
desktop = []
|
||||||
files = []
|
files = []
|
||||||
|
|
||||||
for f in listdir(path):
|
for f in listdir(path):
|
||||||
@ -57,13 +63,24 @@ class Grid:
|
|||||||
if f.startswith('.'):
|
if f.startswith('.'):
|
||||||
continue
|
continue
|
||||||
if isfile(file):
|
if isfile(file):
|
||||||
|
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)
|
files.append(f)
|
||||||
else:
|
else:
|
||||||
dirPaths.append(f)
|
dirPaths.append(f)
|
||||||
|
|
||||||
dirPaths.sort()
|
dirPaths.sort()
|
||||||
|
vids.sort()
|
||||||
|
images.sort()
|
||||||
|
desktop.sort()
|
||||||
files.sort()
|
files.sort()
|
||||||
files = dirPaths + files
|
|
||||||
|
files = dirPaths + vids + images + desktop + files
|
||||||
self.generateDirectoryGrid(path, files)
|
self.generateDirectoryGrid(path, files)
|
||||||
|
|
||||||
@threaded
|
@threaded
|
||||||
|
@ -11,7 +11,6 @@ from xdg.DesktopEntry import DesktopEntry
|
|||||||
|
|
||||||
# Python Imports
|
# Python Imports
|
||||||
import os, subprocess, hashlib, threading
|
import os, subprocess, hashlib, threading
|
||||||
import urllib.request as urllib
|
|
||||||
|
|
||||||
from os.path import isdir, isfile, join
|
from os.path import isdir, isfile, join
|
||||||
|
|
||||||
@ -33,9 +32,6 @@ class Icon:
|
|||||||
self.systemIconImageWxH = settings.returnSystemIconImageWH()
|
self.systemIconImageWxH = settings.returnSystemIconImageWH()
|
||||||
self.viIconWxH = settings.returnVIIconWH()
|
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):
|
def createIcon(self, dir, file):
|
||||||
fullPath = dir + "/" + file
|
fullPath = dir + "/" + file
|
||||||
@ -101,32 +97,27 @@ class Icon:
|
|||||||
|
|
||||||
hashImgpth = steamIconsDir + fileHash + ".jpg"
|
hashImgpth = steamIconsDir + fileHash + ".jpg"
|
||||||
if isfile(hashImgpth) == True:
|
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()
|
execStr = xdgObj.getExec()
|
||||||
parts = execStr.split("steam://rungameid/")
|
parts = execStr.split("steam://rungameid/")
|
||||||
id = parts[len(parts) - 1]
|
id = parts[len(parts) - 1]
|
||||||
|
|
||||||
url = "https://steamdb.info/app/" + id + "/"
|
# NOTE: Can try this logic instead...
|
||||||
request = urllib.Request(url, None, self.headers)
|
# if command exists use it instead of header image
|
||||||
response = urllib.urlopen(request)
|
# if "steamcmd app_info_print id":
|
||||||
page = response.read().decode("utf8")
|
# proc = subprocess.Popen(["steamcmd", "app_info_print", id])
|
||||||
response.close() # its always safe to close an open connection
|
# proc.wait()
|
||||||
imageHTML = ""
|
# else:
|
||||||
imageLink = ""
|
# use the bottom logic
|
||||||
|
|
||||||
for line in page.split("\n"):
|
imageLink = "https://steamcdn-a.akamaihd.net/steam/apps/" + id + "/header.jpg"
|
||||||
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])
|
proc = subprocess.Popen(["wget", "-O", hashImgpth, imageLink])
|
||||||
proc.wait()
|
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):
|
elif os.path.exists(icon):
|
||||||
return self.createIconImageBuffer(icon, self.systemIconImageWxH)
|
return self.createIconImageBuffer(icon, self.systemIconImageWxH)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user