Skip to content

Instantly share code, notes, and snippets.

@lambdan
Created April 5, 2021 08:56
Show Gist options
  • Save lambdan/052c4685f960281ef42264359ec85a91 to your computer and use it in GitHub Desktop.
Save lambdan/052c4685f960281ef42264359ec85a91 to your computer and use it in GitHub Desktop.
Function to get resolution (eg 1080p) from string (python3)
def resolutionP(string): # returns 720p from test.720p-foo and so on
string = string.lower()
if "0p" in string:
index = string.index("0p")
result = ""
# go backwards
while string[index].isnumeric():
result = result + string[index]
index -= 1
result = result[::-1] + "p" # reverse and add p
return result
else:
return "(unknown resolution)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment