def add(self): print "" print "Adding file to iTunes - " + self.filename source = Metadata_Source(self.config) metadata = source.get_metadata(self.tvdb_id, self.filename) osascript_command = [self.config.get("paths", "osascript"), "-e"] script = textwrap.dedent( u"""\ set p to "%s" set f to POSIX file p set outText to "" set seasonnumber to "%s" set episodenumber to "%s" set seriesname to "%s" tell application "iTunes" set playcount to 0 set lastplayed to missing value if seriesname is not "" then set outText to outText & " - Checking to see if episode already exists in iTunes\n" set theTracks to tracks of library playlist 1 whose show contains (seriesname as string) and season number is (seasonnumber as integer) and episode number is (episodenumber as integer) and video kind is TV show repeat with theTrack in theTracks set outText to outText & " - Found in iTunes, deleting previous entry\n" set playcount to played count of theTrack set lastplayed to played date of theTrack delete theTrack end repeat end if set outText to outText & " - Sending file to iTunes\n" set newFile to (add f) set played count of newFile to playcount set played date of newFile to lastplayed end tell return outText""" ) script = script % ( unicode(self.filename, "utf-8"), metadata["seasonnumber"], metadata["episodenumber"], metadata["seriesname"], ) osascript_command.append(script) script_output = subprocess.check_output(osascript_command) print script_output print " * Done adding file to iTunes"
def _get_metadata(self): source = Metadata_Source(self.config) metadata = source.get_metadata(self.tvdb_id, self.filename) print ' - Setting options' tags = dict() # Metadata that's always present tags['TVSeasonNum'] = metadata['seasonnumber'] tags['TVEpisodeNum'] = metadata['episodenumber'] tags['TVShowName'] = tags['artist'] = metadata['seriesname'] tags['title'] = metadata['episodename'] tags['album'] = metadata['seriesname'] + ', Season ' + metadata['seasonnumber'] tags['disk'] = '1/1' tags['stik'] = 'TV Show' # Metadata that may not be present if 'poster' in metadata: tags['artwork'] = self._get_artwork(metadata['poster']) else: tags['artwork'] = self._get_artwork(None) if 'network' in metadata: tags['TVNetwork'] = metadata['network'] if 'airdate' in metadata: tags['year'] = metadata['airdate'] self.airdate = metadata['airdate'] if 'certificate' in metadata: tags['contentRating'] = metadata['certificate'] if 'genre' in metadata: tags['genre'] = metadata['genre'] if 'episodecount' in metadata: tags['tracknum'] = metadata['episodenumber'] + '/' + metadata['episodecount'] if 'id' in metadata: tags['cnID'] = metadata['id'] if 'description' in metadata: tags['description'] = metadata['description'] if 'description' in metadata: tags['longdesc'] = metadata['description'] # Check file for HDness print ' - Scanning video to check HDness' mi = MediaInfo.parse(self.filename) video_hd = False for track in mi.tracks: if track.track_type == 'Video': video_hd = True if (track.height >= 700 or track.width >= 1260) else False tags['hdvideo'] = '1' if video_hd else '0' xml = None if self.config.get('tagMP4', 'add_people') == 'True' and 'actors' in metadata: xml = self._gen_XML(metadata['actors']) return tags, xml