def ftInsertFilm( self, film, commit ):
		newchn = False
		inschn = 0
		insshw = 0
		insmov = 0

		# handle channel
		if self.ft_channel != film['channel']:
			# process changed channel
			newchn = True
			self.ft_channel = film['channel']
			( self.ft_channelid, inschn ) = self._insert_channel( self.ft_channel )
			if self.ft_channelid == 0:
				self.logger.info( 'Undefined error adding channel "{}"', self.ft_channel )
				return ( 0, 0, 0, 0, )

		if newchn or self.ft_show != film['show']:
			# process changed show
			self.ft_show = film['show']
			( self.ft_showid, insshw ) = self._insert_show( self.ft_channelid, self.ft_show, mvutils.make_search_string( self.ft_show ) )
			if self.ft_showid == 0:
				self.logger.info( 'Undefined error adding show "{}"', self.ft_show )
				return ( 0, 0, 0, 0, )

		try:
			cursor = self.conn.cursor()
			cursor.callproc( 'ftInsertFilm', (
				self.ft_channelid,
				self.ft_showid,
				film["title"],
				mvutils.make_search_string( film['title'] ),
				film["aired"],
				film["duration"],
				film["size"],
				film["description"],
				film["website"],
				film["url_sub"],
				film["url_video"],
				film["url_video_sd"],
				film["url_video_hd"],
				film["airedepoch"],
			) )
			for result in cursor.stored_results():
				for ( filmid, insmov ) in result:
					cursor.close()
					if commit:
						self.conn.commit()
					return ( filmid, inschn, insshw, insmov )
				# should never happen
				cursor.close()
				if commit:
					self.conn.commit()
		except mysql.connector.Error as err:
			self.logger.error( 'Database error: {}', err )
			self.notifier.ShowDatabaseError( err )
		return ( 0, 0, 0, 0, )
예제 #2
0
	def ftInsertFilm( self, film, commit ):
		newchn = False
		inschn = 0
		insshw = 0
		insmov = 0

		# handle channel
		if self.ft_channel != film['channel']:
			# process changed channel
			newchn = True
			self.ft_channel = film['channel']
			( self.ft_channelid, inschn ) = self._insert_channel( self.ft_channel )
			if self.ft_channelid == 0:
				self.logger.info( 'Undefined error adding channel "{}"', self.ft_channel )
				return ( 0, 0, 0, 0, )

		if newchn or self.ft_show != film['show']:
			# process changed show
			self.ft_show = film['show']
			( self.ft_showid, insshw ) = self._insert_show( self.ft_channelid, self.ft_show, mvutils.make_search_string( self.ft_show ) )
			if self.ft_showid == 0:
				self.logger.info( 'Undefined error adding show "{}"', self.ft_show )
				return ( 0, 0, 0, 0, )

		try:
			cursor = self.conn.cursor()
			cursor.callproc( 'ftInsertFilm', (
				self.ft_channelid,
				self.ft_showid,
				film["title"],
				mvutils.make_search_string( film['title'] ),
				film["aired"],
				film["duration"],
				film["size"],
				film["description"],
				film["website"],
				film["url_sub"],
				film["url_video"],
				film["url_video_sd"],
				film["url_video_hd"],
				film["airedepoch"],
			) )
			for result in cursor.stored_results():
				for ( filmid, insmov ) in result:
					cursor.close()
					if commit:
						self.conn.commit()
					return ( filmid, inschn, insshw, insmov )
				# should never happen
				cursor.close()
				if commit:
					self.conn.commit()
		except mysql.connector.Error as err:
			self.logger.error( 'Database error: {}', err )
			self.notifier.ShowDatabaseError( err )
		return ( 0, 0, 0, 0, )
예제 #3
0
    def ftInsertFilm(self, film, commit):
        try:
            cursor = self.conn.cursor()
            newchn = False
            inschn = 0
            insshw = 0
            insmov = 0
            channel = film['channel'][:64]
            show = film['show'][:128]
            title = film['title'][:128]

            # handle channel
            if self.ft_channel != channel:
                # process changed channel
                newchn = True
                cursor.execute(
                    'SELECT `id`,`touched` FROM `channel` WHERE channel.channel=?',
                    (channel, ))
                r = cursor.fetchall()
                if len(r) > 0:
                    # get the channel data
                    self.ft_channel = channel
                    self.ft_channelid = r[0][0]
                    if r[0][1] == 0:
                        # updated touched
                        cursor.execute(
                            'UPDATE `channel` SET `touched`=1 WHERE ( channel.id=? )',
                            (self.ft_channelid, ))
                else:
                    # insert the new channel
                    inschn = 1
                    cursor.execute(
                        'INSERT INTO `channel` ( `dtCreated`,`channel` ) VALUES ( ?,? )',
                        (int(time.time()), channel))
                    self.ft_channel = channel
                    self.ft_channelid = cursor.lastrowid

            # handle show
            if newchn or self.ft_show != show:
                # process changed show
                cursor.execute(
                    'SELECT `id`,`touched` FROM `show` WHERE ( show.channelid=? ) AND ( show.show=? )',
                    (self.ft_channelid, show))
                r = cursor.fetchall()
                if len(r) > 0:
                    # get the show data
                    self.ft_show = show
                    self.ft_showid = r[0][0]
                    if r[0][1] == 0:
                        # updated touched
                        cursor.execute(
                            'UPDATE `show` SET `touched`=1 WHERE ( show.id=? )',
                            (self.ft_showid, ))
                else:
                    # insert the new show
                    insshw = 1
                    cursor.execute(
                        """
						INSERT INTO `show` (
							`dtCreated`,
							`channelid`,
							`show`,
							`search`
						)
						VALUES (
							?,
							?,
							?,
							?
						)
						""", (int(time.time()), self.ft_channelid, show,
                    mvutils.make_search_string(show)))
                    self.ft_show = show
                    self.ft_showid = cursor.lastrowid

            # check if the movie is there
            idhash = hashlib.md5(
                "{}:{}:{}".format(self.ft_channelid, self.ft_showid,
                                  film['url_video'])).hexdigest()
            cursor.execute(
                """
				SELECT		`id`,
							`touched`
				FROM		`film`
				WHERE		( film.idhash = ? )
			""", (idhash, ))
            r = cursor.fetchall()
            if len(r) > 0:
                # film found
                filmid = r[0][0]
                if r[0][1] == 0:
                    # update touched
                    cursor.execute(
                        'UPDATE `film` SET `touched`=1 WHERE ( film.id=? )',
                        (filmid, ))
            else:
                # insert the new film
                insmov = 1
                cursor.execute(
                    """
					INSERT INTO `film` (
						`idhash`,
						`dtCreated`,
						`channelid`,
						`showid`,
						`title`,
						`search`,
						`aired`,
						`duration`,
						`size`,
						`description`,
						`website`,
						`url_sub`,
						`url_video`,
						`url_video_sd`,
						`url_video_hd`
					)
					VALUES (
						?,
						?,
						?,
						?,
						?,
						?,
						?,
						?,
						?,
						?,
						?,
						?,
						?,
						?,
						?
					)
					""", (idhash, int(time.time()), self.ft_channelid, self.ft_showid, title,
                mvutils.make_search_string(film['title']), film['airedepoch'],
                mvutils.make_duration(film['duration']), film['size'],
                film['description'], film['website'], film['url_sub'],
                film['url_video'], film['url_video_sd'], film['url_video_hd']))
                filmid = cursor.lastrowid
            if commit:
                self.conn.commit()
            cursor.close()
            return (filmid, inschn, insshw, insmov)
        except sqlite3.DatabaseError as err:
            self._handle_database_corruption(err)
            raise DatabaseCorrupted(
                'Database error during critical operation: {} - Database will be rebuilt from scratch.'
                .format(err))
예제 #4
0
    def ft_insert_film(self, film, commit=True):
        """
        Inserts a film emtry into the database

        Args:
            film(Film): a film entry

            commit(bool, optional): the operation will be
                commited immediately. Default is `True`
        """
        newchn = False
        inschn = 0
        insshw = 0
        insmov = 0
        channel = film['channel'][:64]
        show = film['show'][:128]
        title = film['title'][:128]

        # handle channel
        if self.ft_channel != channel:
            # process changed channel
            newchn = True
            self.ft_channel = channel
            (self.ft_channelid, inschn) = self._insert_channel(self.ft_channel)
            if self.ft_channelid == 0:
                self.logger.info('Undefined error adding channel "{}"',
                                 self.ft_channel)
                return (
                    0,
                    0,
                    0,
                    0,
                )

        if newchn or self.ft_show != show:
            # process changed show
            self.ft_show = show
            (self.ft_showid, insshw) = self._insert_show(
                self.ft_channelid, self.ft_show,
                mvutils.make_search_string(self.ft_show))
            if self.ft_showid == 0:
                self.logger.info('Undefined error adding show "{}"',
                                 self.ft_show)
                return (
                    0,
                    0,
                    0,
                    0,
                )

        try:
            cursor = self.conn.cursor()
            cursor.callproc('ftInsertFilm', (
                self.ft_channelid,
                self.ft_showid,
                title,
                mvutils.make_search_string(title),
                film["aired"],
                film["duration"],
                film["size"],
                film["description"],
                film["website"],
                film["url_sub"],
                film["url_video"],
                film["url_video_sd"],
                film["url_video_hd"],
                film["airedepoch"],
            ))
            for result in cursor.stored_results():
                for (filmid, insmov) in result:
                    cursor.close()
                    if commit:
                        self.conn.commit()
                    return (filmid, inschn, insshw, insmov)
                # should never happen
                cursor.close()
                if commit:
                    self.conn.commit()
        except mysql.connector.Error as err:
            self.logger.error('Database error: {}, {}', err.errno, err)
            self.notifier.show_database_error(err)
        return (
            0,
            0,
            0,
            0,
        )
예제 #5
0
	def ftInsertFilm( self, film, commit ):
		try:
			cursor = self.conn.cursor()
			newchn = False
			inschn = 0
			insshw = 0
			insmov = 0

			# handle channel
			if self.ft_channel != film['channel']:
				# process changed channel
				newchn = True
				cursor.execute( 'SELECT `id`,`touched` FROM `channel` WHERE channel.channel=?', ( film['channel'], ) )
				r = cursor.fetchall()
				if len( r ) > 0:
					# get the channel data
					self.ft_channel = film['channel']
					self.ft_channelid = r[0][0]
					if r[0][1] == 0:
						# updated touched
						cursor.execute( 'UPDATE `channel` SET `touched`=1 WHERE ( channel.id=? )', ( self.ft_channelid, ) )
				else:
					# insert the new channel
					inschn = 1
					cursor.execute( 'INSERT INTO `channel` ( `dtCreated`,`channel` ) VALUES ( ?,? )', ( int( time.time() ), film['channel'] ) )
					self.ft_channel = film['channel']
					self.ft_channelid = cursor.lastrowid

			# handle show
			if newchn or self.ft_show != film['show']:
				# process changed show
				cursor.execute( 'SELECT `id`,`touched` FROM `show` WHERE ( show.channelid=? ) AND ( show.show=? )', ( self.ft_channelid, film['show'] ) )
				r = cursor.fetchall()
				if len( r ) > 0:
					# get the show data
					self.ft_show = film['show']
					self.ft_showid = r[0][0]
					if r[0][1] == 0:
						# updated touched
						cursor.execute( 'UPDATE `show` SET `touched`=1 WHERE ( show.id=? )', ( self.ft_showid, ) )
				else:
					# insert the new show
					insshw = 1
					cursor.execute(
						"""
						INSERT INTO `show` (
							`dtCreated`,
							`channelid`,
							`show`,
							`search`
						)
						VALUES (
							?,
							?,
							?,
							?
						)
						""", (
							int( time.time() ),
							self.ft_channelid, film['show'],
							mvutils.make_search_string( film['show'] )
						)
					)
					self.ft_show = film['show']
					self.ft_showid = cursor.lastrowid

			# check if the movie is there
			cursor.execute( """
				SELECT		`id`,
							`touched`
				FROM		`film`
				WHERE		( film.channelid = ? )
							AND
							( film.showid = ? )
							AND
							( film.url_video = ? )
			""", ( self.ft_channelid, self.ft_showid, film['url_video'] ) )
			r = cursor.fetchall()
			if len( r ) > 0:
				# film found
				filmid = r[0][0]
				if r[0][1] == 0:
					# update touched
					cursor.execute( 'UPDATE `film` SET `touched`=1 WHERE ( film.id=? )', ( filmid, ) )
			else:
				# insert the new film
				insmov = 1
				cursor.execute(
					"""
					INSERT INTO `film` (
						`dtCreated`,
						`channelid`,
						`showid`,
						`title`,
						`search`,
						`aired`,
						`duration`,
						`size`,
						`description`,
						`website`,
						`url_sub`,
						`url_video`,
						`url_video_sd`,
						`url_video_hd`
					)
					VALUES (
						?,
						?,
						?,
						?,
						?,
						?,
						?,
						?,
						?,
						?,
						?,
						?,
						?,
						?
					)
					""", (
						int( time.time() ),
						self.ft_channelid,
						self.ft_showid,
						film['title'],
						mvutils.make_search_string( film['title'] ),
						film['airedepoch'],
						mvutils.make_duration( film['duration'] ),
						film['size'],
						film['description'],
						film['website'],
						film['url_sub'],
						film['url_video'],
						film['url_video_sd'],
						film['url_video_hd']
					)
				)
				filmid = cursor.lastrowid
			if commit:
				self.conn.commit()
			cursor.close()
			return ( filmid, inschn, insshw, insmov )
		except sqlite3.DatabaseError as err:
			self._handle_database_corruption( err )
			raise DatabaseCorrupted( 'Database error during critical operation: {} - Database will be rebuilt from scratch.'.format( err ) )