Ticket #2734: metadata_scripts_prune.patch
File metadata_scripts_prune.patch, 4.6 KB (added by , 17 years ago) |
---|
-
mythvideo/scripts/fetch_poster.py
165 165 urls = [] 166 166 for div in divs: 167 167 links = div.findAll('a') 168 168 169 if len(links) > 0: 169 link = links[0] 170 title = link['title'].lower() 171 if title.endswith("poster"): 172 title = title[0:-len(" poster")] 173 if title == search: 174 urls.append(link['href']) 170 for link in links: 171 # Skip the mailto links. 172 spl = link['href'].split(":") 173 if len(spl) > 1: 174 if spl[0].lower() == "mailto": 175 continue 176 title = link['title'].lower() 177 if title.endswith("poster"): 178 title = title[0:-len(" poster")] 179 if title == search: 180 urls.append(link['href']) 175 181 return urls 176 182 177 183 -
mythvideo/scripts/find_meta.py
130 130 db="mythconverg") 131 131 print_verbose("Database connection successful.") 132 132 return True 133 133 134 134 def find_imdb_id_from_text_file(textFile): 135 135 136 136 if os.access(textFile, os.R_OK): … … 164 164 165 165 def cleanup_title(title): 166 166 title = title.replace("_", " ").replace(".", " ") 167 cut_point_strings = ["hdtv", "xvid", "dvd", "proper", "720p" ]167 cut_point_strings = ["hdtv", "xvid", "dvd", "proper", "720p", "limited"] 168 168 lowest_cutpoint = len(title) 169 169 for string in cut_point_strings: 170 170 pos = title.lower().rfind(string) … … 287 287 else: 288 288 return disc 289 289 290 291 290 def save_metadata_to_mythdb(videopath, metadata): 292 291 """ 293 292 Updates the given metadata for the given video path. 294 293 295 294 Detects if the given title is a dvd-rip dir with multiple videos and 296 adds metadata for all the videos separately ,and chains the videos295 adds metadata for all the videos separately and chains the videos 297 296 together. 298 297 """ 299 298 files_str = parse_meta("Files", "", "", metadata) … … 314 313 return 315 314 316 315 return save_video_metadata_to_mythdb(videopath, metadata) 316 317 def prune_mythdb_metadata(): 318 global db 319 c = db.cursor() 320 c.execute(""" 321 SELECT intid, filename 322 FROM videometadata""") 317 323 318 324 row = c.fetchone() 325 while row is not None: 326 intid = row[0] 327 filename = row[1] 328 if not os.path.exists(filename): 329 print_verbose("%s not exist, removing metadata..." % filename) 330 c2 = db.cursor() 331 c2.execute("""DELETE FROM videometadata WHERE intid = %s""", (intid,)) 332 c2.close() 333 row = c.fetchone() 334 c.close() 335 319 336 def mythvideo_metadata_id(videopath): 320 337 """ 321 338 Finds the MythVideo metadata id for the given video path from the MythDB, if any. … … 357 374 return row[0] 358 375 else: 359 376 return None 360 361 377 362 378 def save_video_metadata_to_mythdb(videopath, metadata, child=-1, disc=None): 363 379 """ 364 380 Updates the given metadata for the given video file. … … 515 531 print_verbose("Found existing cover image.") 516 532 return poster_files[0] 517 533 return None 518 519 534 520 535 def save_metadata_to_file(fileName, metadata): 521 536 global overwrite 522 537 … … 775 790 if metadata is not None: 776 791 save_metadata(pathName, metadata_target, metadata) 777 792 778 779 793 def scan_directory(dirName, imdb_id = None): 780 794 global videoExtensions 781 795 dirName = dirName.replace("[", "?").replace("]", "?") … … 890 904 p.add_option('--answer', '-a', action="store", type="string", dest="imdb_id", 891 905 help="Fetch metadata with the given IMDb ID for the path (must be a single path).") 892 906 907 p.add_option('--prune', '-p', action="store_true", default=False, 908 help="Prune metadata of deleted files from MythDB.") 893 909 910 894 911 options, arguments = p.parse_args() 895 912 896 913 if options.version: … … 904 921 dbimport = not options.no_dbimport 905 922 import_from_files = options.fromfiles and dbimport 906 923 metafiles = options.metafiles 924 prune = options.prune 907 925 908 926 if not (metafiles or dbimport): 909 927 print "You must define writing to either MythDB import (-d) or metadata files (-m)." 910 928 sys.exit(1) 911 929 912 if len(arguments) < 1:930 if not prune and len(arguments) < 1: 913 931 print "Please give the paths to be scanned as argument." 914 932 sys.exit(1) 915 933 paths = arguments … … 923 941 sys.exit(1) 924 942 print_verbose("IMDb ID %s given manually." % options.imdb_id) 925 943 926 if dbimport :944 if dbimport or prune: 927 945 if not db_support: 928 946 print "You must install MySQLdb module to make direct DB importing to work" 929 947 sys.exit(1) … … 933 951 poster_dir = mythtv_setting("VideoArtworkDir", socket.gethostname()) 934 952 935 953 954 if prune: 955 prune_mythdb_metadata() 956 936 957 for path in paths: 937 958 938 959 if not os.path.exists(path):