IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Export Config to Count Files for Each Podcast Category, (e.g., how many Documentaries, Lectures, etc. do I have?)
rko31415
post Jul 11 2016, 22:55
Post #1


Member


Group: Full Members
Posts: 96
Joined: 22-October 13
Member No.: 18669
Mp3tag Version: 2.58



The attached export config displays a count of files containing each podcast category (%podcastcategory%). It takes into account multi-value fields.
I use it to find spelling and other errors in the categories.
It's easy to modify for any other tags you may want to count.

Program logic:
1) build a master file containing all categories (on the desktop)
2) sort the file
3) iterate through the file looking for changes one to the next and counting as you go

It leaves a couple of files on the desktop for you to clean up when you're done.

One nagging issue remains: it screws up if the field contains a pipe (|). I haven't figured out yet how to escape those darn pipes in the meta_sep operation.

Note: mostly not my coding. I merely modified some code found on stackoverflow

.mte coding is as follows ------------

$filename($getEnv('USERPROFILE')'\desktop\CategoryCounts.bat',ANSI)
@Echo Off
chcp 1254
if exist "%%USERPROFILE%%\Desktop\taglisting.txt" del "%%USERPROFILE%%\Desktop\taglisting.txt" /q
$loop(%podcastcategory%)
echo>>"%%USERPROFILE%%\Desktop\taglisting.txt" $meta_sep(podcastcategory,$char(13)$char(10)echo>>"%%USERPROFILE%%\Desktop\taglisting.txt" )
$loopend()
@echo off
setlocal disableDelayedExpansion
set "file=%%USERPROFILE%%\Desktop\taglisting.txt"
set "sorted=%%file%%.sorted"
set "counted=%%file%%.counted"
set /a N = 1
REM Define a variable containing a linefeed character
set LF=^


REM The 2 blank lines above are critical, do not remove
sort "%%file%%" >"%%sorted%%"
>"%%counted%%" (
set "prev=start"
for /f usebackq^ eol^=^%%LF%%%%LF%%^ delims^= %%%%A in ("%%sorted%%") do (
set "curr=%%%%A"
setlocal enableDelayedExpansion
if /i "!curr!" neq "!prev!" (
if "!prev!" neq "start" echo !n! !prev!
endlocal
set "prev=%%%%A"
set /a N = 1
) else (
endlocal
set /a N += 1
)
)
setlocal enableDelayedExpansion
echo !n! !curr!
endlocal
)
>nul move /y "%%counted%%" "%%file%%"
del "%%sorted%%"
"%%USERPROFILE%%\Desktop\taglisting.txt"
Attached File(s)
Attached File  CategoryCounts.mte ( 1.19K ) Number of downloads: 112
 
Go to the top of the page
 
+Quote Post
rko31415
post Jul 12 2016, 13:34
Post #2


Member


Group: Full Members
Posts: 96
Joined: 22-October 13
Member No.: 18669
Mp3tag Version: 2.58



Little bit slower but the following fixes the pipes (|) question I left above.

$filename($getEnv('USERPROFILE')'\desktop\TagCount.bat',ANSI)
@Echo Off
chcp 1254
if exist "%%USERPROFILE%%\Desktop\taglisting.txt" del "%%USERPROFILE%%\Desktop\taglisting.txt" /q
REM Creating a Newline variable (the two blank lines below are required!)
set NLM=^


set NL=^^^%%NLM%%%%NLM%%^%%NLM%%%%NLM%%
$loop(%album%)
$if(%PodcastCategory%,set "string=$meta_sep(PodcastCategory,|)"
setlocal enableDelayedExpansion
SET string=!string:^|=%%NL%%!
echo !string!>>"%%USERPROFILE%%\Desktop\taglisting.txt"
endlocal,)
$loopend()
@echo off
setlocal disableDelayedExpansion
set "file=%%USERPROFILE%%\Desktop\taglisting.txt"
set "sorted=%%file%%.sorted"
set "counted=%%file%%.counted"
set /a N = 1
REM Define a variable containing a linefeed character
set LF=^


REM The 2 blank lines above are critical, do not remove
sort "%%file%%" >"%%sorted%%"
>"%%counted%%" (
set "prev=start"
for /f usebackq^ eol^=^%%LF%%%%LF%%^ delims^= %%%%A in ("%%sorted%%") do (
set "curr=%%%%A"
setlocal enableDelayedExpansion
if /i "!curr!" neq "!prev!" (
if "!prev!" neq "start" echo !n! !prev!
endlocal
set "prev=%%%%A"
set /a N = 1
) else (
endlocal
set /a N += 1
)
)
setlocal enableDelayedExpansion
echo !n! !curr!
endlocal
)
>nul move /y "%%counted%%" "%%file%%"
del "%%sorted%%"
"%%USERPROFILE%%\Desktop\taglisting.txt"
Attached File(s)
Attached File  ___PodcastCategoryCounts.mte ( 1.37K ) Number of downloads: 98
 
Go to the top of the page
 
+Quote Post
rko31415
post Jul 22 2016, 22:53
Post #3


Member


Group: Full Members
Posts: 96
Joined: 22-October 13
Member No.: 18669
Mp3tag Version: 2.58



Discovered a small bug in the script. It didn't handle percentage signs.

The key line should replaced to as follows:
$if(%PodcastCategory%,set "string=$replace($meta_sep(PodcastCategory,|),'%','%%')"

k
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 21st October 2017 - 11:20