1# -*- coding: utf-8 -*-
2
3# Copyright(C) 2013 Julien Veyssier
4#
5# This file is part of weboob.
6#
7# weboob is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Lesser General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# weboob is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Lesser General Public License for more details.
16#
17# You should have received a copy of the GNU Lesser General Public License
18# along with weboob. If not, see <http://www.gnu.org/licenses/>.
19
20
21from .base import Capability, BaseObject, StringField, IntField, Field
22from .date import DateField
23
24
25__all__ = ['Movie', 'Person', 'CapCinema']
26
27
28class Movie(BaseObject):
29    """
30    Movie object.
31    """
32    original_title    = StringField('Original title of the movie')
33    other_titles      = Field('Titles in other countries', list)
34    release_date      = DateField('Release date of the movie')
35    all_release_dates = StringField('Release dates list of the movie')
36    duration          = IntField('Duration of the movie in minutes')
37    short_description = StringField('Short description of the movie')
38    genres            = Field('Genres of the movie', list)
39    pitch             = StringField('Short story description of the movie')
40    country           = StringField('Origin country of the movie')
41    note              = StringField('Notation of the movie')
42    roles             = Field('Lists of Persons related to the movie indexed by roles', dict)
43    thumbnail_url     = StringField('Url of movie thumbnail')
44
45    def __init__(self, id, original_title, url=None):
46        super(Movie, self).__init__(id, url)
47        self.original_title = original_title
48
49    def get_roles_by_person_name(self, name):
50        for role in self.roles.keys():
51            if name.lower() in [person[1].lower() for person in self.roles[role]]:
52                return role
53        return None
54
55    def get_roles_by_person_id(self, id):
56        result = []
57        for role in self.roles.keys():
58            if id in [person[0] for person in self.roles[role]]:
59                result.append(role)
60
61        return result
62
63
64class Person(BaseObject):
65    """
66    Person object.
67    """
68    name              = StringField('Star name of a person')
69    real_name         = StringField('Real name of a person')
70    birth_date        = DateField('Birth date of a person')
71    death_date        = DateField('Death date of a person')
72    birth_place       = StringField('City and country of birth of a person')
73    gender            = StringField('Gender of a person')
74    nationality       = StringField('Nationality of a person')
75    short_biography   = StringField('Short biography of a person')
76    biography         = StringField('Full biography of a person')
77    short_description = StringField('Short description of a person')
78    roles             = Field('Lists of movies related to the person indexed by roles', dict)
79    thumbnail_url     = StringField('Url of person thumbnail')
80
81    def __init__(self, id, name, url=None):
82        super(Person, self).__init__(id, url)
83        self.name = name
84
85    def get_roles_by_movie_title(self, title):
86        for role in self.roles.keys():
87            for mt in [movie[1] for movie in self.roles[role]]:
88                # title we have is included ?
89                if title.lower() in mt.lower():
90                    return role
91        return None
92
93    def get_roles_by_movie_id(self, id):
94        result = []
95        for role in self.roles.keys():
96            if id in [movie[0] for movie in self.roles[role]]:
97                result.append(role)
98
99        return result
100
101
102class CapCinema(Capability):
103    """
104    Cinema databases.
105    """
106
107    def iter_movies(self, pattern):
108        """
109        Search movies and iterate on results.
110
111        :param pattern: pattern to search
112        :type pattern: str
113        :rtype: iter[:class:`Movies`]
114        """
115        raise NotImplementedError()
116
117    def get_movie(self, _id):
118        """
119        Get a movie object from an ID.
120
121        :param _id: ID of movie
122        :type _id: str
123        :rtype: :class:`Movie`
124        """
125        raise NotImplementedError()
126
127    def get_movie_releases(self, _id, country=None):
128        """
129        Get a list of a movie releases from an ID.
130
131        :param _id: ID of movie
132        :type _id: str
133        :rtype: :class:`String`
134        """
135        raise NotImplementedError()
136
137    def iter_movie_persons(self, _id, role=None):
138        """
139        Get the list of persons who are related to a movie.
140
141        :param _id: ID of movie
142        :type _id: str
143        :rtype: iter[:class:`Person`]
144        """
145        raise NotImplementedError()
146
147    def iter_persons(self, pattern):
148        """
149        Search persons and iterate on results.
150
151        :param pattern: pattern to search
152        :type pattern: str
153        :rtype: iter[:class:`persons`]
154        """
155        raise NotImplementedError()
156
157    def get_person(self, _id):
158        """
159        Get a person object from an ID.
160
161        :param _id: ID of person
162        :type _id: str
163        :rtype: :class:`Person`
164        """
165        raise NotImplementedError()
166
167    def iter_person_movies(self, _id, role=None):
168        """
169        Get the list of movies related to a person.
170
171        :param _id: ID of person
172        :type _id: str
173        :rtype: iter[:class:`Movie`]
174        """
175        raise NotImplementedError()
176
177    def iter_person_movies_ids(self, _id):
178        """
179        Get the list of movie ids related to a person.
180
181        :param _id: ID of person
182        :type _id: str
183        :rtype: iter[str]
184        """
185        raise NotImplementedError()
186
187    def iter_movie_persons_ids(self, _id):
188        """
189        Get the list of person ids related to a movie.
190
191        :param _id: ID of movie
192        :type _id: str
193        :rtype: iter[str]
194        """
195        raise NotImplementedError()
196
197    def get_person_biography(self, id):
198        """
199        Get the person full biography.
200
201        :param _id: ID of person
202        :type _id: str
203        :rtype: str
204        """
205        raise NotImplementedError()
206