You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
1.9 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. #! /usr/bin/env python
  2. import os
  3. import sys
  4. import locale
  5. import subprocess
  6. def remove_empty_items(array):
  7. return [x for x in array if x != '']
  8. def remove_spaces(string):
  9. return string.replace(' ', '')
  10. def string_to_array(string, char=' '):
  11. return string.split(char)
  12. def preferredencoding():
  13. try:
  14. pref = locale.getpreferredencoding()
  15. u'TEST'.encode(pref)
  16. except:
  17. pref = 'UTF-8'
  18. return pref
  19. def get_encoding():
  20. if sys.version_info >= (3, 0):
  21. return None
  22. if sys.platform == 'win32':
  23. # Refer to http://stackoverflow.com/a/9951851/35070
  24. return preferredencoding()
  25. return None
  26. def encode_list(data_list, encoding):
  27. return [x.encode(encoding, 'ignore') for x in data_list]
  28. def video_is_dash(video):
  29. return "DASH" in video
  30. def have_dash_audio(audio):
  31. return audio != "NO SOUND"
  32. def remove_file(filename):
  33. os.remove(filename)
  34. def get_path_seperator():
  35. return '\\' if os.name == 'nt' else '/'
  36. def fix_path(path):
  37. if path != '' and path[-1:] != get_path_seperator():
  38. path += get_path_seperator()
  39. path_list = path.split(get_path_seperator())
  40. for i in range(len(path_list)):
  41. if path_list[i] == '~':
  42. path_list[i] = get_HOME()
  43. return get_path_seperator().join(path_list)
  44. def get_HOME():
  45. return os.path.expanduser("~")
  46. def add_PATH(path):
  47. os.environ["PATH"] += os.pathsep + path
  48. def abs_path(filename):
  49. path = os.path.abspath(filename).split(get_path_seperator())
  50. path.pop()
  51. return get_path_seperator().join(path)
  52. def file_exist(filename):
  53. return os.path.exists(filename)
  54. def get_os_type():
  55. return os.name
  56. def get_filesize(path):
  57. return os.path.getsize(path)
  58. def makedir(path):
  59. os.makedirs(path)
  60. def get_filename(path):
  61. return path.split(get_path_seperator())[-1]
  62. def open_dir(path):
  63. if os.name == 'nt':
  64. os.startfile(path)
  65. else:
  66. subprocess.call(('xdg-open', path))