home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
MediaPortal 1 Talk
TV recordings renamed with metadata COMMENT tag
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Mike Amory" data-source="post: 1192733" data-attributes="member: 152945"><p>MediaPortal 1 doesn't allow to use COMMENT tag in the filename format of TV recordings. In Finland series and episode info is inside the COMMENT tag. This FoxPro program renames TV recordings with the COMMENT tag. This program is freeware and you can modify it as you please. </p><p></p><p>----------------- SNIP ------------------</p><p>* FILE: bulkrename.prg</p><p>* This program adds metadata to file names of MediaPortal TV recordings.</p><p>* 40 leftmost and 40 rightmost characters of COMMENT tag in .xml file are added and</p><p>* the first occurrence of character @ in the file name marks the placing of the metadata.</p><p>* This program is useful if series and episode info is inside the COMMENT tag.</p><p>* MediaPortal doesn't allow to use COMMENT tag in the filename format of TV recordings</p><p>* Windows 7 gives OLE error code 0x80070057 if files are on external drive bigger than 2TB,</p><p>* so this program gives the user option to directly rename all files in selected directory</p><p>* or write the rename commands into a batch file "bulkrename.cmd" that user can run later (recommended).</p><p>* Visual FoxPro does not recognize a path name properly if disk or directory name contains an exclamation point (!).</p><p>* Running batch file "bulkrename.cmd" may give an error "the system cannot find file specified",</p><p>* changing the character code page in the beginning of the batch file solves this problem.</p><p>* Default character set is ANSI (Windows-1252), that is character encoding of the Latin alphabet</p><p>* Preserves the original case of paths and file names.</p><p>* Works with Visual Foxpro 9.0.</p><p>* Example:</p><p>* Original filename: Blacklist @ SE_2016-05-19-1_25-TV5.ts</p><p>* Renamed file: Blacklist @ (Series 1, Episode 19. The Pavlovich Brothers.) SE_2016-05-19-1_25-TV5.ts</p><p></p><p>CLEAR ALL</p><p>CLOSE ALL</p><p>CREATE TABLE Recordings (Recname c(250), Meta m) && Create a temp table</p><p>USE Recordings ALIAS Recordings && Open the table</p><p>DIMENSION Temparray(1,5) && Declare array to store file names</p><p>ofs=CREATEOBJECT('scripting.filesystemobject')</p><p>o=CREATEOBJECT('scripting.filesystemobject')</p><p>path = GETDIR()</p><p>IF EMPTY(path)</p><p> WAIT 'Directory not selected' WINDOW</p><p> RETURN</p><p>ENDIF</p><p>path = ofs.GetAbsolutePathName(path)</p><p>path = ADDBS(path)</p><p>WAIT 'Press Y if you want to send commands to a batch file instead of executing them.' TO Retval WINDOW</p><p>IF ALLTRIM(UPPER(Retval))='Y'</p><p> Writebatch=.T.</p><p> IF FILE(path + 'bulkrename.cmd') && Does file exist?</p><p> fhandle = FOPEN(path + 'bulkrename.cmd',12) && If so, open read/write unbuffered</p><p> ELSE</p><p> fhandle = FCREATE(path + 'bulkrename.cmd') && If not create it</p><p> ENDIF</p><p> IF fhandle < 0 && Check for error opening file</p><p> WAIT 'Cannot open or create output file' WINDOW</p><p> RETURN</p><p> ELSE</p><p> FPUTS(fhandle, 'chcp 1252')</p><p> ENDIF</p><p>ELSE</p><p> Writebatch=.F.</p><p>ENDIF</p><p>ln = ADIR(Temparray, path + '*.ts','A' ,1) && Use ADIR() function to get recording names into array</p><p>* DIMENSION lcFileName2(1,1) AS String, lcNewFileName(1,1) AS String</p><p>FOR i = 1 TO ln && Store file names into Recordings table</p><p> lcFileName2=path + ofs.getfile(path + Temparray[i,1]).name</p><p> IF .NOT. FILE(lcFileName2)</p><p> WAIT 'Error locating a file' WINDOW</p><p> RETURN</p><p> ENDIF</p><p> SELECT Recordings</p><p> APPEND BLANK</p><p> REPLACE Recname WITH Temparray(i,1)</p><p> IF FILE(path + LEFT(TRIM(Recname), LEN(TRIM(Recname))-3) +'.xml') && Tries to find the xml file of the recording</p><p> APPEND MEMO Meta FROM path + LEFT(TRIM(Recname), LEN(TRIM(Recname))-3) +'.xml' && Metadata is added into the memo field</p><p> Comment = SUBSTR(Meta,AT('<name>COMMENT</name>', Meta )+35)</p><p> Comment = LEFT(Comment,AT('</value>', Comment)-1)</p><p> Comment = CHRTRAN(Comment, '*/:<>?|\' + CHR(34), '_________' ) && Replacing invalid characters with underscore</p><p> Addstr1 = LEFT(Comment,40) && 40 characters from the beginning of COMMENT tag</p><p> Addstr2 = RIGHT(Comment,40) && 40 characters from the end of COMMENT tag</p><p> IF EMPTY(Comment)</p><p> Addstr = '@ ( ) '</p><p> ELSE</p><p> IF LEN(Comment) < 81</p><p> Addstr = '@ (' + Comment + ') '</p><p> ELSE</p><p> Addstr = '@ (' + Addstr1 + '...' + Addstr2 + ') '</p><p> ENDIF</p><p> ENDIF</p><p> Addstr = STRCONV(Addstr, 11) && Converts UTF-8 characters to double-byte characters, works for Scandinavian character set</p><p> lcNewFileName = STUFF(lcFileName2, AT('@',lcFileName2),1, Addstr)</p><p> IF FILE(lcFileName2)</p><p> IF Writebatch=.T.</p><p> tmpstr = 'RENAME ' + CHR(34) + lcFileName2 + CHR(34) + ' ' + CHR(34) + JUSTFNAME(lcNewFileName) + CHR(34)</p><p> FPUTS(fhandle, tmpstr)</p><p> ELSE</p><p> o.movefile(lcFileName2, lcNewFileName)</p><p> ENDIF</p><p> ENDIF</p><p> lcFileName2 = LEFT(TRIM(lcFileName2), LEN(TRIM(lcFileName2))-3) +'.xml'</p><p> lcNewFileName = STUFF(lcFileName2, AT('@',lcFileName2),1, Addstr)</p><p> IF FILE(lcFileName2)</p><p> IF Writebatch=.T.</p><p> tmpstr = 'RENAME ' + CHR(34) + lcFileName2 + CHR(34) + ' ' + CHR(34) + JUSTFNAME(lcNewFileName) + CHR(34)</p><p> FPUTS(fhandle, tmpstr)</p><p> ELSE</p><p> o.movefile(lcFileName2, lcNewFileName)</p><p> ENDIF</p><p> ENDIF</p><p> ENDIF</p><p>NEXT i</p><p>IF Writebatch=.T.</p><p> =FCLOSE(fhandle) && Close file</p><p> MODIFY FILE (path + 'bulkrename.cmd') NOWAIT && Open file in edit window</p><p>ENDIF</p><p>RETURN</p><p>----------------- SNIP ------------------</p></blockquote><p></p>
[QUOTE="Mike Amory, post: 1192733, member: 152945"] MediaPortal 1 doesn't allow to use COMMENT tag in the filename format of TV recordings. In Finland series and episode info is inside the COMMENT tag. This FoxPro program renames TV recordings with the COMMENT tag. This program is freeware and you can modify it as you please. ----------------- SNIP ------------------ * FILE: bulkrename.prg * This program adds metadata to file names of MediaPortal TV recordings. * 40 leftmost and 40 rightmost characters of COMMENT tag in .xml file are added and * the first occurrence of character @ in the file name marks the placing of the metadata. * This program is useful if series and episode info is inside the COMMENT tag. * MediaPortal doesn't allow to use COMMENT tag in the filename format of TV recordings * Windows 7 gives OLE error code 0x80070057 if files are on external drive bigger than 2TB, * so this program gives the user option to directly rename all files in selected directory * or write the rename commands into a batch file "bulkrename.cmd" that user can run later (recommended). * Visual FoxPro does not recognize a path name properly if disk or directory name contains an exclamation point (!). * Running batch file "bulkrename.cmd" may give an error "the system cannot find file specified", * changing the character code page in the beginning of the batch file solves this problem. * Default character set is ANSI (Windows-1252), that is character encoding of the Latin alphabet * Preserves the original case of paths and file names. * Works with Visual Foxpro 9.0. * Example: * Original filename: Blacklist @ SE_2016-05-19-1_25-TV5.ts * Renamed file: Blacklist @ (Series 1, Episode 19. The Pavlovich Brothers.) SE_2016-05-19-1_25-TV5.ts CLEAR ALL CLOSE ALL CREATE TABLE Recordings (Recname c(250), Meta m) && Create a temp table USE Recordings ALIAS Recordings && Open the table DIMENSION Temparray(1,5) && Declare array to store file names ofs=CREATEOBJECT('scripting.filesystemobject') o=CREATEOBJECT('scripting.filesystemobject') path = GETDIR() IF EMPTY(path) WAIT 'Directory not selected' WINDOW RETURN ENDIF path = ofs.GetAbsolutePathName(path) path = ADDBS(path) WAIT 'Press Y if you want to send commands to a batch file instead of executing them.' TO Retval WINDOW IF ALLTRIM(UPPER(Retval))='Y' Writebatch=.T. IF FILE(path + 'bulkrename.cmd') && Does file exist? fhandle = FOPEN(path + 'bulkrename.cmd',12) && If so, open read/write unbuffered ELSE fhandle = FCREATE(path + 'bulkrename.cmd') && If not create it ENDIF IF fhandle < 0 && Check for error opening file WAIT 'Cannot open or create output file' WINDOW RETURN ELSE FPUTS(fhandle, 'chcp 1252') ENDIF ELSE Writebatch=.F. ENDIF ln = ADIR(Temparray, path + '*.ts','A' ,1) && Use ADIR() function to get recording names into array * DIMENSION lcFileName2(1,1) AS String, lcNewFileName(1,1) AS String FOR i = 1 TO ln && Store file names into Recordings table lcFileName2=path + ofs.getfile(path + Temparray[i,1]).name IF .NOT. FILE(lcFileName2) WAIT 'Error locating a file' WINDOW RETURN ENDIF SELECT Recordings APPEND BLANK REPLACE Recname WITH Temparray(i,1) IF FILE(path + LEFT(TRIM(Recname), LEN(TRIM(Recname))-3) +'.xml') && Tries to find the xml file of the recording APPEND MEMO Meta FROM path + LEFT(TRIM(Recname), LEN(TRIM(Recname))-3) +'.xml' && Metadata is added into the memo field Comment = SUBSTR(Meta,AT('<name>COMMENT</name>', Meta )+35) Comment = LEFT(Comment,AT('</value>', Comment)-1) Comment = CHRTRAN(Comment, '*/:<>?|\' + CHR(34), '_________' ) && Replacing invalid characters with underscore Addstr1 = LEFT(Comment,40) && 40 characters from the beginning of COMMENT tag Addstr2 = RIGHT(Comment,40) && 40 characters from the end of COMMENT tag IF EMPTY(Comment) Addstr = '@ ( ) ' ELSE IF LEN(Comment) < 81 Addstr = '@ (' + Comment + ') ' ELSE Addstr = '@ (' + Addstr1 + '...' + Addstr2 + ') ' ENDIF ENDIF Addstr = STRCONV(Addstr, 11) && Converts UTF-8 characters to double-byte characters, works for Scandinavian character set lcNewFileName = STUFF(lcFileName2, AT('@',lcFileName2),1, Addstr) IF FILE(lcFileName2) IF Writebatch=.T. tmpstr = 'RENAME ' + CHR(34) + lcFileName2 + CHR(34) + ' ' + CHR(34) + JUSTFNAME(lcNewFileName) + CHR(34) FPUTS(fhandle, tmpstr) ELSE o.movefile(lcFileName2, lcNewFileName) ENDIF ENDIF lcFileName2 = LEFT(TRIM(lcFileName2), LEN(TRIM(lcFileName2))-3) +'.xml' lcNewFileName = STUFF(lcFileName2, AT('@',lcFileName2),1, Addstr) IF FILE(lcFileName2) IF Writebatch=.T. tmpstr = 'RENAME ' + CHR(34) + lcFileName2 + CHR(34) + ' ' + CHR(34) + JUSTFNAME(lcNewFileName) + CHR(34) FPUTS(fhandle, tmpstr) ELSE o.movefile(lcFileName2, lcNewFileName) ENDIF ENDIF ENDIF NEXT i IF Writebatch=.T. =FCLOSE(fhandle) && Close file MODIFY FILE (path + 'bulkrename.cmd') NOWAIT && Open file in edit window ENDIF RETURN ----------------- SNIP ------------------ [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
MediaPortal 1 Talk
TV recordings renamed with metadata COMMENT tag
Contact us
RSS
Top
Bottom