<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p><br>
</p>
<div class="moz-forward-container"><br>
<br>
-------- Forwarded Message --------
<table cellpadding="0" cellspacing="0" border="0"
class="moz-email-headers-table">
<tbody>
<tr>
<th valign="BASELINE" align="RIGHT" nowrap="nowrap">Subject:
</th>
<td>Re: [kwlug-disc] Regular Expression to Match Movie
Titles and Year and Ignore the rest.</td>
</tr>
<tr>
<th valign="BASELINE" align="RIGHT" nowrap="nowrap">Date: </th>
<td>Tue, 31 Dec 2024 17:56:48 -0500</td>
</tr>
<tr>
<th valign="BASELINE" align="RIGHT" nowrap="nowrap">From: </th>
<td>John Driezen <a class="moz-txt-link-rfc2396E" href="mailto:jdriezen@sympatico.ca"><jdriezen@sympatico.ca></a></td>
</tr>
<tr>
<th valign="BASELINE" align="RIGHT" nowrap="nowrap">To: </th>
<td>Jason Eckert <a class="moz-txt-link-rfc2396E" href="mailto:jason.eckert@gmail.com"><jason.eckert@gmail.com></a></td>
</tr>
</tbody>
</table>
<br>
<br>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<p>Following the helpful suggestions given, I am attempting to
write a python program to automatically rename the movie files
for me. However, I have gotten stuck. Here is the code.</p>
<p>import os<br>
import re<br>
with os.scandir() as i:<br>
for entry in i:<br>
if entry.is_file():<br>
filename = entry.name<br>
basename, ext = filename.rsplit('.', 1)<br>
print(basename,ext)<br>
basenameregex =
re.compile('^([^.]+(?:\.[^.]+)*)\.(\d{4})\.(\d+p)')<br>
title = re.split(basenameregex, basename)<br>
print(title)<br>
movietitle = title[1].replace('.', ' ') # replace
periods with spaces<br>
#movietitle = re.split('^([^.]+(?:\.[^.]+)*)',title)<br>
yearregex = re.compile('\.(\d{4})')<br>
year = re.search(yearregex, title)<br>
resolutionregex = re.compile('\.\(d+p)')<br>
resolution = re.search(resolutionregex, title)<br>
print (movietitle, year, resolution)<br>
</p>
<p>This program gives the following error messages when run.</p>
<p>/home/john/bin/renamemoviefiles.py:9: SyntaxWarning: invalid
escape sequence '\.'<br>
basenameregex =
re.compile('^([^.]+(?:\.[^.]+)*)\.(\d{4})\.(\d{3}p)')<br>
/home/john/bin/renamemoviefiles.py:14: SyntaxWarning: invalid
escape sequence '\.'<br>
yearregex = re.compile('\.(\d{4})')<br>
/home/john/bin/renamemoviefiles.py:16: SyntaxWarning: invalid
escape sequence '\.'<br>
resolutionregex = re.compile('\.\(d+p)')<br>
</p>
<p>I can't seem to find my error. Suggestions and improvements
welcome.<br>
</p>
<div class="moz-cite-prefix">On 2024-12-31 2:40 p.m., Jason Eckert
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAG+C2Af3SzjMvGXKjCwu5qxk+USff8b44MEkR64nXz-fL5GsuA@mail.gmail.com">
<meta http-equiv="content-type"
content="text/html; charset=UTF-8">
<div dir="ltr">You could also use:<br>
<br>
^([A-Za-z]+(?:\.[A-Za-z]+)*)\.(\d{4})\.(\d+p)\..*\.(mp4|mkv|avi)$<br>
<br>
Explanation:<br>
^: Anchors the regex to the start of the string.<br>
([A-Za-z]+(?:\.[A-Za-z]+)*): This part matches the title. It
captures words separated by dots (e.g., Zero.Dark.Thirty will
be captured as Zero Dark Thirty).<br>
([A-Za-z]+): Matches the first word.<br>
(?:\.[A-Za-z]+)*: Matches any additional words separated by
dots.<br>
\.(\d{4}): Matches the year (a 4-digit number).<br>
\.(\d+p): Matches the resolution (e.g., 720p, 1080p).<br>
\..*: Matches any additional characters between the resolution
and the file extension (e.g., BrRip.x264.BOKUTOX.YIFY).<br>
\.(mp4|mkv|avi): Matches the file extension (mp4, mkv, avi,
etc.).</div>
<br>
<div class="gmail_quote gmail_quote_container">
<div dir="ltr" class="gmail_attr">On Tue, 31 Dec 2024 at
11:29, John Driezen <<a
href="mailto:jdriezen@sympatico.ca" moz-do-not-send="true"
class="moz-txt-link-freetext">jdriezen@sympatico.ca</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Can
anyone give me a regular expression to turn the following
filename<br>
<br>
"Zero.Dark.Thirty.2012.720p.BrRip.x264.BOKUTOX.YIFY.mp4"<br>
<br>
into<br>
<br>
"Zero Dark Thirty (2012)-720p.mp4"<br>
<br>
201[0-9] matches the year<br>
<br>
How do I match the title before the year, and ignore
everything after <br>
the ".720p"?<br>
<br>
John Driezen<br>
<br>
<br>
<br>
_______________________________________________<br>
kwlug-disc mailing list<br>
To unsubscribe, send an email to <a
href="mailto:kwlug-disc-leave@kwlug.org" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">kwlug-disc-leave@kwlug.org</a><br>
with the subject "unsubscribe", or email<br>
<a href="mailto:kwlug-disc-owner@kwlug.org" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">kwlug-disc-owner@kwlug.org</a>
to contact a human being.<br>
</blockquote>
</div>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre wrap="" class="moz-quote-pre">_______________________________________________
kwlug-disc mailing list
To unsubscribe, send an email to <a
class="moz-txt-link-abbreviated moz-txt-link-freetext"
href="mailto:kwlug-disc-leave@kwlug.org" moz-do-not-send="true">kwlug-disc-leave@kwlug.org</a>
with the subject "unsubscribe", or email
<a class="moz-txt-link-abbreviated moz-txt-link-freetext"
href="mailto:kwlug-disc-owner@kwlug.org" moz-do-not-send="true">kwlug-disc-owner@kwlug.org</a> to contact a human being.
</pre>
</blockquote>
</div>
</body>
</html>