Package: aniparse
AniparseAniparse is a Python library for parsing anime video filenames. It's simple to use, and it's based on the C++
libraryAnitomywith a lot of improvement.UpdateThis library has already achieved its goal in a somewhat hacky way, as discussed inissue #9.
I am aware that the last commit isn't the clean code, but I don't have much time to work on this project anymore.
It's a sacrifice I have to make. I don't expect any improvements here for another year or so unless something breaks.
If you have an interest in this project, I would suggest you take a look at thev2-ideabranch instead.
I've documented the library's goals, how I plan to achieve them, and other details more comprehensively in that branch.ExampleThe following filename[TaigaSubs]_Toradora!_(2008)_-_01v2_-_Tiger_and_Dragon_[1280x720_H.264_FLAC][1234ABCD].mkv
Toradora! S01E03-Your Song.mkvcan be parsed using the following code:importaniparseaniparse.parse('[TaigaSubs]_Toradora!_(2008)_-_01v2_-_Tiger_and_Dragon_[1280x720_H.264_FLAC][1234ABCD].mkv'){'anime_title':'Toradora!','anime_year':2008,'audio_term':'FLAC','episode_number':1,'episode_title':'Tiger and Dragon','file_checksum':'1234ABCD','file_extension':'mkv','file_name':'[TaigaSubs]_Toradora!_(2008)_-_01v2_-_Tiger_and_Dragon_[1280x720_H.264_FLAC][1234ABCD].mkv','release_group':'TaigaSubs','release_version':2,'video_resolution':'1280x720','video_term':'H.264'}aniparse.parse("Toradora! S01E03-Your Song.mkv"){'anime_season':1,'anime_season_prefix':'S','anime_title':'Toradora!','episode_number':3,'episode_prefix':'E','episode_title':'Your Song','file_extension':'mkv','file_name':'Toradora! S01E03-Your Song.mkv'}Theparsefunction receives a string and returns a dictionary containing all found elements.
It can also receive parsingoptionsandkeyword_manager, this will be explained below.How does it work?Suppose that we're working on the following filename:"Aim_For_The_Top!_Gunbuster-ep1.BD(H264.FLAC.10bit)[KAA][69ECCDCF].mkv"The filename is first stripped off of its extension and split into groups. Groups are determined by the position of
brackets:"Aim_For_The_Top!_Gunbuster-ep1.BD", "H264.FLAC.10bit", "KAA", "69ECCDCF"Each group is then split into tokens. In our current example, the delimiter for the enclosed group is., while the
words in other groups are separated by_:"Aim", "For", "The", "Top!", "Gunbuster-ep1", "BD", "H264", "FLAC", "10bit", "KAA", "69ECCDCF"Note: the brackets and delimiter are stored as token with categoryDelimiterandBracket. And each token remembers
if it enclosed or not.Once the tokenizer is done, the parser comes into effect.
First, all tokens are compared against a set of known keywords. In this case,
the tokensBD,H264,FLAC,10bit, and69ECCDCFare recognized as keywords,
and are assigned the categorySource,VideoTerm,AudioTerm,VideoResolution, andFileChecksumrespectively."Aim", "For", "The", "Top!", "Gunbuster-ep1", "KAA"The next step is to look for the episode number. Each token that contains a number is analyzed. Here.Gunbuster-ep1contains number, but it doesn't match the episode number pattern. In this case,
the token checked againts buggy dash pattern. So,Gunbuster-ep1will be split intoGunbusterandep1.
After that, it will check andep1is recognized as an episode number.
The categoryEpisodeNumberis assigned to it and the changes is saved."Aim", "For", "The", "Top!", "Gunbuster", "KAA"The next step is to look for the anime title. The parser will try to find unknown token before the episode number and
not inside a bracket.
In this case,Aim,For,The,Top!, andGunbusterare unknown tokens, they are not inside a bracket, so it
assigned to theAnimeTitlecategory."KAA"the next step is to look for the release group. The parser will try to find unknown token after the episode number and
inside a bracket.
In this case,KAAis unknown token, and it inside a bracket, so it assigned to theReleaseGroupcategory.the next step is to look for the episode title. The parser will try to find unknown token after the episode number and
not inside a bracket.
In this case, no more unknown token left, so it leave it emptylastly, the parser will try to find any unknown token and assign it to each category or toOthersif it is not
recognized.Why should I use it?Anime video files are commonly named in a format where the anime title is followed by the episode number,
and all the technical details are enclosed within brackets.
However, fansub groups tend to use their own naming conventions,
and the problem is more complicated than it first appears:Element order is not always the same.
Technical information is not guaranteed to be enclosed.
Brackets and parentheses may be grouping symbols or a part of the anime/episode title.
Space and underscore are not the only delimiters in use.
A single filename may contain multiple delimiters.
There are so many cases to cover that it's simply not possible to parse all filenames solely with
regular expressions. Aniparse tries a different approach, and it succeeds:
It's able to parse tens of thousands of filenames, with great accuracy.Are there any exceptions?Yes, unfortunately. Aniparse fails to identify the anime title and episode number on rare occasions,
mostly due to bad naming conventions. See the examples below.Arigatou.Shuffle!.Ep08.[x264.AAC][D6E43829].mkv
Here, Aniparse would report that this file is the 8th episode ofArigatou Shuffle!, whereArigatouis actually the
name of the fansub group.Spice and Wolf 2
Is this the 2nd episode ofSpice and Wolf, or a batch release ofSpice and Wolf 2? with a text after number, there's
no way to know. It's up to you consider both cases. For current version, it treats as part of title if it's not leading zero,
and as episode number if it's leading zero.Suggestions to fansub groupsPlease consider abiding by these simple rules before deciding on your naming convention:Don't enclose anime title, episode number and episode title within brackets. Enclose everything else, including the
name of your group.Don't use parentheses to enclose release information; use square brackets instead. Parentheses should only be used if
they are a part of the anime/episode title.Don't use multiple delimiters in a single filename. If possible, stick with either space or underscore.Use a separator (e.g. a dash) between anime title and episode number. There are anime titles that end with a number,
which creates ambiguity.Indicate the episode interval in batch releases.InstallationTo install Aniparse, simply use pip:pip install aniparseOr download the source code and inside the source code's folder run:python setup.py installOptionsTheparsefunction can receive theoptionsparameter. E.g.:importaniparseaniparse_options={'allowed_delimiters':' '}aniparse.parse('DRAMAtical Murder Episode 1 - Data_01_Login',options=aniparse_options){'anime_title':'DRAMAtical Murder','episode_prefix':'Episode','episode_number':'1','episode_title':'Data_01_Login','file_name':'DRAMAtical Murder Episode 1 - Data_01_Login'}If the default options had been used, the parser would have considered_as a delimiter and replaced it with space in
the episode title.The options contain the following attributes:Attribute nameTypeDescriptionDefault valueallowed_delimitersstringThe list of character to be considered as delimiters.' _.&+,|'check_title_enclosedbooleanCheck the anime title in enclosed if no title foundTrueeps_lower_than_altbooleanSet episode number to the lowest and the alt to be the highestTrueignored_dashbooleanIf the dash in anime/episode title should be ignored or not.Trueignored_stringslist of stringsA list of strings to be removed from the filename during parse.[]keep_delimitersbooleanIf the delimiters should be kept or not in anime/episode title.Falsemax_extension_lengthintegerMaximum extension length.4title_before_episodebooleanIf the anime title should be before the episode number or not.TrueLicenseAniparseis licensed underMozilla Public License 2.0.