class test_Dataheap_Video_001(unittest.TestCase): """Test class 'Videos' from dataheap. """ @classmethod def setUpClass(cls): # get the global test environment global TestEnv cls.testenv = TestEnv def setUp(self): self.mydb = MythDB() def test_Dataheap_Video_001_getHash_01(self): """Test 'getHash' method from MythTV.Video using 'searchVideos'. """ vids = self.mydb.searchVideos(title=self.testenv['VIDTITLE'], cast=self.testenv['VIDCAST']) vid = next(vids) #print("%s : %s" %(vid.title, type(vid.title))) self.assertTrue(isinstance(vid, Video)) vid_hash = vid.getHash() # check if retval is hexadecimal: hex_set = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' } self.assertTrue(set(vid_hash.lower()).issubset(hex_set)) # test '__repr__' and '__str__' print() print(repr(vid)) print(str(vid))
class test_Methodheap_MythDB_010(unittest.TestCase): """Test method 'searchVideos' from MythTV.MythDB(). """ @classmethod def setUpClass(cls): # get the global test environment global TestEnv cls.testenv = TestEnv def setUp(self): self.mydb = MythDB() def test_Methodheap_MythDB_010_searchVideos_01(self): """Test 'searchVideos' method from MythTV.MythDB() using 'title' and 'cast'. """ vids = self.mydb.searchVideos( title = self.testenv['VIDTITLE'] , cast = self.testenv['VIDCAST'] ) vid = next(vids) self.assertTrue(isinstance(vid, Video))
def main(): parser = OptionParser(usage="usage: option [option] [option]") maintenancegroup = OptionGroup( parser, "Maintenance", "These options can be used to perform DB cleanup.") maintenancegroup.add_option( "--dedup", action="store_true", default=False, dest="dedup", help="checks for duplicate entries in the Video database") maintenancegroup.add_option("--check_orphans", action="store_true", default=False, dest="check_orphans", help="checks for orphaned DB entries in Video") parser.add_option_group(maintenancegroup) actiongroup = OptionGroup(parser, "Meta Updates", "This option updates Video Meta Data") actiongroup.add_option('--update', action='store_true', default=False, dest='update', help='Updates the video meta data on each entry') parser.add_option_group(actiongroup) othergroup = OptionGroup(parser, 'Other Options', "These options allow for additional controls") othergroup.add_option( '--folder', action='store', type='string', dest='folder', help='Limits actions to Videos in a specified folder,\ example "Movies" would limit to any filename \ starting with Movies/some_video_file.mpg') othergroup.add_option( '--step', action="store_true", default=False, dest='step', help='Steps through each action to allow evaluation of \ process') parser.add_option_group(othergroup) opts, args = parser.parse_args() # if a manual channel and time entry then setup the export with opts # sys.exit(1) # setup the connection to the DB db = MythDB() be = MythBE() #Setup a scanner for all videos in the DB videos = db.searchVideos() # setup a Video object to work with 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 elif len(results) == 0: print 'No MetaData to import for: ' + item.title + '\n'
class test_Dataheap_Video_004(unittest.TestCase): """Test creation of a Video and writing/reading to the videocategory table. This test uses hardcoded values from the file '.testenv'. """ @classmethod def setUpClass(cls): # get the global test environment global TestEnv cls.testenv = TestEnv def setUp(self): with add_log_flags(): self.mydb = MythDB() def tearDown(self): if os.path.exists('/tmp/my_logfile'): os.remove('/tmp/my_logfile') def test_Dataheap_Video_004_01(self): """Test creation of a Video and writing/reading to the videocategory table. This test assumes, that there are no entries in the videocategory table! All entries in that table will be deleted! """ class VideoCategory(DBDataWrite): """ VideoCategory(data=None, db=None) --> VideoCategory object to database table 'videocategory', data is a `videocategory` string. - get information about the table: $ mysql -h <master-backend-ip> -u mythtv -p<password-from-config.xml> mythconverg MariaDB [mythconverg]> describe videocategory; +-------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+----------------+ | intid | int(10) | NO | PRI | NULL | auto_increment | | category | varchar(128)| NO | | | | +-------------+-------------+------+-----+---------+----------------+ 2 rows in set (0.00 sec) """ _table = 'videocategory' _key = ['category'] _defaults = {'category': ''} ### end class VideoCategory title = u"Le Dernier Métro" filename = title + u".mkv" vid = Video(db=self.mydb).create({ 'title': title, 'filename': filename, 'host': self.mydb.getMasterBackend() }) vid.category = u"python_test" vid.update() # find this video and check it vids = self.mydb.searchVideos(title=title) vid_r = next(vids) # print(vid_r.category) self.assertEqual(vid.category, vid_r.category) print(repr(vid_r)) print(str(vid_r)) # delete the video previously created vid.delete() # delete the previously assigned category vid_category = VideoCategory(u"python_test", db=self.mydb) vid_category.delete()
class test_Dataheap_Video_003(unittest.TestCase): """Test class 'Videos' from dataheap. """ @classmethod def setUpClass(cls): # get the global test environment global TestEnv cls.testenv = TestEnv def setUp(self): with add_log_flags(): self.mydb = MythDB() def test_Dataheap_Video_003_fromFilename_01(self): """Test 'fromFilename' classmethod from MythTV.Video. According wiki, this "Creates a new object with initial data parsed from the filename. Object is not stored to the database." Remark: What to do with this 'new object' ? """ path = self.testenv['VIDPATH_DE'] cast = self.testenv['VIDCAST_DE'] vid = Video.fromFilename(os.path.basename(path), db=self.mydb) self.assertEqual(os.path.basename(path), vid.filename) def test_Dataheap_Video_003_exportMetadata_01(self): """Test 'exportMetadata' method from MythTV.Video. """ path = self.testenv['VIDPATH_DE'] cast = self.testenv['VIDCAST_DE'] title = self.testenv['VIDTITLE_DE'] vids = self.mydb.searchVideos(title=title, cast=cast) vid = next(vids) self.assertEqual(path, vid.filename) # get the metadata of the video mtdata = vid.exportMetadata() self.assertTrue(isinstance(mtdata, VideoMetadata)) # save year of video for later use year_saved = mtdata.year # python 3 does not have a 'long' type self.assertTrue((isinstance(year_saved, int)) or (isinstance(year_saved, long))) # increment year mtdata.year = year_saved + 1 # write back metadata, allow overwriting existing values vid.importMetadata(mtdata, overwrite=True) # check year self.assertEqual(vid.year, year_saved + 1) # restore old year vid.year = year_saved vid.update() # check again year mtnew = vid.exportMetadata() self.assertEqual(mtnew.year, year_saved) def test_Dataheap_Video_003_importMetadata_01(self): """Test 'exportMetadata' method from MythTV.Video. """ path = self.testenv['VIDPATH_DE'] cast = self.testenv['VIDCAST_DE'] title = self.testenv['VIDTITLE_DE'] vids = self.mydb.searchVideos(title=title, cast=cast) vid = next(vids) self.assertEqual(path, vid.filename) # get the metadata of the video mtdata = vid.exportMetadata() self.assertTrue(isinstance(mtdata, VideoMetadata)) ### print(mtdata.keys()) # save plot of video for later use # Note: VideoMetadata.description gets translated to Video.plot plot_saved = mtdata.description # alter plot mtdata.description = mtdata.description + u"test_Dataheap_Video_003_importMetadata_01" # write back metadata, allow overwriting existing values vid.importMetadata(mtdata, overwrite=True) # check plotr self.assertEqual(vid.plot, mtdata.description) # restore old plot vid.plot = plot_saved vid.update() # check again plot mtnew = vid.exportMetadata() self.assertEqual(mtnew.description, plot_saved)
class test_Dataheap_VideoGrabber_001(unittest.TestCase): """Test class 'VideoGrabber' from dataheap. """ @classmethod def setUpClass(cls): # get the global test environment global TestEnv cls.testenv = TestEnv global INSTALL_PREFIX cls.INSTALL_PREFIX = INSTALL_PREFIX def setUp(self): if (self.INSTALL_PREFIX != os.getcwd()): self.fail("Unable to rewrite 'INSTALL_PREFIX' in static.py!") def tearDown(self): if os.path.exists("/tmp/my_logfile"): os.remove("/tmp/my_logfile") if os.path.exists("/tmp/details.xml"): os.remove("/tmp/details.xml") 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) 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 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)