'''
Helper functions for parsing paths and URLs.

@author: Michael A. Bayer
'''
import os
import hashlib
from datetime import datetime

#Python 2 to 3 fix.
try:
    from urlparse import urlparse
except ImportError:
    from urllib.parse import urlparse


def parseTime(data):
    """Parses the time from a URL or image name.
    
    Args:
        data (str): Image URL or name.
    Returns:
        datetime: The parsed time as a datetime object.
    """
    time_string = os.path.splitext(os.path.split(data)[-1])[0].split('_')[-1]
    time_stamp = datetime.strptime(time_string, '%Y%m%d%H%M%S%f')
    return time_stamp

def parseCamera(data):
    """Parses the camera name from a URL or image name.
    
    Args:
        data (str): Image URL or name.
    Returns:
        str: Camera name.
    """
    split1 = os.path.splitext(os.path.split(data)[-1])[0].split('_')[0]
    md5_str = hashlib.md5(split1[split1.index('-')+1:].encode('utf-8')).hexdigest()
    
    if split1[0:4] == md5_str[0:4]:
        return split1[5:]
    else:
        return split1
    
def parseImageName(url):
    """Parses the image name from a URL.
    
    Args:
        url (str): Image URL.
    Returns:
        str: Image name.
    """ 
    return os.path.split(url)[-1]

def parseUrl(url):
    """Parses a URL into its components.
    
    Args:
        url (str): Image URL.
    Returns:
        obj: Parsed URL.
    """
    return urlparse(url)


if __name__=='__main__':
    x = r'https://helios-u-exelis.s3.amazonaws.com/collections/9d0bf4fa-affb-4d45-81e7-8c9b11ea9119/TL-15939_20150409185836059.jpg'
    print(parseTime(x))
@@ -806,16 +806,20 @@
   split1
+_rev
  = os.pa
@@ -861,21 +861,69 @@
 )%5B0%5D
-.split('_')%5B0
+%5B::-1%5D%0A    split2 = split1_rev%5Bsplit1_rev.index('_')+1:%5D%5B::-1
 %5D%0A  
@@ -955,16 +955,16 @@
 plit
-1
+2
 %5Bsplit
-1
+2
 .ind
@@ -1021,17 +1021,17 @@
 if split
-1
+2
 %5B0:4%5D ==
@@ -1065,17 +1065,17 @@
 rn split
-1
+2
 %5B5:%5D%0A   
@@ -1101,17 +1101,17 @@
 rn split
-1
+2
 %0A    %0Ade
@@ -1480,187 +1480,4 @@
 url)
-%0A%0A%0Aif __name__=='__main__':%0A    x = r'https://helios-u-exelis.s3.amazonaws.com/collections/9d0bf4fa-affb-4d45-81e7-8c9b11ea9119/TL-15939_20150409185836059.jpg'%0A    print(parseTime(x))

Fix parseCamera for cam names with multiple underscores.