1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
| InfosVisionnage::InfosVisionnage(const Saison& saison, fs::path const& m_cheminFichier) : m_saison{ saison }
{
// ([[:digit:]]+)x([[:digit:]]{1,3})\\.(((([[:digit:]]{4})-([[:digit:]]{2})-([[:digit:]]{2})|([[:digit:]]{2})-([[:digit:]]{2})|([[:digit:]]{2})))(_?))+)(\\s(.+))?
const std::wstring numero_saison_format = L"([[:digit:]]{1,2})"; // saison
const std::wstring sep_numero_saison = L"x"; // x
const std::wstring numero_episode_format = L"([[:digit:]]{1,3})"; // episode
const std::wstring sep_episode_saison = L"\\."; //.
const std::wstring date_year_month_day_format = L"([[:digit:]]{4})-([[:digit:]]{2})-([[:digit:]]{2})";
const std::wstring date_month_day_format = L"([[:digit:]]{2})-([[:digit:]]{2})";
const std::wstring date_day_format = L"([[:digit:]]{2})";
const std::wstring stream_format = L"(\\s(.+))?";
const std::wstring dates_format = L"((" + date_year_month_day_format + L"|" + date_month_day_format + L"|" + date_day_format + L")(_?))";
const int dates_full_match_index = 0;
const int dates_date_year_month_day_year_index = dates_full_match_index + 3;
const int dates_date_year_month_day_month_index = dates_date_year_month_day_year_index + 1;
const int dates_date_year_month_day_day_index = dates_date_year_month_day_month_index + 1;
const int dates_date_month_day_month_index = dates_date_year_month_day_day_index + 1;
const int dates_date_month_day_day_index = dates_date_month_day_month_index + 1;
const int dates_date_day_day_index = dates_date_month_day_day_index + 1;
const int dates_someFlag_index = dates_date_day_day_index + 2;
const std::wregex filename_format_rg{ numero_saison_format + sep_numero_saison + numero_episode_format + sep_episode_saison + L"(" + dates_format + L"+)" + stream_format };
const int filename_full_match_index = 0;
const int filename_numero_saison_index = filename_full_match_index + 1;
const int filename_numero_episode_index = filename_numero_saison_index + 1;
const int filename_dates_index = filename_numero_episode_index + 1;
const int filename_date_year_month_day_year_index = filename_dates_index + 2;
const int filename_date_year_month_day_month_index = filename_date_year_month_day_year_index + 1;
const int filename_date_year_month_day_day_index = filename_date_year_month_day_month_index + 1;
const int filename_date_month_day_month_index = filename_date_year_month_day_day_index + 1;
const int filename_date_month_day_day_index = filename_date_month_day_month_index + 1;
const int filename_date_day_day_index = filename_date_month_day_day_index + 1;
const int filename_someFlag_index = filename_date_day_day_index + 2;
const int filename_stream_index = filename_someFlag_index + 2;
auto nomFichier = m_cheminFichier.filename().wstring();
assert(nomFichier.length() > 0 && L"Nom de fichier Épisode vide");
auto stem = m_cheminFichier.stem().wstring();
assert((stem.length() > 9) && L"Nom de fichier Épisode trop court pour avoir au moins une date");
assert(std::isdigit(stem[0]) && L"Nom de fichier Épisode ne commençant pas par un nombre");
assert((m_NumeroSaison <= 1000) && L"x <= 1000 !!!");// saison == m_NumeroSaison
assert((stem.find(L"x", 0) != std::wstring::npos) && L"Saison::afficher_Episode() : x !!!");
/* std::wsmatch match;
auto str = stem;
//Exemple assez complexe de nom de fichier
//str = L"1x01.2024-02-01_2024-02-02_02-03_0405 Netflix";
std::regex_match(str, match, filename_format_rg);
if (match[filename_numero_saison_index].matched)
m_NumeroSaison = std::stoi(match[filename_numero_saison_index]);
std::wsmatch dates_match;
auto dates_str = match[filename_dates_index].str();
while (std::regex_search(dates_str, dates_match, std::wregex{ dates_format }))
{
if (dates_match[dates_date_year_month_day_year_index].matched)
{
auto year = std::stoi(dates_match[dates_date_year_month_day_year_index]);
auto month = std::stoi(dates_match[dates_date_year_month_day_month_index]);
auto day = std::stoi(dates_match[dates_date_year_month_day_day_index]);
assert(checkyear(year));
assert(checkmonth(month));
assert(checkday(month, day, year));
DateRecord dr{ {0,0,0,day,month - 1,year - 1900} };
m_DatesVisionnage.emplace_back(dr);
}
else if (dates_match[dates_date_month_day_month_index].matched)
{
assert(m_DatesVisionnage.size() > 0 && L"Utilisation d'un format mois-jour sans avoir d'année déduite.");
auto month = std::stoi(dates_match[dates_date_month_day_month_index]);
auto day = std::stoi(dates_match[dates_date_month_day_day_index]);
auto lastDateRecord = m_DatesVisionnage.back();
auto last_year = lastDateRecord.date.tm_year + 1900;
assert(checkmonth(month));
assert(checkday(month, day, last_year));
DateRecord dr{ {0,0,0,day,month - 1,last_year - 1900} };
m_DatesVisionnage.emplace_back(dr);
}
else if (dates_match[dates_date_day_day_index].matched)
{
assert(m_DatesVisionnage.size() > 0 && L"Utilisation d'un format jour sans avoir de mois et d'années déduits.");
auto day = std::stoi(dates_match[dates_date_day_day_index]);
auto lastDateRecord = m_DatesVisionnage.back();
auto last_year = lastDateRecord.date.tm_year + 1900;
auto last_month = lastDateRecord.date.tm_mon + 1;
assert(checkday(last_month, day, last_year));
DateRecord dr{ {0,0,0,day,last_month - 1,last_year - 1900} };
m_DatesVisionnage.emplace_back(dr);
}
else
{
assert(true && L"format de date d'épisode inconnu.");
}
if (dates_match[dates_someFlag_index].matched)
{
m_DatesVisionnage.back().someFlag = true;
}
dates_str = dates_match.suffix().str();
}
m_NumeroEpisodeDansSaison = std::stoi(match[filename_numero_episode_index]);
*/
InfosVisionnage_dates(filename_format_rg, filename_numero_saison_index, filename_dates_index, dates_format, dates_date_year_month_day_year_index, stem);
std::vector<std::wstring> file_content = lire_fichierTxt(m_cheminFichier.wstring(), { L"\n" }, false);
if (file_content.size() > 0)
{
InfosVisionnage_file_content(file_content);
}
}
void InfosVisionnage::InfosVisionnage_dates(const std::wregex filename_format_rg, const int filename_numero_saison_index, const int filename_dates_index, const std::wstring dates_format, const int dates_date_year_month_day_year_index, std::wstring stem)
{
std::wsmatch match;
auto str = stem;
//Exemple assez complexe de nom de fichier
//str = L"1x01.2024-02-01_2024-02-02_02-03_0405 Netflix";
std::regex_match(str, match, filename_format_rg);
if (match[filename_numero_saison_index].matched)
m_NumeroSaison = std::stoi(match[filename_numero_saison_index]);
std::wsmatch dates_match;
auto dates_str = match[filename_dates_index].str();
while (std::regex_search(dates_str, dates_match, std::wregex{ dates_format }))
{
if (dates_match[dates_date_year_month_day_year_index].matched)
{
auto year = std::stoi(dates_match[dates_date_year_month_day_year_index]);
auto month = std::stoi(dates_match[dates_date_year_month_day_month_index]);
auto day = std::stoi(dates_match[dates_date_year_month_day_day_index]);
assert(checkyear(year));
assert(checkmonth(month));
assert(checkday(month, day, year));
DateRecord dr{ {0,0,0,day,month - 1,year - 1900} };
m_DatesVisionnage.emplace_back(dr);
}
else if (dates_match[dates_date_month_day_month_index].matched)
{
assert(m_DatesVisionnage.size() > 0 && L"Utilisation d'un format mois-jour sans avoir d'année déduite.");
auto month = std::stoi(dates_match[dates_date_month_day_month_index]);
auto day = std::stoi(dates_match[dates_date_month_day_day_index]);
auto lastDateRecord = m_DatesVisionnage.back();
auto last_year = lastDateRecord.date.tm_year + 1900;
assert(checkmonth(month));
assert(checkday(month, day, last_year));
DateRecord dr{ {0,0,0,day,month - 1,last_year - 1900} };
m_DatesVisionnage.emplace_back(dr);
}
else if (dates_match[dates_date_day_day_index].matched)
{
assert(m_DatesVisionnage.size() > 0 && L"Utilisation d'un format jour sans avoir de mois et d'années déduits.");
auto day = std::stoi(dates_match[dates_date_day_day_index]);
auto lastDateRecord = m_DatesVisionnage.back();
auto last_year = lastDateRecord.date.tm_year + 1900;
auto last_month = lastDateRecord.date.tm_mon + 1;
assert(checkday(last_month, day, last_year));
DateRecord dr{ {0,0,0,day,last_month - 1,last_year - 1900} };
m_DatesVisionnage.emplace_back(dr);
}
else
{
assert(true && L"format de date d'épisode inconnu.");
}
if (dates_match[dates_someFlag_index].matched)
{
m_DatesVisionnage.back().someFlag = true;
}
dates_str = dates_match.suffix().str();
}
if (match[filename_stream_index].matched)
{
m_streaming = match[filename_stream_index];
}
m_NumeroEpisodeDansSaison = std::stoi(match[filename_numero_episode_index]);
}
void InfosVisionnage::InfosVisionnage_file_content(std::vector<std::wstring>file_content)
{
const std::wregex numeroPlusTitres_rg{ L"(?:(\\d)+\\.)?(.*)" };
std::wsmatch titles_match;
std::regex_match(file_content[0], titles_match, numeroPlusTitres_rg);
if (titles_match[1].matched)
{
m_NumeroEpisodeDansSerie = std::stoi(titles_match[1]);
}
std::wstring titres = titles_match[2];
trim(titres);
m_titres = extraire_Titres_Depuis_UneLigne(titres);
if (file_content.size() > 1)
initialiser_Duree(file_content[1]);
if (file_content.size() > 2)
{
file_content.erase(file_content.begin(), file_content.begin() + 2);
m_resume = file_content;
}
} |
Partager