Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fixed_file_path = fixed_file_name + config.DEFAULT_VIDEO_EXTENSION
# Create cloud path based on guessit results.
cloud_dir = None
cloud_file = None
guess_results = guessit(os.path.basename(fixed_file_path))
video_type = guess_results.get('type')
title = guess_results.get('title')
# Make sure every word starts with a capital letter.
if title:
title = title.title()
if video_type == 'episode' and title:
season = guess_results.get('season')
if season:
episode = guess_results.get('episode')
if episode:
cloud_dir = '{}/{}/Season {:02d}'.format(config.AMAZON_TV_PATH, title, season)
cloud_file = '{} - S{:02d}E{:02d}'.format(title, season, episode)
elif video_type == 'movie' and title:
year = guess_results.get('year')
if year:
cloud_dir = '{}/{} ({})'.format(config.AMAZON_MOVIE_PATH, title, year)
cloud_file = '{} ({})'.format(title, year)
if cloud_dir and cloud_file:
if language_extension:
cloud_file += language_extension
cloud_file += file_extension
logger.info('Cloud path: {}'.format(posixpath.join(cloud_dir, cloud_file)))
# Rename local file before upload.
base_dir = os.path.dirname(file_path)
new_path = os.path.join(base_dir, cloud_file)
os.rename(file_path, new_path)
# Sync first.