Exemple #1
0
    def test_Dataheap_VideoGrabber_002_importMetadata_02(self):
        """Test 'VideoGrabber.grabInetref' method and 'Video.importMetadata'
           methods using predefined values. See 'mythvidexport.py' as well.
           See MythtTV trac tickets #12243 and #12245.
           Note: Use a TV series with season and episode.
        """
        from MythTV import MythDB, Video, VideoGrabber

        with add_log_flags():
            self.mydb =  MythDB()

            alf_metadata = { u'title'    : u'Alf',
                             u'subtitle' : u'Wedding Bell Blues',
                             u'season'   : 2,
                             u'episode'  : 4,
                             u'inetref'  : '78020'}

            grab = VideoGrabber('TV', lang='en', db=self.mydb)
            metadata = grab.grabInetref( alf_metadata['inetref'],
                                         alf_metadata['season'],
                                         alf_metadata['episode'])

            # print(metadata.collectionref)   # ---> '78020'
            self.assertEqual(metadata.collectionref, alf_metadata[u'inetref'])

            # run the grabber again, but based on a 'VideoMetadata' object
            new_metadata = grab.grabInetref(metadata)
            # check if collected metadata are the equal
            self.assertEqual(new_metadata, metadata)
Exemple #2
0
    def get_meta(self):
        self.vid.hostname = self.db.gethostname()

        if self.rec.subtitle:  # subtitle exists, assume tv show
            self.type = 'TV'
            self.log(self.log.IMPORTANT, 'Attempting TV export.')
            if self.opts.listingonly:
                self.log(self.log.IMPORTANT, 'Forcing listing data only.')
                self.get_generic(False)
                return
            grab = VideoGrabber(self.type)
            match = grab.sortedSearch(self.rec.title, self.rec.subtitle)
        else:  # assume movie
            self.type = 'MOVIE'
            self.log(self.log.IMPORTANT, 'Attempting Movie export.')
            if self.opts.listingonly:
                self.log(self.log.IMPORTANT, 'Forcing listing data only.')
                self.get_generic(False)
                return
            grab = VideoGrabber(self.type)
            match = grab.sortedSearch(self.rec.title)

        if len(match) == 0:
            # no match found
            self.log(self.log.IMPORTANT, 'Falling back to generic export.')
            self.get_generic()
        elif (len(match) > 1) & (match[0].levenshtein > 0):
            # multiple matches found, and closest is not exact
            self.vid.delete()
            raise MythError('Multiple metadata matches found: '\
                                                   + self.rec.title)
        else:
            self.log(self.log.IMPORTANT, 'Importing content from', match[0].inetref)
            self.vid.importMetadata(grab.grabInetref(match[0]))
Exemple #3
0
    def test_Dataheap_VideoGrabber_001_sortedSearch_01(self):
        """Test 'sortedSearch' method from MythTV.VideoGrabber
           using predefined  values.
        """
        from MythTV import MythDB, RecordedArtwork, Video, VideoGrabber

        with add_log_flags():
            self.mydb =  MythDB()

            title      = self.testenv['VIDTITLE_DE']
            cast       = self.testenv['VIDCAST_DE']
            inetrefstr = self.testenv['VIDINETREF_DE']
            lang       = self.testenv['VIDLANGUAGE_DE']

            # remove grabber from inetref:
            try:
                inetref = inetrefstr.split('_')[-1]
            except IndexError:
                inetref = inetrefstr

            grab = VideoGrabber("Movie", lang=lang, db=self.mydb)
            metadatalist = grab.sortedSearch(title, subtitle=None, tolerance=2)
            inetref_found = False
            for m in metadatalist:
                if (m.inetref == inetref):
                    inetref_found = True
                    break
            self.assertTrue(inetref_found)
Exemple #4
0
    def test_Dataheap_VideoGrabber_001_search_01(self):
        """Test 'search' method from MythTV.VideoGrabber
           using 'searchVideos'.
        """
        from MythTV import MythDB, RecordedArtwork, Video, VideoGrabber

        with add_log_flags():
            self.mydb =  MythDB()

            title      = self.testenv['VIDTITLE']
            cast       = self.testenv['VIDCAST']
            inetrefstr = self.testenv['VIDINETREF']
            lang       = self.testenv['VIDLANGUAGE']

            # remove grabber from inetref:
            try:
                inetref = inetrefstr.split('_')[-1]
            except IndexError:
                inetref = inetrefstr

            vids = self.mydb.searchVideos( title = title )
            vid = next(vids)
            # print("%s : %s" %(vid.title, type(vid.title)))
            self.assertTrue(isinstance(vid, Video))
            grab = VideoGrabber("Movie", lang = lang, db = self.mydb)
            metadatalistgen = grab.search(vid.title, subtitle=None, tolerance=1)
            mlist = list(metadatalistgen)
            inetref_found = False
            for m in mlist:
                if (m.inetref == inetref):
                    inetref_found = True
                    break
            self.assertTrue(inetref_found)
    def get_meta(self):
        self.vid.hostname = self.db.gethostname()
        if self.rec.inetref:
            # good data is available, use it
            if self.rec.season is not None:
                self.log(self.log.GENERAL, self.log.INFO,
                        'Performing TV export with local data.')
                self.type = 'TV'
            else:
                self.log(self.log.GENERAL, self.log.INFO,
                        'Performing Movie export with local data.')
                self.type = 'MOVIE'
            metadata = self.rec.exportMetadata()
        elif self.opts.listingonly:
            # force use of local data
            if self.rec.subtitle:
                self.log(self.log.GENERAL, self.log.INFO,
                        'Forcing TV export with local data.')
                self.type = 'TV'
            else:
                self.log(self.log.GENERAL, self.log.INFO,
                        'Forcing Movie export with local data.')
                self.type = 'MOVIE'
            metadata = self.rec.exportMetadata()
        else:
            if self.rec.subtitle:
                # subtitle exists, assume tv show
                self.type = 'TV'
                self.log(self.log.GENERAL, self.log.INFO,
                        'Attempting TV export.')
                grab = VideoGrabber(self.type)
                match = grab.sortedSearch(self.rec.title, self.rec.subtitle)
            else:                   # assume movie
                self.type = 'MOVIE'
                self.log(self.log.GENERAL, self.log.INFO,
                        'Attempting Movie export.')
                grab = VideoGrabber(self.type)
                match = grab.sortedSearch(self.rec.title)

            if len(match) == 0:
                # no match found
                self.log(self.log.GENERAL, self.log.INFO,
                        'Falling back to generic export.')
                self.type = 'GENERIC'
                metadata = self.rec.exportMetadata()
            elif (len(match) > 1) & (match[0].levenshtein > 0):
                # multiple matches found, and closest is not exact
                self.vid.delete()
                raise MythError('Multiple metadata matches found: '\
                                                   +self.rec.title)
            else:
                self.log(self.log.GENERAL, self.log.INFO,
                        'Importing content from', match[0].inetref)
                metadata = grab.grabInetref(match[0])

        self.vid.importMetadata(metadata)
        self.log(self.log.GENERAL, self.log.INFO, 'Import complete')
Exemple #6
0
    def test_Dataheap_VideoGrabber_001_grabInetref_01(self):
        """Test 'grabInetref' and 'toXML' methods from MythTV.VideoGrabber
           using predefined  values.
        """
        from MythTV import MythDB, RecordedArtwork, Video, VideoGrabber

        with add_log_flags():
            self.mydb =  MythDB()

            title      = self.testenv['VIDTITLE_DE']
            cast       = self.testenv['VIDCAST_DE']
            inetrefstr = self.testenv['VIDINETREF_DE']
            lang       = self.testenv['VIDLANGUAGE_DE']

            # remove grabber from inetref:
            try:
                inetref = inetrefstr.split('_')[-1]
            except IndexError:
                inetref = inetrefstr

            grab = VideoGrabber("Movie", lang=lang, db=self.mydb)
            metadatalist = grab.sortedSearch(title, subtitle=None, tolerance=2)

            details = grab.grabInetref(metadatalist[0].inetref)
            # details has lists of dicts for
            #  'certifications',  'categories', 'countries', 'studios', 'people', 'images'

            names = [n.name for n in details.people]
            self.assertTrue(cast in names)

            tree  = etree.XML(u'<metadata></metadata>')
            tree.append(details.toXML())
            xml_str = etree.tostring ( tree
                                     , pretty_print    = True
                                     , xml_declaration = True
                                     , encoding        = "UTF-8"
                                     , standalone      = "yes"
                                     )
            xml_file  = open("/tmp/details.xml", "wb")
            xml_file.write(xml_str)
            xml_file.close()

            # read xml file and check for cast
            root = etree.parse(r'/tmp/details.xml').getroot()
            cast_found = False
            for name in root.findall('item/people/person'):
                if (name.attrib['name'] == cast):
                    cast_found = True
            self.assertTrue(cast_found)
Exemple #7
0
    def get_meta(self):
        self.vid.hostname = self.db.gethostname()

        if self.rec.subtitle:  # subtitle exists, assume tv show
            self.type = 'TV'
            self.log(self.log.IMPORTANT, 'Attempting TV export.')
            if self.opts.listingonly:
                self.log(self.log.IMPORTANT, 'Forcing listing data only.')
                self.get_generic(False)
                return
            grab = VideoGrabber(self.type)
            match = grab.sortedSearch(self.rec.title, self.rec.subtitle)
        else:  # assume movie
            self.type = 'MOVIE'
            self.log(self.log.IMPORTANT, 'Attempting Movie export.')
            if self.opts.listingonly:
                self.log(self.log.IMPORTANT, 'Forcing listing data only.')
                self.get_generic(False)
                return
            grab = VideoGrabber(self.type)
            match = grab.sortedSearch(self.rec.title)

        if len(match) == 0:
            # no match found
            self.log(self.log.IMPORTANT, 'Falling back to generic export.')
            self.get_generic()
        elif (len(match) > 1) & (match[0].levenshtein > 0):
            # multiple matches found, and closest is not exact
            self.vid.delete()
            raise MythError('Multiple metadata matches found: '\
                                                   +self.rec.title)
        else:
            self.log(self.log.IMPORTANT, 'Importing content from',
                     match[0].inetref)
            self.vid.importMetadata(grab.grabInetref(match[0]))
    def get_meta(self):
        self.vid.hostname = self.db.gethostname()
        if self.rec.inetref:
            # good data is available, use it
            if self.rec.season is not None:
                self.log(self.log.GENERAL, self.log.INFO,
                         'Performing TV export with local data.')
                self.type = 'TV'
            else:
                self.log(self.log.GENERAL, self.log.INFO,
                         'Performing Movie export with local data.')
                self.type = 'MOVIE'
            metadata = self.rec.exportMetadata()
        elif self.opts.listingonly:
            # force use of local data
            if self.rec.subtitle:
                self.log(self.log.GENERAL, self.log.INFO,
                         'Forcing TV export with local data.')
                self.type = 'TV'
            else:
                self.log(self.log.GENERAL, self.log.INFO,
                         'Forcing Movie export with local data.')
                self.type = 'MOVIE'
            metadata = self.rec.exportMetadata()
        else:
            if self.rec.subtitle:
                # subtitle exists, assume tv show
                self.type = 'TV'
                self.log(self.log.GENERAL, self.log.INFO,
                         'Attempting TV export.')
                grab = VideoGrabber(self.type)
                match = grab.sortedSearch(self.rec.title, self.rec.subtitle)
            else:  # assume movie
                self.type = 'MOVIE'
                self.log(self.log.GENERAL, self.log.INFO,
                         'Attempting Movie export.')
                grab = VideoGrabber(self.type)
                match = grab.sortedSearch(self.rec.title)

            if len(match) == 0:
                # no match found
                self.log(self.log.GENERAL, self.log.INFO,
                         'Falling back to generic export.')
                self.type = 'GENERIC'
                metadata = self.rec.exportMetadata()
            elif (len(match) > 1) & (match[0].levenshtein > 0):
                # multiple matches found, and closest is not exact
                self.vid.delete()
                raise MythError('Multiple metadata matches found: '\
                                                   +self.rec.title)
            else:
                self.log(self.log.GENERAL, self.log.INFO,
                         'Importing content from', match[0].inetref)
                metadata = grab.grabInetref(match[0])

        self.vid.importMetadata(metadata)
        self.log(self.log.GENERAL, self.log.INFO, 'Import complete')
Exemple #9
0
    def test_Dataheap_VideoGrabber_002_importMetadata_01(self):
        """Test 'VideoGrabber.grabInetref' method and 'Video.importMetadata'
           methods using predefined values. See 'mythvidexport.py' as well.
           See MythtTV trac tickets #12243 and #12245.
           Note: Use a video with French accents in title and cast.
        """
        from MythTV import MythDB, Video, VideoGrabber

        with add_log_flags():

            title      = u"Le Dernier Métro"
            castlist   = [u"Catherine Deneuve", u"Gérard Depardieu", u"Andréa Ferréol"]
            inetstr    = "tmdb3.py_1716"
            lang       = "fr"
            filename   = title + u".mkv"

            # create a new Video instance
            self.mydb = MythDB()
            vid  = Video(db=self.mydb).create ({'title'   : title,
                                                'filename': filename,
                                                'host'    : self.mydb.getMasterBackend()})
            # grab details from www.themoviedb.org
            grab = VideoGrabber('MOVIE', lang=lang, db=self.mydb)
            metadata = grab.grabInetref(inetstr)
            #print(type(metadata))   -->   <class 'MythTV.system.VideoMetadata'>
            # import metadata into Video instance
            vid.importMetadata(metadata)
            #print(vid.cast[1].cast)   ### --->  Gérard Depardieu
            # create a list of cast members from metadata
            vidcastmembers = [c.cast for c in vid.cast]
            # check for members in cast list
            self.assertTrue(self.is_sublist(castlist, vidcastmembers))
            # delete previously created Video object in database
            vid.delete()
            #print(metadata.inetref)   # --> 1716
            self.assertEqual(metadata.inetref, inetstr.split('_')[-1])
            # run the grabber again, but based on a 'VideoMetadata' object
            new_metadata = grab.grabInetref(metadata)
            # check if collected metadata are the equal
            self.assertEqual(new_metadata, metadata)
    def get_meta(self):
        metadata = self.rec.exportMetadata()
        yrInfo = self.rec.getProgram()
        metadata['year'] = yrInfo.get('year')
        self.vid.importMetadata(metadata)
        if self.type == 'MOVIE':
            grab = VideoGrabber('Movie')
            results = grab.sortedSearch(self.rec.title)
            if len(results) > 0:
                for i in results:
                    if i.year == yrInfo.get(
                            'year') and i.title == self.rec.get('title'):
                        self.vid.importMetadata(i)
                        match = grab.grabInetref(i.get('inetref'))
                        length = len(match.people)
                        for p in range(length - 2):
                            self.vid.cast.add(match.people[p].get('name'))
                        self.vid.director = match.people[length -
                                                         1].get('name')
                        import_info = 'Full MetaData Import complete'
            elif len(results) == 0:
                import_info = 'Listing only MetaData import complete'
        else:
            grab = VideoGrabber('TV')
            results = grab.sortedSearch(self.rec.title, self.rec.subtitle)
            if len(results) > 0:
                for i in results:
                    if i.title == self.rec.get(
                            'title') and i.subtitle == self.rec.get(
                                'subtitle'):
                        self.vid.importMetadata(i)
                        match = grab.grabInetref(grab.grabInetref(i.get('inetref'), \
                                season=i.get('season'),episode=i.get('episode')))
                        length = len(match.people)
                        for p in range(length - 2):
                            self.vid.cast.add(match.people[p].get('name'))
                        self.vid.director = match.people[length -
                                                         1].get('name')
                        import_info = 'Full MetaData Import complete'
            elif len(results) == 0:
                import_info = 'Listing only MetaData import complete'

        self.vid.category = self.rec.get('category')

        self.log(self.log.GENERAL, self.log.INFO, import_info)
    def get_metadata(self):
        """ Get Metadata
        Get the recording metadata.
        """
        self.vid.hostname = self.db.gethostname()
        try:
            if self.rec.inetref:
                # good data is available, use it
                if self.rec.season > 0 or self.rec.episode > 0:
                    self.type = 'TV'
                    grab = VideoGrabber(self.type)
                    metadata = grab.grabInetref(self.rec.inetref, self.rec.season, self.rec.episode)
                else:
                    self.type = 'MOVIE'
                    grab = VideoGrabber(self.type)
                    metadata = grab.grabInetref(self.rec.inetref)
            else:
                if self.rec.subtitle:
                    # subtitle exists, assume tv show
                    self.type = 'TV'
                    grab = VideoGrabber(self.type)
                    match = grab.sortedSearch(self.rec.title, self.rec.subtitle)
                else: # assume movie
                    self.type = 'MOVIE'
                    grab = VideoGrabber(self.type)
                    match = grab.sortedSearch(self.rec.title)

                if len(match) == 0:
                    # no match found
                    metadata = self.rec.exportMetadata()
                elif (len(match) > 1) & (match[0].levenshtein > 0):
                    # multiple matches found, and closest is not exact
                    self.vid.delete()
                    raise ArchiveError('Multiple metadata matches found: '\
                                                       +self.rec.title)
                else:
                    metadata = grab.grabInetref(match[0])
        except (MythError, StopIteration), e:
            self.log.warning('Error Getting Metadata: %r' % e)
            metadata = self.rec.exportMetadata()
    def get_meta(self):
        import_info = 'Listing only MetaData import complete'
        metadata = self.rec.exportMetadata()
        yrInfo = self.rec.getProgram()
        metadata['year'] = yrInfo.get('year')
        self.vid.importMetadata(metadata)
        if self.type == 'MOVIE':
            grab = VideoGrabber('Movie')
            results = grab.sortedSearch(self.rec.title)
            if len(results) > 0:
                for i in results:
                    if i.year == yrInfo.get('year') and i.title == self.rec.get('title'):
                        self.vid.importMetadata(i)
                        match = grab.grabInetref(i.get('inetref'))
                        length = len(match.people)
                        for p in range(length-2):
                            self.vid.cast.add(match.people[p].get('name'))
                        self.vid.director = match.people[length - 1].get('name')
                        import_info = 'Full MetaData Import complete'
        else:
            grab = VideoGrabber('TV')
            results = grab.sortedSearch(self.rec.title, self.rec.subtitle)
            if len(results) > 0:
                for i in results:
                    if  i.title == self.rec.get('title') and i.subtitle == self.rec.get('subtitle'):
                        self.vid.importMetadata(i)
                        match = grab.grabInetref(grab.grabInetref(i.get('inetref'), \
                                season=i.get('season'),episode=i.get('episode')))
                        length = len(match.people)
                        for p in range(length-2):
                            self.vid.cast.add(match.people[p].get('name'))
                        self.vid.director = match.people[length - 1].get('name')
                        import_info = 'Full MetaData Import complete'
            
        
        self.vid.category = self.rec.get('category')

        self.log(self.log.GENERAL, self.log.INFO, import_info)
    def get_Meta(item):

        metadata = item.exportMetadata()

        if not item.filename.startswith('Television'):
            grab = VideoGrabber('Movie')
            if item.get('inetref') != '00000000':
                try:
                    match = grab.grabInetref(item.inetref)
                    item.importMetadata(match)
                    item.plot = match.get('description')
                    item.title = match.get('title')
                    copy_Art(match, item)
                    item.update()
                    return

                except Exception:
                    print 'grabber failed for: ' + str(item.get('inetref'))
                    print 'trying by name instead'

            try:
                results = grab.sortedSearch(item.title)
            except Exception, e:
                print 'grabber failed for: ' + str(item.get('inetref'))
                print e
                return

            if len(results) > 0:
                if len(results) > 1:
                    menu = {}
                    list = 1
                    for each in results:
                        menu[list]= each.title + ', year: ' + str(each.get('year')) \
                                                + ', inetref: ' + str(each.get('inetref'))
                        list = list + 1
                    menu[list] = 'Skip to next video\n\n'
                    print '\n'
                    while True:
                        options = menu.keys()
                        options.sort()
                        for entry in options:
                            print entry, menu[entry]
                        try:
                            selection = input("Please Select: ")
                            if selection in range(1, len(results) + 1):
                                listing = results[selection - 1]
                                break
                            elif selection == len(results) + 1:
                                return
                            else:
                                print "Invalid Selection, try again!\n\n"
                        except Exception:
                            print "Invalid Selection, try again!\n\n"
                else:
                    listing = results[0]

                try:
                    match = grab.grabInetref(listing.get('inetref'))
                    item.importMetadata(match)
                    item.plot = match.get('description')
                    item.title = match.get('title')
                    copy_Art(match, item)
                    item.update()
                    print 'Full MetaData Import complete for: ' + item.title + '\n'

                except Exception, e:
                    print 'grabber failed for: ' + str(item.get('inetref'))
                    print e
                    match = grab.grabInetref(listing.get('inetref'))
                    item.importMetadata(match)
                    item.plot = match.get('description')
                    item.title = match.get('title')
                    copy_Art(match, item)
                    item.update()
                    print 'Full MetaData Import complete for: ' + item.title + '\n'

                except Exception, e:
                    print 'grabber failed for: ' + str(item.get('inetref'))
                    print e

            elif len(results) == 0:
                print 'No MetaData to import for: ' + item.title + '\n'
        else:
            grab = VideoGrabber('TV')
            results = grab.sortedSearch(item.title, item.subtitle)
            if len(results) > 0:
                if len(results) > 1:
                    menu = {}
                    list = 1
                    for each in results:
                        menu[list]= each.title + ' - ' + each.subtitle, \
                                        + ' year: ' + str(each.get('year')) \
                                        + ', inetref: ' + str(each.get('inetref'))
                        list = list + 1
                    menu[list] = 'Skip to next video\n\n'
                    while True:
                        options = menu.keys()
                        options.sort()
                        for entry in options:
Exemple #15
0
mvid = MythVideo()


def format_name(vid):
    # returns a string in the format 'TITLE[ - SEASONxEPISODE][ - SUBTITLE]'
    s = vid.title
    if vid.season:
        s += ' - %dx%02d' % (vid.season, vid.episode)
    if vid.subtitle:
        s += ' - ' + vid.subtitle
    return s.encode('utf-8', 'replace')


# Load TV Grabber
try:
    TVgrab = VideoGrabber('TV', db=mvid)
except:
    print 'ERROR: Cannot find MythVideo TV grabber'
    sys.exit(-1)

# Load Movie Grabber
try:
    Mgrab = VideoGrabber('Movie', db=mvid)
except:
    print 'ERROR: Cannot find MythVideo Movie grabber'
    sys.exit(-1)

# pull new/old content list
LOG(LOG.GENERAL, 'Performing scan...')
toadd, todel = mvid.scanStorageGroups(False)
Exemple #16
0
LOG = MythLog('MythVideo Scanner', lstr='general')
mvid = MythVideo()

def format_name(vid):
    # returns a string in the format 'TITLE[ - SEASONxEPISODE][ - SUBTITLE]'
    s = vid.title
    if vid.season:
        s += ' - %dx%02d' % (vid.season, vid.episode)
    if vid.subtitle:
        s += ' - '+vid.subtitle
    return s.encode('utf-8', 'replace')

# Load TV Grabber
try:
    TVgrab = VideoGrabber('TV', db=mvid)
except:
    print 'ERROR: Cannot find MythVideo TV grabber'
    sys.exit(-1)

# Load Movie Grabber
try:
    Mgrab = VideoGrabber('Movie', db=mvid)
except:
    print 'ERROR: Cannot find MythVideo Movie grabber'
    sys.exit(-1)

# pull new/old content list
LOG(LOG.GENERAL, 'Performing scan...')
toadd, todel = mvid.scanStorageGroups(False)