mirror of
https://github.com/cooperhammond/irs.git
synced 2025-07-03 15:18:14 +00:00
Decorator for staticmethods in utils.py
This commit is contained in:
parent
09a839aeab
commit
79a9733fe7
23
irs/utils.py
23
irs/utils.py
|
@ -4,6 +4,9 @@
|
||||||
# Imports
|
# Imports
|
||||||
# =======
|
# =======
|
||||||
|
|
||||||
|
# Static Method Hook
|
||||||
|
import inspect
|
||||||
|
|
||||||
# And Now For Something Completely Different
|
# And Now For Something Completely Different
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -15,10 +18,21 @@ import pkg_resources
|
||||||
from .config import CONFIG
|
from .config import CONFIG
|
||||||
|
|
||||||
|
|
||||||
|
# ==================
|
||||||
|
# Static Method Hook
|
||||||
|
# ==================
|
||||||
|
|
||||||
|
def staticmethods(cls):
|
||||||
|
for name, method in inspect.getmembers(cls, inspect.ismethod):
|
||||||
|
setattr(cls, name, staticmethod(method.__func__))
|
||||||
|
return cls
|
||||||
|
|
||||||
|
|
||||||
# =========================
|
# =========================
|
||||||
# Youtube-DL Logs and Hooks
|
# Youtube-DL Logs and Hooks
|
||||||
# =========================
|
# =========================
|
||||||
|
|
||||||
|
@staticmethods
|
||||||
class YdlUtils:
|
class YdlUtils:
|
||||||
def clear_line():
|
def clear_line():
|
||||||
sys.stdout.write("\x1b[2K\r")
|
sys.stdout.write("\x1b[2K\r")
|
||||||
|
@ -33,7 +47,6 @@ class YdlUtils:
|
||||||
def error(self, msg):
|
def error(self, msg):
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def my_hook(d):
|
def my_hook(d):
|
||||||
if d['status'] == 'finished':
|
if d['status'] == 'finished':
|
||||||
print("Converting to mp3 ...")
|
print("Converting to mp3 ...")
|
||||||
|
@ -43,6 +56,7 @@ class YdlUtils:
|
||||||
# Object Manipulation and Checking
|
# Object Manipulation and Checking
|
||||||
# ================================
|
# ================================
|
||||||
|
|
||||||
|
@staticmethods
|
||||||
class ObjManip: # Object Manipulation
|
class ObjManip: # Object Manipulation
|
||||||
def limit_song_name(song):
|
def limit_song_name(song):
|
||||||
bad_phrases = "remaster remastered master".split(" ")
|
bad_phrases = "remaster remastered master".split(" ")
|
||||||
|
@ -53,7 +67,6 @@ class ObjManip: # Object Manipulation
|
||||||
return song.split(" - ")[0]
|
return song.split(" - ")[0]
|
||||||
return song
|
return song
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def check_garbage_phrases(phrases, string, title):
|
def check_garbage_phrases(phrases, string, title):
|
||||||
for phrase in phrases:
|
for phrase in phrases:
|
||||||
if phrase in ObjManip.blank(string):
|
if phrase in ObjManip.blank(string):
|
||||||
|
@ -61,7 +74,6 @@ class ObjManip: # Object Manipulation
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def blank(string, downcase=True):
|
def blank(string, downcase=True):
|
||||||
import re
|
import re
|
||||||
regex = re.compile('[^a-zA-Z0-9\ ]')
|
regex = re.compile('[^a-zA-Z0-9\ ]')
|
||||||
|
@ -70,7 +82,6 @@ class ObjManip: # Object Manipulation
|
||||||
string = string.lower()
|
string = string.lower()
|
||||||
return ' '.join(string.split())
|
return ' '.join(string.split())
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def blank_include(this, includes_this):
|
def blank_include(this, includes_this):
|
||||||
this = ObjManip.blank(this)
|
this = ObjManip.blank(this)
|
||||||
includes_this = ObjManip.blank(includes_this)
|
includes_this = ObjManip.blank(includes_this)
|
||||||
|
@ -112,6 +123,7 @@ class ObjManip: # Object Manipulation
|
||||||
# Download Log Reading/Updating/Formatting
|
# Download Log Reading/Updating/Formatting
|
||||||
# ========================================
|
# ========================================
|
||||||
|
|
||||||
|
@staticmethods
|
||||||
class DLog:
|
class DLog:
|
||||||
def format_download_log_line(t, download_status="not downloaded"):
|
def format_download_log_line(t, download_status="not downloaded"):
|
||||||
return (" @@ ".join([t["name"], t["artist"], t["album"]["id"],
|
return (" @@ ".join([t["name"], t["artist"], t["album"]["id"],
|
||||||
|
@ -357,6 +369,7 @@ def check_sources(ripper, key, default=None, environment=False, where=None):
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethods
|
||||||
class Config:
|
class Config:
|
||||||
|
|
||||||
def parse_spotify_creds(ripper):
|
def parse_spotify_creds(ripper):
|
||||||
|
@ -366,7 +379,6 @@ class Config:
|
||||||
environment=True)
|
environment=True)
|
||||||
return CLIENT_ID, CLIENT_SECRET
|
return CLIENT_ID, CLIENT_SECRET
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def parse_search_terms(ripper):
|
def parse_search_terms(ripper):
|
||||||
search_terms = check_sources(ripper, "additional_search_terms",
|
search_terms = check_sources(ripper, "additional_search_terms",
|
||||||
"lyrics")
|
"lyrics")
|
||||||
|
@ -376,7 +388,6 @@ class Config:
|
||||||
artist = check_sources(ripper, "artist")
|
artist = check_sources(ripper, "artist")
|
||||||
return artist
|
return artist
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def parse_directory(ripper):
|
def parse_directory(ripper):
|
||||||
directory = check_sources(ripper, "custom_directory",
|
directory = check_sources(ripper, "custom_directory",
|
||||||
where="post_processors")
|
where="post_processors")
|
||||||
|
|
Loading…
Reference in a new issue