Created
April 5, 2021 08:56
-
-
Save lambdan/052c4685f960281ef42264359ec85a91 to your computer and use it in GitHub Desktop.
Function to get resolution (eg 1080p) from string (python3)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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