def run(path):
    logger.info("Start application")
    app_config = load_configuration(path)
    player_service = PlayerService(app_config.kodi)
    ftp_service = FtpService(app_config.ftp)
    ftp_files = ftp_service.read_file_items(app_config.directories.ftp_source)
    store_files = FileSystemHelper.read_file_items_from_dir(
        app_config.directories.store)
    delta_file_items = FileItemUtils.detect_new_files_on_ftp(
        store_files, ftp_files)
    if not delta_file_items.is_empty():
        print_delta(delta_file_items)
        current_playlist = PlaylistUtils.load_from_file(
            app_config.playlist.path)
        new_playlist = PlaylistUtils.create_actual_playlist(
            app_config, delta_file_items, store_files, current_playlist)
        downloaded_files = download_files_to_buffer_store(
            delta_file_items, app_config, ftp_service)
        player_service.pause()
        player_service.clean_current_playlist()
        archive_changed_files(delta_file_items, app_config)
        move_files_to_store(downloaded_files, app_config)
        updated_playlist_path = PlaylistUtils.save_to_file(new_playlist)
        logger.info("Playlist saved by path \"%s\"" % updated_playlist_path)
        player_service.add_playlist_by_name(
            os.path.basename(app_config.playlist.path))
        player_service.open_playlist()
    else:
        logger.info("Does not find anything")
    ftp_service.close()
 def test_bad_playlist(self):
     path = self.PATH_TEST_SOURCES + "/bad_playlist.m3u"
     try:
         PlaylistUtils.load_from_file(path)
         self.fail("It can not finished")
     except WrongTypePlaylistException:
         print("Test finished success")
 def test_save_playlist(self):
     path_new_playlist = self.PATH_TEST_SOURCES + "/new_playlist.m3u"
     self.remove_file(path_new_playlist)
     new_playlist = Playlist(path_new_playlist, list())
     new_playlist_item_file = "/data/video/v1.mp3"
     new_playlist.add(new_playlist_item_file)
     path_saved_playlist = PlaylistUtils.save_to_file(new_playlist)
     saved_playlist = PlaylistUtils.load_from_file(path_saved_playlist)
     self.assertEqual(os.path.abspath(path_new_playlist), saved_playlist.path)
     self.assertEqual(1, len(saved_playlist.items))
     self.assertEqual(new_playlist_item_file, saved_playlist.items[0].path)
     self.remove_file(path_new_playlist)
 def test_empty_playlist(self):
     path = self.PATH_TEST_SOURCES + "/empty_playlist.m3u"
     try:
         playlist = PlaylistUtils.load_from_file(path)
         self.assertEqual(0, len(playlist.items))
     except WrongTypePlaylistException:
         print("Test finished success")
 def test_full_playlist(self):
     path = self.PATH_TEST_SOURCES + "/full_playlist.m3u"
     playlist = PlaylistUtils.load_from_file(path)
     self.assertEqual(3, len(playlist.items))
 def test_empty_file(self):
     path = self.PATH_TEST_SOURCES + "/empty_file.m3u"
     playlist = PlaylistUtils.load_from_file(path)
     self.assertEqual(0, len(playlist.items))