son-link / minimal-podcasts-player

Subscribe, listen and (in the future) download your favorite podcasts, quickly and easily.
GNU General Public License v3.0
17 stars 4 forks source link

sqlite3.OperationalError: near "t": syntax error #15

Closed joergmlpts closed 2 years ago

joergmlpts commented 2 years ago

Nice project!

I managed to add one of my podcasts but could not add all of them. For example, when adding podcast https://www.spreaker.com/show/5634537/episodes/feed this exception occurred:

Traceback (most recent call last):
  File "minimal-podcasts-player/mpp/db.py", line 52, in run
    lastid, episodes = insertPodcast(self.url, data)
  File "minimal-podcasts-player/mpp/db.py", line 564, in insertPodcast
    )
sqlite3.OperationalError: near "t": syntax error
joergmlpts commented 2 years ago

It seems this exception occurs when there is an apostrophe in the podcast title or the podast description. In my case podcast https://www.spreaker.com/show/5634537/episodes/feed has title Crime Pays But Botany Doesn't which contains an apostrophe.

The title and description are inserted into the database with this code:

        # Insert podcasts data in the podcasts table
        insert = cursor.execute(
            """
                INSERT INTO podcasts (
                title,
                url,
                cover,
                description,
                pageUrl,
                coverUrl
            )
            VALUES (
                '{0}',
                '{1}',
                '{2}',
                '{3}',
                '{4}',
                '{5}')
            """.format(
                data['title'],
                url,
                cover_name,
                data['description'],
                data['link'],
                data['cover_url']
            )
        )

For this podcast, this data is passed to cursor.execute:

            INSERT INTO podcasts (
                title,
                url,
                cover,
                description,
                pageUrl,
                coverUrl
            )
            VALUES (
                'Crime Pays But Botany Doesn't',
                'https://www.spreaker.com/show/5634537/episodes/feed',
                '35f4fcd771cee1eaf50cb70d643a81f3.jpg',
                'An antidote to the nausea caused by life in modern society via explorations of the cast of plant species composing the "living skin" of Planet Earth.',
                'https://www.spreaker.com/show/crime-pays-but-botany-doesnt',
                'https://d3wo5wojvuv7l.cloudfront.net/t_rss_itunes_square_1400/images.spreaker.com/original/35f4fcd771cee1eaf50cb70d643a81f3.jpg')

The value for title - 'Crime Pays But Botany Doesn't' - causes this exception. A single quote in a string delimited with quotes certainly looks wrong. Near "t" in the error message is likely because "t" is the character that follows the apostrophe.