Exemple #1
0
def buildSingle(inetref, opts):
    from MythTV.tmdb3.tmdb_exceptions import TMDBRequestInvalid
    from MythTV.tmdb3 import Movie
    from MythTV import VideoMetadata
    from lxml import etree

    import re
    if re.match('^0[0-9]{6}$', inetref):
        movie = Movie.fromIMDB(inetref)
    else:
        movie = Movie(inetref)

    tree = etree.XML(u'<metadata></metadata>')
    mapping = [['runtime',      'runtime'],     ['title',       'originaltitle'],
               ['releasedate',  'releasedate'], ['tagline',     'tagline'],
               ['description',  'overview'],    ['homepage',    'homepage'],
               ['userrating',   'userrating'],  ['popularity',  'popularity'],
               ['budget',       'budget'],      ['revenue',     'revenue']]
    m = VideoMetadata()
    for i,j in mapping:
        try:
            if getattr(movie, j):
                setattr(m, i, getattr(movie, j))
        except TMDBRequestInvalid:
            sys.stdout.write(etree.tostring(tree, encoding='UTF-8', pretty_print=True,
                                            xml_declaration=True))
            sys.exit()

    if movie.title:
        m.title = movie.title

    releases = movie.releases.items()

    if opts.country:
        try:
            # resort releases with selected country at top to ensure it
            # is selected by the metadata libraries
            index = zip(*releases)[0].index(opts.country)
            releases.insert(0, releases.pop(index))
        except IndexError, ValueError:
            pass
        else:
            m.releasedate = releases[0][1].releasedate
Exemple #2
0
def buildSingle(inetref, opts):
    from MythTV.tmdb3.tmdb_exceptions import TMDBRequestInvalid
    from MythTV.tmdb3 import Movie
    from MythTV import VideoMetadata
    from lxml import etree

    import re
    if re.match('^0[0-9]{6}$', inetref):
        movie = Movie.fromIMDB(inetref)
    else:
        movie = Movie(inetref)

    tree = etree.XML(u'<metadata></metadata>')
    mapping = [['runtime', 'runtime'], ['title', 'originaltitle'],
               ['releasedate', 'releasedate'], ['tagline', 'tagline'],
               ['description', 'overview'], ['homepage', 'homepage'],
               ['userrating', 'userrating'], ['popularity', 'popularity'],
               ['budget', 'budget'], ['revenue', 'revenue']]
    m = VideoMetadata()
    for i, j in mapping:
        try:
            if getattr(movie, j):
                setattr(m, i, getattr(movie, j))
        except TMDBRequestInvalid:
            print_etree(
                etree.tostring(tree,
                               encoding='UTF-8',
                               pretty_print=True,
                               xml_declaration=True))
            sys.exit()

    if movie.title:
        m.title = movie.title

    releases = list(movie.releases.items())

    # get the release date for the wanted country
    # TODO if that is not part of the reply use the primary release date (Primary=true)
    # if that is not part of the reply use whatever release date is first in list
    # if there is not a single release date in the reply, then leave it empty
    if len(releases) > 0:
        if opts.country:
            # resort releases with selected country at top to ensure it
            # is selected by the metadata libraries
            r = list(zip(*releases))
            if opts.country in r[0]:
                index = r[0].index(opts.country)
                releases.insert(0, releases.pop(index))

        m.releasedate = releases[0][1].releasedate

    m.inetref = str(movie.id)
    if movie.collection:
        m.collectionref = str(movie.collection.id)
    if m.releasedate:
        m.year = m.releasedate.year
    for country, release in releases:
        if release.certification:
            m.certifications[country] = release.certification
    for genre in movie.genres:
        m.categories.append(genre.name)
    for studio in movie.studios:
        m.studios.append(studio.name)
    for country in movie.countries:
        m.countries.append(country.name)
    for cast in movie.cast:
        d = {
            'name': cast.name,
            'character': cast.character,
            'department': 'Actors',
            'job': 'Actor',
            'url': 'http://www.themoviedb.org/people/{0}'.format(cast.id)
        }
        if cast.profile: d['thumb'] = cast.profile.geturl()
        m.people.append(d)
    for crew in movie.crew:
        d = {
            'name': crew.name,
            'job': crew.job,
            'department': crew.department,
            'url': 'http://www.themoviedb.org/people/{0}'.format(crew.id)
        }
        if crew.profile: d['thumb'] = crew.profile.geturl()
        m.people.append(d)
    for backdrop in movie.backdrops:
        m.images.append({
            'type': 'fanart',
            'url': backdrop.geturl(),
            'thumb': backdrop.geturl(backdrop.sizes()[0]),
            'height': str(backdrop.height),
            'width': str(backdrop.width)
        })
    for poster in movie.posters:
        m.images.append({
            'type': 'coverart',
            'url': poster.geturl(),
            'thumb': poster.geturl(poster.sizes()[0]),
            'height': str(poster.height),
            'width': str(poster.width)
        })
    tree.append(m.toXML())
    print_etree(
        etree.tostring(tree,
                       encoding='UTF-8',
                       pretty_print=True,
                       xml_declaration=True))
    sys.exit()
Exemple #3
0
def buildSingle(inetref, opts):
    from MythTV.tmdb3.tmdb_exceptions import TMDBRequestInvalid
    from MythTV.tmdb3 import Movie, get_locale
    from MythTV import VideoMetadata
    from lxml import etree

    import locale as py_locale
    import re

    if re.match('^0[0-9]{6}$', inetref):
        movie = Movie.fromIMDB(inetref)
    else:
        movie = Movie(inetref)

    tree = etree.XML(u'<metadata></metadata>')
    mapping = [['runtime', 'runtime'], ['title', 'originaltitle'],
               ['releasedate', 'releasedate'], ['tagline', 'tagline'],
               ['description', 'overview'], ['homepage', 'homepage'],
               ['userrating', 'userrating'], ['popularity', 'popularity'],
               ['budget', 'budget'], ['revenue', 'revenue']]
    m = VideoMetadata()
    for i, j in mapping:
        try:
            if getattr(movie, j):
                setattr(m, i, getattr(movie, j))
        except TMDBRequestInvalid:
            return etree.tostring(tree,
                                  encoding='UTF-8',
                                  pretty_print=True,
                                  xml_declaration=True)

    if movie.title:
        m.title = movie.title

    releases = list(movie.releases.items())

    # get the release date for the wanted country
    # TODO if that is not part of the reply use the primary release date (Primary=true)
    # if that is not part of the reply use whatever release date is first in list
    # if there is not a single release date in the reply, then leave it empty
    if len(releases) > 0:
        if opts.country:
            # resort releases with selected country at top to ensure it
            # is selected by the metadata libraries
            r = list(zip(*releases))
            if opts.country in r[0]:
                index = r[0].index(opts.country)
                releases.insert(0, releases.pop(index))

        m.releasedate = releases[0][1].releasedate

    m.inetref = str(movie.id)
    if movie.collection:
        m.collectionref = str(movie.collection.id)
    if m.releasedate:
        m.year = m.releasedate.year
    for country, release in releases:
        if release.certification:
            m.certifications[country] = release.certification
    for genre in movie.genres:
        m.categories.append(genre.name)
    for studio in movie.studios:
        m.studios.append(studio.name)
    for country in movie.countries:
        m.countries.append(country.name)
    for cast in movie.cast:
        d = {
            'name': cast.name,
            'character': cast.character,
            'department': 'Actors',
            'job': 'Actor',
            'url': 'http://www.themoviedb.org/people/{0}'.format(cast.id)
        }
        if cast.profile: d['thumb'] = cast.profile.geturl()
        m.people.append(d)
    for crew in movie.crew:
        d = {
            'name': crew.name,
            'job': crew.job,
            'department': crew.department,
            'url': 'http://www.themoviedb.org/people/{0}'.format(crew.id)
        }
        if crew.profile: d['thumb'] = crew.profile.geturl()
        m.people.append(d)
    for backdrop in movie.backdrops:
        m.images.append({
            'type': 'fanart',
            'url': backdrop.geturl(),
            'thumb': backdrop.geturl(backdrop.sizes()[0]),
            'height': str(backdrop.height),
            'width': str(backdrop.width)
        })

    # tmdb already sorts the posters by language
    # if no poster of given language was found,
    # try to sort by system language and then by language "en"
    system_language = py_locale.getdefaultlocale()[0].split("_")[0]
    locale_language = get_locale().language
    if opts.debug:
        print("system_language : ", system_language)
        print("locale_language : ", locale_language)

    loc_posters = movie.posters
    if loc_posters[0].language != locale_language \
                    and locale_language != system_language:
        if opts.debug:
            print(
                "1: No poster found for language '%s', trying to sort posters by '%s' :"
                % (locale_language, system_language))
        loc_posters = sorted(movie.posters,
                             key=lambda x: x.language == system_language,
                             reverse=True)

    if loc_posters[0].language != system_language \
                    and loc_posters[0].language != locale_language:
        if opts.debug:
            print(
                "2: No poster found for language '%s', trying to sort posters by '%s' :"
                % (system_language, "en"))
        loc_posters = sorted(movie.posters,
                             key=lambda x: x.language == "en",
                             reverse=True)

    for poster in loc_posters:
        if opts.debug:
            print("Poster : ", poster.language, " | ", poster.userrating,
                  "\t | ", poster.geturl())
        m.images.append({
            'type': 'coverart',
            'url': poster.geturl(),
            'thumb': poster.geturl(poster.sizes()[0]),
            'height': str(poster.height),
            'width': str(poster.width)
        })

    tree.append(m.toXML())
    return etree.tostring(tree,
                          encoding='UTF-8',
                          pretty_print=True,
                          xml_declaration=True)
Exemple #4
0
def buildSingle(inetref, opts):
    from MythTV.tmdb3 import Movie
    from MythTV import VideoMetadata
    from lxml import etree

    import re
    if re.match('^0[0-9]{6}$', inetref):
        movie = Movie.fromIMDB(inetref)
    else:
        movie = Movie(inetref)

    tree = etree.XML(u'<metadata></metadata>')
    mapping = [['runtime',      'runtime'],     ['title',       'originaltitle'],
               ['releasedate',  'releasedate'], ['tagline',     'tagline'],
               ['description',  'overview'],    ['homepage',    'homepage'],
               ['userrating',   'userrating'],  ['popularity',  'popularity'],
               ['budget',       'budget'],      ['revenue',     'revenue']]
    m = VideoMetadata()
    for i,j in mapping:
        if getattr(movie, j):
            setattr(m, i, getattr(movie, j))

    if movie.title:
        m.title = movie.title

    releases = movie.releases.items()

    if opts.country:
        try:
            # resort releases with selected country at top to ensure it
            # is selected by the metadata libraries
            index = zip(*releases)[0].index(opts.country)
            releases.insert(0, releases.pop(index))
        except ValueError:
            pass
        else:
            m.releasedate = releases[0][1].releasedate

    m.inetref = str(movie.id)
    if movie.collection:
        m.collectionref = str(movie.collection.id)
    if movie.releasedate:
        m.year = movie.releasedate.year
    for country, release in releases:
        if release.certification:
            m.certifications[country] = release.certification
    for genre in movie.genres:
        m.categories.append(genre.name)
    for studio in movie.studios:
        m.studios.append(studio.name)
    for country in movie.countries:
        m.countries.append(country.name)
    for cast in movie.cast:
        d = {'name':cast.name, 'character':cast.character, 'department':'Actors',
             'job':'Actor', 'url':'http://www.themoviedb.org/people/{0}'.format(cast.id)}
        if cast.profile: d['thumb'] = cast.profile.geturl()
        m.people.append(d)
    for crew in movie.crew:
        d = {'name':crew.name, 'job':crew.job, 'department':crew.department,
             'url':'http://www.themoviedb.org/people/{0}'.format(crew.id)}
        if crew.profile: d['thumb'] = crew.profile.geturl()
        m.people.append(d)
    for backdrop in movie.backdrops:
        m.images.append({'type':'fanart', 'url':backdrop.geturl(),
                        'thumb':backdrop.geturl(backdrop.sizes()[0]),
                        'height':str(backdrop.height),
                        'width':str(backdrop.width)})
    for poster in movie.posters:
        m.images.append({'type':'coverart', 'url':poster.geturl(),
                        'thumb':poster.geturl(poster.sizes()[0]),
                        'height':str(poster.height),
                        'width':str(poster.width)})
    tree.append(m.toXML())
    sys.stdout.write(etree.tostring(tree, encoding='UTF-8', pretty_print=True,
                                    xml_declaration=True))
    sys.exit()
Exemple #5
0
def buildSingle(inetref, opts):
    from MythTV.tmdb3 import Movie
    from MythTV import VideoMetadata
    from lxml import etree

    import re

    if re.match("^0[0-9]{6}$", inetref):
        movie = Movie.fromIMDB(inetref)
    else:
        movie = Movie(inetref)

    tree = etree.XML(u"<metadata></metadata>")
    mapping = [
        ["runtime", "runtime"],
        ["title", "originaltitle"],
        ["releasedate", "releasedate"],
        ["tagline", "tagline"],
        ["description", "overview"],
        ["homepage", "homepage"],
        ["userrating", "userrating"],
        ["popularity", "popularity"],
        ["budget", "budget"],
        ["revenue", "revenue"],
    ]
    m = VideoMetadata()
    for i, j in mapping:
        if getattr(movie, j):
            setattr(m, i, getattr(movie, j))

    if movie.title:
        m.title = movie.title

    releases = movie.releases.items()

    if opts.country:
        try:
            # resort releases with selected country at top to ensure it
            # is selected by the metadata libraries
            index = zip(*releases)[0].index(opts.country)
            releases.insert(0, releases.pop(index))
        except ValueError:
            pass
        else:
            m.releasedate = releases[0][1].releasedate

    m.inetref = str(movie.id)
    if movie.collection:
        m.collectionref = str(movie.collection.id)
    if movie.releasedate:
        m.year = movie.releasedate.year
    for country, release in releases:
        if release.certification:
            m.certifications[country] = release.certification
    for genre in movie.genres:
        m.categories.append(genre.name)
    for studio in movie.studios:
        m.studios.append(studio.name)
    for country in movie.countries:
        m.countries.append(country.name)
    for cast in movie.cast:
        d = {
            "name": cast.name,
            "character": cast.character,
            "department": "Actors",
            "job": "Actor",
            "url": "http://www.themoviedb.org/people/{0}".format(cast.id),
        }
        if cast.profile:
            d["thumb"] = cast.profile.geturl()
        m.people.append(d)
    for crew in movie.crew:
        d = {
            "name": crew.name,
            "job": crew.job,
            "department": crew.department,
            "url": "http://www.themoviedb.org/people/{0}".format(crew.id),
        }
        if crew.profile:
            d["thumb"] = crew.profile.geturl()
        m.people.append(d)
    for backdrop in movie.backdrops:
        m.images.append({"type": "fanart", "url": backdrop.geturl(), "thumb": backdrop.geturl(backdrop.sizes()[0])})
    for poster in movie.posters:
        m.images.append({"type": "coverart", "url": poster.geturl(), "thumb": poster.geturl(poster.sizes()[0])})
    tree.append(m.toXML())
    sys.stdout.write(etree.tostring(tree, encoding="UTF-8", pretty_print=True, xml_declaration=True))
    sys.exit()
Exemple #6
0
def buildSingle(inetref, opts):
    from MythTV.tmdb3.tmdb_exceptions import TMDBRequestInvalid
    from MythTV.tmdb3 import Movie, ReleaseType, get_locale
    from MythTV import VideoMetadata
    from lxml import etree

    import locale as py_locale
    import re

    if re.match('^0[0-9]{6}$', inetref):
        movie = Movie.fromIMDB(inetref)
    else:
        movie = Movie(inetref)

    tree = etree.XML('<metadata></metadata>')
    mapping = [['runtime', 'runtime'], ['title', 'originaltitle'],
               ['releasedate', 'releasedate'], ['tagline', 'tagline'],
               ['description', 'overview'], ['homepage', 'homepage'],
               ['userrating', 'userrating'], ['popularity', 'popularity'],
               ['budget', 'budget'], ['revenue', 'revenue']]
    m = VideoMetadata()
    for i, j in mapping:
        try:
            if getattr(movie, j):
                setattr(m, i, getattr(movie, j))
        except TMDBRequestInvalid:
            return etree.tostring(tree,
                                  encoding='UTF-8',
                                  pretty_print=True,
                                  xml_declaration=True)

    if movie.title:
        m.title = movie.title

    if movie.releasedate:
        m.releasedate = movie.releasedate

    releases = list(movie.cert_releases.items())

    if len(releases) > 0:
        if opts.country:
            # resort releases with selected country at top to ensure it
            # is selected by the metadata libraries
            r = list(zip(*releases))
            if opts.country in r[0]:
                index = r[0].index(opts.country)
                releases.insert(0, releases.pop(index))
                r_dates_country = releases[0][1].cert_release_dates
                r_types_country = [x.releasetype for x in r_dates_country]
                # from the mailing list:
                # https://www.themoviedb.org/talk/585ad032925141724d0514f4
                # sort order for release dates: 2, 3, 1, min (4 ,5, 6)
                sorted_dates = []
                for rt in [
                        ReleaseType.Theatrical_limited,  # 2
                        ReleaseType.Theatrical,  # 3
                        ReleaseType.Premiere,  # 1
                        ReleaseType.Digital,  # 4
                        ReleaseType.Physical,  # 5
                        ReleaseType.TV
                ]:  # 6
                    if rt in r_types_country:
                        r_index = r_types_country.index(rt)
                        sorted_dates.append(
                            r_dates_country[r_index].releasedate)
                        if rt < ReleaseType.Digital:
                            break
                if len(sorted_dates) > 0:
                    m.releasedate = min(sorted_dates)

    m.inetref = str(movie.id)
    if movie.collection:
        m.collectionref = str(movie.collection.id)
    if m.releasedate:
        m.year = m.releasedate.year
    for country, releaseitem in releases:
        if releaseitem.cert_release_dates[0].certification:
            m.certifications[country] = releaseitem.cert_release_dates[
                0].certification
    for genre in movie.genres:
        m.categories.append(genre.name)
    for studio in movie.studios:
        m.studios.append(studio.name)
    for country in movie.countries:
        m.countries.append(country.name)
    for cast in movie.cast:
        d = {
            'name': cast.name,
            'character': cast.character,
            'department': 'Actors',
            'job': 'Actor',
            'url': 'http://www.themoviedb.org/people/{0}'.format(cast.id)
        }
        if cast.profile: d['thumb'] = cast.profile.geturl()
        m.people.append(d)
    for crew in movie.crew:
        d = {
            'name': crew.name,
            'job': crew.job,
            'department': crew.department,
            'url': 'http://www.themoviedb.org/people/{0}'.format(crew.id)
        }
        if crew.profile: d['thumb'] = crew.profile.geturl()
        m.people.append(d)
    for backdrop in movie.backdrops:
        m.images.append({
            'type': 'fanart',
            'url': backdrop.geturl(),
            'thumb': backdrop.geturl(backdrop.sizes()[0]),
            'height': str(backdrop.height),
            'width': str(backdrop.width)
        })

    # tmdb already sorts the posters by language
    # if no poster of given language was found,
    # try to sort by system language and then by language "en"
    system_language = py_locale.getdefaultlocale()[0].split("_")[0]
    system_country = py_locale.getdefaultlocale()[0].split("_")[1]
    locale_language = get_locale().language
    locale_country = get_locale().country
    if opts.debug:
        print("system_language : ", system_language)
        print("locale_language : ", locale_language)
        print("system_country  : ", system_country)
        print("locale_country  : ", locale_country)

    loc_posters = movie.posters
    if len(loc_posters) and loc_posters[0].language != locale_language \
                    and locale_language != system_language:
        if opts.debug:
            print(
                "1: No poster found for language '%s', trying to sort posters by '%s' :"
                % (locale_language, system_language))
        loc_posters = sorted(movie.posters,
                             key=lambda x: x.language == system_language,
                             reverse=True)

    if len(loc_posters) and loc_posters[0].language != system_language \
                    and loc_posters[0].language != locale_language:
        if opts.debug:
            print(
                "2: No poster found for language '%s', trying to sort posters by '%s' :"
                % (system_language, "en"))
        loc_posters = sorted(movie.posters,
                             key=lambda x: x.language == "en",
                             reverse=True)

    for poster in loc_posters:
        if opts.debug:
            print("Poster : ", poster.language, " | ", poster.userrating,
                  "\t | ", poster.geturl())
        m.images.append({
            'type': 'coverart',
            'url': poster.geturl(),
            'thumb': poster.geturl(poster.sizes()[0]),
            'height': str(poster.height),
            'width': str(poster.width)
        })

    tree.append(m.toXML())
    return etree.tostring(tree,
                          encoding='UTF-8',
                          pretty_print=True,
                          xml_declaration=True)