Exemplo n.º 1
0
def linkMediaFileToMovie(aMediaFile, aMovie, conn = None):
	if conn == None:
		conn = mySql.createConnection()
	cursor = conn.cursor()

	dirConf = settingsManager.directorySettings()

	#Set the proper movie as 'Active'
	movieArray = movie.getByMediaFileId(aMediaFile.id, conn)
	for m in movieArray:
		m.active = 0
		if m.id == aMovie.id:
			m.active = 1
		m.save(conn)

	#Delete the existing linked file if there is one
	removeHardLinkForMediaFile(aMediaFile)

	#Generate a new linked file name and path and update the media file accordingly
	movieFileName = generateHardLinkNameFromMediaFileAndMovie(aMediaFile, aMovie)
	moviePath = os.path.join(dirConf.movieDestination, movieFileName)
	aMediaFile.linkedPath = moviePath
	aMediaFile.save(conn)

	#Create the new link
	createHardLinkForMediaFile(aMediaFile)

	return movieFileName
Exemplo n.º 2
0
def generateSeasonPathFromEpisodeAndSeries(anEpisode, aSeries):
	dirConf = settingsManager.directorySettings()
	seriesPath = os.path.join(dirConf.tvDestination, aSeries.title)

	seasonFolderSkeleton = 'Season 0{0}' if anEpisode.season <= 9 else 'Season {0}'

	seasonPath = os.path.join(seriesPath, seasonFolderSkeleton.format(anEpisode.season))
	return seasonPath
Exemplo n.º 3
0
def main():
	systemConf = settingsManager.systemSettings()
	dirConf = settingsManager.directorySettings()
	conn = mySql.createConnection()

	addedContent = []
	for root, dirs, files in os.walk(dirConf.contentSource):
		for file in files:
			fullPath = os.path.join(root, file)
			if isNewTvEpisode(file, root, conn):
				tvShowInfo = getSeries(file)
				newMediaFile = mediaFile.createWithPath(fullPath).save(conn)
				anEpisode = episode.create(tvShowInfo[1], tvShowInfo[2])
				aSeriesAlias = seriesAlias.getBySeriesAliasString(tvShowInfo[0], conn)
				anEpisode = mediaLinker.associateEpisodeWithMediaFile(anEpisode, newMediaFile)
				if aSeriesAlias == None:
					aSeriesAlias = seriesAlias.create(tvShowInfo[0]).save(conn)
					anEpisode = mediaLinker.associateEpisodeWithSeriesAlias(anEpisode, aSeriesAlias)
					seriesArray = findImdbSeriesLikeTitle(file)
					if len(seriesArray) > 0:
						mediaLinker.associateArrayOfSeriesWithSeriesAlias(seriesArray, aSeriesAlias)
						episodeName = mediaLinker.linkMediaFileToSeries(newMediaFile, seriesArray[0])
						addedContent.append(episodeName)
						print file, '  ->  ', episodeName
					else:
						print "\t", "No series for " + file
				else:
					anEpisode = mediaLinker.associateEpisodeWithSeriesAlias(anEpisode, aSeriesAlias)
					aSeries = series.getActiveBySeriesAliasId(aSeriesAlias.id, conn)
					episodeName = mediaLinker.linkMediaFileToSeries(newMediaFile, aSeries)
					addedContent.append(episodeName)
					print file, '  ->  ', episodeName
			elif isNewMovie(file, root, conn):
				newMediaFile = mediaFile.createWithPath(fullPath).save(conn)
				#Check to see if the movie is in a sub folder
				#if so then do the search based on folder name instead of file name
				if len(root) > len(dirConf.contentSource):
					folderTitle = os.path.basename(root)
					movies = findImdbMoviesLikeTitle(folderTitle)
				else:
					movies = findImdbMoviesLikeTitle(file)

				if len(movies) > 0:
					mediaLinker.associateArrayOfMoviesWithMediaFile(movies, newMediaFile, conn)
					movieName = mediaLinker.linkMediaFileToMovie(newMediaFile, movies[0], conn)
					addedContent.append(movieName)
					print file, '  ->  ', movieName
				else:
					print "\t", "No movies for " + file			

	conn.close()
	if len(addedContent) == 1:
		sendXbmcNotification("New Content", addedContent[0]+" was added to the library.")
		sendXbmcLibraryUpdate()
	elif len(addedContent) > 1:
		sendXbmcNotification("New Content", str(len(addedContent))+" new items were added to the library.")
		sendXbmcLibraryUpdate()
Exemplo n.º 4
0
def linkMediaFileToSeries(aMediaFile, aSeries, conn = None):
	if conn == None:
		conn = mySql.createConnection()
	cursor = conn.cursor()

	dirConf = settingsManager.directorySettings()

	#Get all the episode information needed to do the linking
	anEpisode = episode.getByMediaFileId(aMediaFile.id, conn)
	aSeriesAlias = seriesAlias.getBySeriesAliasId(anEpisode.associatedSeriesAliasId, conn)

	#Set the proper series as 'Active'
	seriesArray = series.getBySeriesAliasId(aSeriesAlias.id, conn)
	for s in seriesArray:
		s.active = 0
		if s.id == aSeries.id:
			s.active = 1
		s.save(conn)

	#Delete the existing linked file if there is one
	removeHardLinkForMediaFile(aMediaFile)
	removeSeasonFolderIfEmptyForMediaFile(aMediaFile)
	removeSeriesFolderIfEmptyForMediaFile(aMediaFile)

	#Generate a new linked file name and path and update the media file accordingly
	episodeFileName = generateHardLinkNameFromMediaFileAndEpisodeAndSeries(aMediaFile, anEpisode, aSeries)
	seasonPath = generateSeasonPathFromEpisodeAndSeries(anEpisode, aSeries)
	episodePath = os.path.join(seasonPath, episodeFileName)
	aMediaFile.linkedPath = episodePath
	aMediaFile.save(conn)

	#Create the new link
	createSeriesFolderForMediaFile(aMediaFile)
	createSeasonFolderForMediaFile(aMediaFile)
	createHardLinkForMediaFile(aMediaFile)

	return episodeFileName