<commit_before>package dynamo.backlog.tasks.tvshows;

import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import dynamo.backlog.BackLogProcessor;
import dynamo.backlog.tasks.core.VideoFileFilter;
import dynamo.core.ReleaseGroup;
import dynamo.core.model.DownloadableDAO;
import dynamo.core.model.TaskExecutor;
import dynamo.jdbi.TVShowDAO;
import dynamo.model.DownloadableStatus;
import dynamo.model.backlog.find.FindEpisodeTask;
import dynamo.model.backlog.subtitles.FindSubtitleEpisodeTask;
import dynamo.model.tvshows.TVShowManager;
import dynamo.parsers.TVShowEpisodeInfo;
import dynamo.parsers.VideoNameParser;
import dynamo.video.VideoManager;
import model.ManagedEpisode;
import model.ManagedSeries;
import model.backlog.ScanTVShowTask;

public class ScanTVShowExecutor extends TaskExecutor<ScanTVShowTask> {
	
	private TVShowDAO tvShowDAO;
	private DownloadableDAO downloadableDAO;

	public ScanTVShowExecutor(ScanTVShowTask item, TVShowDAO tvShowDAO, DownloadableDAO downloadableDAO) {
		super(item);
		this.tvShowDAO = tvShowDAO;
		this.downloadableDAO = downloadableDAO;
	}

	private void parseFolder( ManagedSeries series, List<ManagedEpisode> existingEpisodes, Path folder ) throws IOException, InterruptedException {

		if (! Files.isReadable( folder )) {
			return;
		}

		DirectoryStream<Path> ds = Files.newDirectoryStream( folder, VideoFileFilter.getInstance() );

		for (Path p : ds) {
			if (Files.isDirectory(p)) {
				parseFolder( series, existingEpisodes, p );
			} else {

				Integer seasonNumber = null;
				List<Integer> episodes = new ArrayList<Integer>();
				
				TVShowEpisodeInfo episodeInfo = VideoNameParser.getTVShowEpisodeInfo(series, p);<commit_msg>Remove subtitles if none specified<commit_after>package dynamo.backlog.tasks.tvshows;

import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import dynamo.backlog.BackLogProcessor;
import dynamo.backlog.tasks.core.SubtitlesFileFilter;
import dynamo.backlog.tasks.core.VideoFileFilter;
import dynamo.backlog.tasks.files.DeleteTask;
import dynamo.core.ReleaseGroup;
import dynamo.core.model.DownloadableDAO;
import dynamo.core.model.TaskExecutor;
import dynamo.jdbi.TVShowDAO;
import dynamo.model.DownloadableStatus;
import dynamo.model.backlog.find.FindEpisodeTask;
import dynamo.model.backlog.subtitles.FindSubtitleEpisodeTask;
import dynamo.model.tvshows.TVShowManager;
import dynamo.parsers.TVShowEpisodeInfo;
import dynamo.parsers.VideoNameParser;
import dynamo.video.VideoManager;
import model.ManagedEpisode;
import model.ManagedSeries;
import model.backlog.ScanTVShowTask;

public class ScanTVShowExecutor extends TaskExecutor<ScanTVShowTask> {
	
	private TVShowDAO tvShowDAO;
	private DownloadableDAO downloadableDAO;

	public ScanTVShowExecutor(ScanTVShowTask item, TVShowDAO tvShowDAO, DownloadableDAO downloadableDAO) {
		super(item);
		this.tvShowDAO = tvShowDAO;
		this.downloadableDAO = downloadableDAO;
	}

	private void parseFolder( ManagedSeries series, List<ManagedEpisode> existingEpisodes, Path folder ) throws IOException, InterruptedException {

		if (! Files.isReadable( folder )) {
			return;
		}

		if (series.getSubtitleLanguage() == null) {
			// remove subtitles
			for ( Path subtitle : Files.newDirectoryStream( folder, SubtitlesFileFilter.getInstance() )) {
				if (Files.isRegularFile(subtitle)) {
					queue( new DeleteTask(subtitle, false));
				}
			}
		}

		DirectoryStream<Path> ds = Files.newDirectoryStream( folder, VideoFileFilter.getInstance() );
		for (Path p : ds) {
			if (Files.isDirectory(p)) {
				parseFolder( series, existingEpisodes, p );
			} else {

				Integer seasonNumber = null;
				List<Integer> episodes = new ArrayList<Integer>();
				
				TVShowEpisodeInfo episodeInfo = VideoNameParser.getTVShowEpisodeInfo(series, p);
{'fraction_non_alphanumeric': 0.09340659340659341, 'fraction_numerical': 0.0, 'mean_word_length': 5.776649746192893, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2895819', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1241, 'n_words': 248}