Ticket #4055: scanner.patch

File scanner.patch, 2.9 KB (added by matthew.d.stone@…, 17 years ago)

Patch

  • MythTV.py

     
    363363                else:
    364364                        return None
    365365
     366        def hasMetadata(self, videopath):
     367                """
     368                Determines if the given videopath has any metadata in the DB
     369               
     370                Returns False if no metadata was found.
     371                """
     372                c = self.db.cursor()
     373                c.execute("""
     374                        SELECT category, year
     375                        FROM videometadata
     376                        WHERE filename = %s""", (videopath,))
     377                row = c.fetchone()
     378                c.close()
     379               
     380                if row is not None:
     381                        # If category is 0 and year is 1895, we can safely assume no metadata
     382                        if (row[0] == 0) and (row[1] == 1895):
     383                                return False
     384                        else:
     385                                return True
     386                else:
     387                        return False
    366388        def getMetadata(self, id):
    367389                """
    368390                Finds the MythVideo metadata for the given id from the MythDB, if any.
  • imdbpy.py

     
    158158
    159159        movies = []
    160160        for m in sorted_movies:
     161                try:
     162                        movies.append([imdb_access.get_imdbID(m), m['title'], int(m['year'])])
     163                except KeyError:
     164                        movies.append([imdb_access.get_imdbID(m), m['title'], 1901])
    161165                movies.append([imdb_access.get_imdbID(m), m['title'], int(m['year'])])
    162166        return movies
    163167
  • find_meta.py

     
    583583                        return None
    584584
    585585        print_verbose("Querying IMDb for meta data for ID %s..." % imdb_id)
    586         meta = imdbpy.fetch_metadata(imdb_id)
    587         if meta is not None:
    588                 if meta.series_episode:
    589                         title, season, episode = imdbpy.detect_series_title(title)
    590                         if meta.season is None:
    591                                 meta.season = season
    592                         if meta.episode is None:
    593                                 meta.episode = episode
    594                 metadata = meta.toMetadataString()
    595                 metadata += "IMDb:%s" % imdb_id + "\n"
    596         return metadata
     586        try:
     587                meta = imdbpy.fetch_metadata(imdb_id)
     588                if meta is not None:
     589                        if meta.series_episode:
     590                                title, season, episode = imdbpy.detect_series_title(title)
     591                                if meta.season is None:
     592                                        meta.season = season
     593                                if meta.episode is None:
     594                                        meta.episode = episode
     595                        metadata = meta.toMetadataString()
     596                        metadata += "IMDb:%s" % imdb_id + "\n"
     597                return metadata
     598        except:
     599                print_verbose("Problem occured fetching metadata for ID %s..." % imdb_id)
     600                return None
    597601
    598602def video_file_list_metadata(videoPaths):
    599603        videoPaths = [os.path.basename(v) for v in videoPaths]
     
    797801        # Check if we are not in overwrite mode and there is existing data
    798802        # for the wanted targets (metadata files and/or MythDB).
    799803        if not overwrite:
    800                 need_mythdb_data = dbimport and mythvideo.getMetadataId(path) is None
     804                need_mythdb_data = dbimport and not mythvideo.hasMetadata(path)
    801805                need_metadata_file = metafiles
    802806                if metafiles and meta_file is not None:
    803807                        need_metadata_file = not os.path.exists(meta_file)