X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Futils.py;h=73fe1ad0a3a27165d3dffc61927733beb9c5ed33;hb=7ee40b5d1cf0d4e79a049f3851262378c08d9e4c;hp=0b0d1eb9000ae4875ce64cb10f8a5271b6abacb2;hpb=79f82953039f832576f6d0202c7bbeaa2fd390c0;p=youtube-dl diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 0b0d1eb90..73fe1ad0a 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -818,6 +818,15 @@ def date_from_str(date_str): return today + delta return datetime.datetime.strptime(date_str, "%Y%m%d").date() +def hyphenate_date(date_str): + """ + Convert a date in 'YYYYMMDD' format to 'YYYY-MM-DD' format""" + match = re.match(r'^(\d\d\d\d)(\d\d)(\d\d)$', date_str) + if match is not None: + return '-'.join(match.groups()) + else: + return date_str + class DateRange(object): """Represents a time interval between two dates""" def __init__(self, start=None, end=None): @@ -1142,3 +1151,13 @@ def parse_duration(s): def prepend_extension(filename, ext): name, real_ext = os.path.splitext(filename) return u'{0}.{1}{2}'.format(name, ext, real_ext) + + +def check_executable(exe, args=[]): + """ Checks if the given binary is installed somewhere in PATH, and returns its name. + args can be a list of arguments for a short output (like -version) """ + try: + subprocess.Popen([exe] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() + except OSError: + return False + return exe