import re from helpers.colors import bcolors # prep utf-8 4-byte filter try: highpoints = re.compile(u'[\U00010000-\U0010ffff]') except re.error: # UCS-2 build highpoints = re.compile(u'[\uD800-\uDBFF][\uDC00-\uDFFF]') def display_general_db(db_row): display_message = [str(k)+': '+bcolors.OKGREEN+str(v)+" "+bcolors.ENDC for k,v in db_row.items()] display_message = '\n'.join(display_message) return display_message+"\n" def display_ownership_db(db_row): ownership_array = [i.strip() for i in db_row['derived_ownership'].strip('{}').split(',')] ownership_array = sorted(ownership_array) ownership = ','.join(ownership_array) OA_link = 'https://oa.theorchard.com/cont_mgmt/edit_track.php?' \ 'searchList=track&upc={}&tuid={}'.format( db_row['upc'], db_row['derived_tuid']) YT_link = 'https://www.youtube.com/content_id?o=J8vAyKuNSYBIN_9RIdxggQ' \ '#asset/d/a={}&x=s&si=0&t=op'.format(db_row['asset_id']) display_message = "DB Row: {}\n " \ "asset_id: {}{}{}\n " \ "UPC: {}{}{}\n " \ "ISRC: {}{}{}\n " \ "TUID: {}{}{}\n " \ "Process Notes: {}{}{}\n " \ "OA link: {}{}{}\n " \ "Youtube link: {}{}{}\n\n " \ "Territories ({}{}{} out of 249): \n{}\n".format( db_row['id'], bcolors.HEADER, db_row['asset_id'], bcolors.ENDC, bcolors.WARNING, db_row['upc'], bcolors.ENDC, bcolors.OKGREEN, db_row['isrc'], bcolors.ENDC, bcolors.OKBLUE, db_row['derived_tuid'], bcolors.ENDC, bcolors.HEADER, db_row['reason'], bcolors.ENDC, bcolors.FAIL, OA_link, bcolors.ENDC, bcolors.FAIL, YT_link, bcolors.ENDC, bcolors.OKGREEN, len(ownership_array), bcolors.ENDC, ownership) return OA_link, display_message def display_general_file(file_row, line_num): display_message = "" display_message = [str(k) + ': ' + bcolors.OKGREEN + str(v)+" " + bcolors.ENDC for k, v in file_row.items()] display_message = '\n'.join(display_message) return "File line: "+str(line_num)+"\n" + display_message+"\n" def display_ownership_file(file_row, line_num): not_in_iso = ['AN', 'CS', 'FX', 'GZ', 'TP', 'ZZ'] display_message = "" file_row['Cleaned'] = file_row['Ownership'] for i in not_in_iso: file_row['Cleaned'] \ = file_row['Cleaned'] \ .replace(i, '') file_row['Cleaned'] \ = file_row['Cleaned'] \ .replace(',,', ',') \ .replace(' ,', ' ') \ .strip(',') display_message = "File line: {}\n" \ "asset_id: {}{}{}\n" \ "UPC: {}{}{}\n" \ "ISRC: {}{}{}\n" \ "Artist: {}{}{}\n" \ "Album: {}{}{}\n" \ "Song: {}{}{}\n" \ "Custom_ID: {}{}{}\n" \ "Ownership: {}\n" \ "Not in ISO-3166-1: AN,CS,FX,GZ,TP,ZZ\n" \ "ISO 3166 Ownership: {}{}{}\n".format( line_num, bcolors.HEADER, file_row['Asset ID'], bcolors.ENDC, bcolors.WARNING, file_row['UPC'], bcolors.ENDC, bcolors.OKGREEN, file_row['ISRC'], bcolors.ENDC, bcolors.WARNING, highpoints.sub(u'', file_row['Artist']), bcolors.ENDC, bcolors.WARNING, highpoints.sub(u'', file_row['Album']), bcolors.ENDC, bcolors.WARNING, highpoints.sub(u'', file_row['Song']), bcolors.ENDC, bcolors.OKBLUE, file_row['Custom ID'], bcolors.ENDC, file_row['Ownership'].strip().replace(";", ";\n"), bcolors.OKGREEN, file_row['Cleaned'].replace(";", ";\n"), bcolors.ENDC) return display_message