def __init__(self, config): # Device ID device_id_file = open(config.get('Device', 'device_id_file'), 'r') self.DEVICE_ID = device_id_file.read().strip() device_id_file.close() # Playlist URL server_url = config.get('Server', 'server_url') playlist_server_path = config.get('Server', 'playlist_server_path') self.PLAYLIST_URL = urljoin(server_url, playlist_server_path) self.LOG.debug('PLAYLIST URL SET: %s', self.PLAYLIST_URL) # Playlist file playlist_file = config.get('Storage', 'playlist_file') playlist_folder = os.path.dirname(playlist_file) if not os.path.exists(playlist_folder): os.makedirs(playlist_folder) self.PLAYLIST_FILEPATH = playlist_file # Media folder self.MEDIA_FOLDER = config.get('Storage', 'media_folder') if not os.path.exists(self.MEDIA_FOLDER): os.makedirs(self.MEDIA_FOLDER) # Utility for parsing playlist JSON self.PLAYLIST_PARSER = PlaylistJsonParser(self.PLAYLIST_FILEPATH) playlist_bytes_timeout = int( config.get('Client', 'playlist_bytes_timeout')) if playlist_bytes_timeout == 0: playlist_bytes_timeout = None playlist_connection_timeout = int( config.get('Client', 'playlist_connection_timeout')) if playlist_connection_timeout == 0: playlist_connection_timeout = None self.PLAYLIST_TIMEOUTS = (playlist_bytes_timeout, playlist_connection_timeout) media_cleaner = MediaCleaner(config, self.PLAYLIST_PARSER) # Utility for downloading files self.downloader = ChunkedDownloader(server_url, self.DEVICE_ID, self.MEDIA_FOLDER, self.PLAYLIST_TIMEOUTS, media_cleaner) self.playlist_id = None self.playlist_update_time = None