def __load_meta_data(self): meta_data_cache_file = self.full_filename + '.meta' if not os.path.isfile(meta_data_cache_file): media_info = MediaInfo() media_info.Open(str(self.get_full_path())) data = media_info.Inform().split("\n") for line in data: line = line.strip().split(':') if line[0].strip() in terrariumAudioFile.META_FIELDS: field = line[0].strip().replace(' ','').replace('(s)','s').lower() value = line[1].strip() if 'duration' == field: duration = terrariumAudioFile.DURATION_REGEX.match(value) value = 0 if duration.group('seconds'): value = int(duration.group('seconds')) if duration.group('minutes'): value += int(duration.group('minutes')) * 60 value *= 1000 self.meta_data[field] = value media_info.Close() if len(self.meta_data) > 0: with open(meta_data_cache_file, 'w') as datafile: json.dump(self.meta_data, datafile) else: with open(meta_data_cache_file) as datafile: self.meta_data = json.load(datafile)
def __load_meta_data(self): meta_data_cache_file = self.full_filename + '.meta' if not os.path.isfile(meta_data_cache_file): media_info = MediaInfo() media_info.Open(self.get_full_path()) data = media_info.Inform().split("\n") for line in data: line = line.strip().split(':') if line[0].strip() in terrariumAudioFile.META_FIELDS: field = line[0].strip().replace(' ', '').replace('(s)', 's').lower() value = line[1].strip() if 'duration' == field: value = media_info.Get(Stream.Audio, 0, "Duration") self.meta_data[field] = value media_info.Close() if len(self.meta_data) > 0: with open(meta_data_cache_file, 'wb') as datafile: json.dump(self.meta_data, datafile) else: with open(meta_data_cache_file) as datafile: self.meta_data = json.load(datafile)
class Core(CorePluginBase): def enable(self): self.media_info = MediaInfo() def disable(self): pass def update(self): pass @export def get_media_info(self, torrent_id, file_index): """ Generates the media info for the file. :param torrent_id: The Torrent the file belongs to :param file_index: The file index to generate the media info for :return: MediaInfo string """ log.debug('mediainfo info request for:\nTorrent ID: %s\nFile ID: %s' % (torrent_id, file_index)) media_file = self._get_torrent_data(torrent_id, file_index) self.media_info.Open(media_file) info = self.media_info.Inform() self.media_info.Close() return info @staticmethod def _get_torrent_data(torrent_id, file_index): data = component.get('Core').get_torrent_status( torrent_id, ['save_path', 'files']) file_path = filter(lambda file_: file_index == file_['index'], data['files']) if len(file_path) != 1: log.error('no file index %d' % file_index) return None file_path = file_path[0]['path'] log.debug('download path: %s\nfile path: %s', str(data['save_path']), str(file_path)) return os.path.join(data['save_path'], file_path)
def enable(self): self.media_info = MediaInfo()
endTime = time.time() #Records the end time and duration = endTime - startTime #Calculates the duration #Entry portion begins here path = raw_input('Please enter a directory and ensure it ends with a \:' ) #Provides a raw input area #Main Script Begins Here os.chdir(os.environ["PROGRAMFILES"] + "\\mediainfo") from MediaInfoDLL import MediaInfo, Stream #Imports MediaInfo from the Lib MI = MediaInfo() #Defines MI as the python script MediaInfo def get_lengths_in_milliseconds_of_directory(prefix): for f in os.listdir(path): # For each file in the directory MI.Open(path + f) #Opens each file duration_string = MI.Get(Stream.Video, 0, "Duration") #Defines duration_string try: duration = int(duration_string) #Gets the duration from metadata
response = table.scan( FilterExpression=Attr('userId').eq('*****@*****.**'), ProjectionExpression='filename, watched') items = response['Items'] while 'LastEvaluatedKey' in response: response = table.scan( FilterExpression=Attr('userId').eq('*****@*****.**'), ProjectionExpression='filename, watched', ExclusiveStartKey=response['LastEvaluatedKey']) for i in response['Items']: items.append(i) mediaInfo = MediaInfo() print("The current time is ", datetime.now().strftime('%Y-%m-%d %H:%M:%S')) loadMovies('F:\\Media Library\\Movies\\New') loadMovies('G:\\Media Library\\Movies\\New') loadMovies('H:\\Media Library\\Movies\\New') print("Done loading movies!!") updateWatched('F:\\Media Library\\Movies\\New\\_Done') updateWatched('G:\\Media Library\\Movies\\New\\_Done') updateWatched('H:\\Media Library\\Movies\\New\\_Done') print("Done updating watched movies!!")