__license__ = 'GPL v3'
__copyright__ = '2008-2012, Darko Miletic <darko.miletic at gmail.com>'
'''
blic.rs
'''

import re

from calibre.web.feeds.news import BasicNewsRecipe


class Blic(BasicNewsRecipe):
    title = 'Blic'
    __author__ = 'Darko Miletic'
    description = 'Blic.rs online verzija najtiraznije novine u Srbiji donosi najnovije vesti iz Srbije i sveta, komentare, politicke analize, poslovne i ekonomske vesti, vesti iz regiona, intervjue, informacije iz kulture, reportaze, pokriva sve sportske dogadjaje, detaljan tv program, nagradne igre, zabavu, fenomenalni Blic strip, dnevni horoskop, arhivu svih dogadjaja'  # noqa: E501
    publisher = 'RINGIER d.o.o.'
    category = 'news, politics, Serbia'
    oldest_article = 2
    max_articles_per_feed = 100
    no_stylesheets = True
    use_embedded_content = False
    masthead_url = 'http://www.blic.rs/resources/images/header/header_back.png'
    language = 'sr'
    publication_type = 'newspaper'
    extra_css = '''
                               @font-face {font-family: "serif1";src:url(res:///opt/sony/ebook/FONT/tt0011m_.ttf)}
                               @font-face {font-family: "sans1";src:url(res:///opt/sony/ebook/FONT/tt0003m_.ttf)}
                               body{font-family: Georgia, serif1, serif}
                               .articledescription,#nadnaslov,.article_info{font-family: Arial, sans1, sans-serif}
                               .img_full{float: none}
                               #nadnaslov{font-size: small}
                               #article_lead{font-size: 1.5em}
                               h1{color: red}
                               .potpis{font-size: x-small; color: gray}
                               .article_info{font-size: small}
                               img{margin-bottom: 0.8em; margin-top: 0.8em; display: block}
                            '''

    conversion_options = {'comment': description, 'tags': category, 'publisher': publisher, 'language': language, 'linearize_tables': True}

    preprocess_regexps = [(re.compile('\u0110'), lambda match: '\u00d0')]  # noqa: RUF039
    remove_tags_before = dict(name='div', attrs={'id': 'article_info'})
    remove_tags = [dict(name=['object', 'link', 'meta', 'base', 'object', 'embed'])]
    remove_attributes = ['width', 'height', 'm_id', 'm_ext', 'mlg_id', 'poll_id', 'v_id']

    feeds = [
        ('Politika', 'http://www.blic.rs/rss/Vesti/Politika'),
        ('Tema Dana', 'http://www.blic.rs/rss/Vesti/Tema-Dana'),
        ('Svet', 'http://www.blic.rs/rss/Vesti/Svet'),
        ('Drustvo', 'http://www.blic.rs/rss/Vesti/Drustvo'),
        ('Ekonomija', 'http://www.blic.rs/rss/Vesti/Ekonomija'),
        ('Hronika', 'http://www.blic.rs/rss/Vesti/Hronika'),
        ('Beograd', 'http://www.blic.rs/rss/Vesti/Beograd'),
        ('Srbija', 'http://www.blic.rs/rss/Vesti/Srbija'),
        ('Vojvodina', 'http://www.blic.rs/rss/Vesti/Vojvodina'),
        ('Republika Srpska', 'http://www.blic.rs/rss/Vesti/Republika-Srpska'),
        ('Reportaza', 'http://www.blic.rs/rss/Vesti/Reportaza'),
        ('Dodatak', 'http://www.blic.rs/rss/Vesti/Dodatak'),
        ('Zabava', 'http://www.blic.rs/rss/Zabava'),
        ('Kultura', 'http://www.blic.rs/rss/Kultura'),
        ('Slobodno Vreme', 'http://www.blic.rs/rss/Slobodno-vreme'),
        ('IT', 'http://www.blic.rs/rss/IT'),
        ('Komentar', 'http://www.blic.rs/rss/Komentar'),
        ('Intervju', 'http://www.blic.rs/rss/Intervju'),
    ]

    def print_version(self, url):
        return url + '/print'

    def get_cover_url(self):
        soup = self.index_to_soup('http://www.blic.rs/')
        alink = soup.find('a', attrs={'id': 'blic_naslovna_print'})
        if alink:
            return 'http://www.blic.rs' + alink['href']
        return None
