mirror of
https://github.com/zoriya/guessit.git
synced 2026-06-07 04:06:01 +00:00
Added suggested_expected method to the API to support apps that uses guessit as a library
This commit is contained in:
@@ -82,6 +82,19 @@ def properties(options=None):
|
||||
return default_api.properties(options)
|
||||
|
||||
|
||||
def suggested_expected(titles, options=None):
|
||||
"""
|
||||
Return a list of suggested titles to be used as `expected_title` based on the list of titles
|
||||
:param titles: the filename or release name
|
||||
:type titles: list|set|dict
|
||||
:param options:
|
||||
:type options: str|dict
|
||||
:return:
|
||||
:rtype: list of str
|
||||
"""
|
||||
return default_api.suggested_expected(titles, options)
|
||||
|
||||
|
||||
class GuessItApi(object):
|
||||
"""
|
||||
An api class that can be configured with custom Rebulk configuration.
|
||||
@@ -228,5 +241,23 @@ class GuessItApi(object):
|
||||
ordered = self.rebulk.customize_properties(ordered)
|
||||
return ordered
|
||||
|
||||
def suggested_expected(self, titles, options=None):
|
||||
"""
|
||||
Return a list of suggested titles to be used as `expected_title` based on the list of titles
|
||||
:param titles: the filename or release name
|
||||
:type titles: list|set|dict
|
||||
:param options:
|
||||
:type options: str|dict
|
||||
:return:
|
||||
:rtype: list of str
|
||||
"""
|
||||
suggested = []
|
||||
for title in titles:
|
||||
guess = self.guessit(title, options)
|
||||
if len(guess) != 2 or 'title' not in guess:
|
||||
suggested.append(title)
|
||||
|
||||
return suggested
|
||||
|
||||
|
||||
default_api = GuessItApi()
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"titles": [
|
||||
"13 Reasons Why",
|
||||
"Star Wars: Episode VII - The Force Awakens",
|
||||
"3%",
|
||||
"The 100",
|
||||
"3 Percent",
|
||||
"This is Us",
|
||||
"Open Season 2",
|
||||
"Game of Thrones",
|
||||
"The X-Files",
|
||||
"11.22.63"
|
||||
],
|
||||
"suggested": [
|
||||
"13 Reasons Why",
|
||||
"Star Wars: Episode VII - The Force Awakens",
|
||||
"The 100",
|
||||
"Open Season 2",
|
||||
"11.22.63"
|
||||
]
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name, pointless-string-statement
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
import six
|
||||
|
||||
from ..api import guessit, properties, GuessitException
|
||||
from ..api import guessit, properties, suggested_expected, GuessitException
|
||||
|
||||
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
|
||||
|
||||
@@ -74,3 +74,10 @@ def test_exception():
|
||||
assert "An internal error has occured in guessit" in str(excinfo.value)
|
||||
assert "Guessit Exception Report" in str(excinfo.value)
|
||||
assert "Please report at https://github.com/guessit-io/guessit/issues" in str(excinfo.value)
|
||||
|
||||
|
||||
def test_suggested_expected():
|
||||
with open(os.path.join(__location__, 'suggested.json'), 'r') as f:
|
||||
content = json.load(f)
|
||||
actual = suggested_expected(content['titles'])
|
||||
assert actual == content['suggested']
|
||||
|
||||
Reference in New Issue
Block a user