Talk:AniDB O'Matic - Documentation: Local file renaming - Samples

From AniDB
Jump to navigation Jump to search

Anidb ed2k filename pattern

I wanted a filename pattern that was as close as possible to the AniDB filename pattern for the ed2k links

  • Its not perfect as some information is missing in AoM (like the necessary information for the "(RAW)" part of the filename) but its pretty close
  • It assumes the default language settings in AniDB for anime and episode titles
  • Version and episode numbers work a little different in this version. This was because of an issue with specials and such with the default pattern

Hope others find this pattern useful.

set('atitle', at('x-jat'))
if(length(atitle)=0, set('atitle', at('en')))
if(length(atitle)=0, set('atitle', A.Name))
set('atitle', replace(atitle, '\', ' '))

set('etitle', et('en'))
if(length(etitle)=0, set('etitle', et('x-jat')))
if(length(etitle)=0, set('etitle', et('ja')))
if(length(etitle)=0, set('etitle', E.Name))
set('etitle', replace(etitle, '\', ' '))

set('version', if(F.Version>1, 'v'+F.Version, ''))
set('mepno', if(E.TypeId=1, max(A.TotalEpisodeCount, E.EpisodeTypeCount), 1))
set('epno', padl(E.EpisodeStr, max(1, length(mepno)), '0') + version)

set('groupname', if(G, if(length(G.Shortname)>0, G.Shortname, G.Name), ''))
set('groupname', if(length(groupname)>0, '['+groupname+']'))
set('groupname', replace(groupname, '\', ' '))

set('crc', if(F.CrcStatus='crcOk', if(H, H.Crc32, F.Crc), ''))
if(length(crc)=0, set('crc', if(F.CrcStatus='crcInvalid', 'invalid_crc', '')))
if(length(crc)>0, set('crc', '('+lc(crc)+')'))

set('censored', '')
set('state_map', F.State mod 4096)
if(state_map>=2048, set('state_map', state_map - 2048))
if(state_map>=1024, set('state_map', state_map - 1024))
if(state_map>=512, set('state_map', state_map - 512))
if(state_map>=256, set('state_map', state_map - 256))
if(state_map>=128, set('censored', '(cen)') + set('state_map', state_map - 128))
if(state_map>=64, set('censored', '(unc)') + set('state_map', state_map - 64))

set('filename_p1', atitle)
set('filename_p2', epno + ' - ' + etitle)
set('filename_p3', limit(groupname, 35) + crc + censored)
set('filename_ext', '.' + F.FileType)

set('path_filename', PATH)
set('path_parts', 1)
for('i', 1, length(path_filename), if(copy(path_filename, i, 1) = '\', set('path_parts', path_parts+1)))
set('path_filename', split(path_filename, '\', path_parts))
set('path_length', length(PATH) - length(path_filename))

set('filename_p3_length', length(filename_p3))
set('filename_ext_length', length(filename_ext))
set('filename_maxlength', 255)
set('filename_maxlength', filename_maxlength - 1)
set('filename_maxlength', filename_maxlength - filename_ext_length)
set('filename_maxlength', filename_maxlength - path_length)

set('filename', limit(limit(filename_p1, 90) + ' - ' + filename_p2, filename_maxlength-filename_p3_length) + if(filename_p3_length>0, ' - ' + filename_p3) + filename_ext)

set('filename', replace(filename, '*', ' '))
set('filename', replace(filename, '/', '-'))
set('filename', replace(filename, '?', '.'))
set('filename', replace(filename, ':', '.'))
set('filename', replace(filename, '"', "'"))
set('filename', replace(filename, '<', ' '))
set('filename', replace(filename, '>', ' '))
set('filename', replace(filename, '|', ' '))
set('filename', replace(filename, '  ', ' '))
set('filename', replace(filename, ' ', '_'))
set('filename', replace(filename, '__', '_'))
filename

Reaver56 (talk) 02:49, 21 October 2017 (UCT)