Example #1
0
 def Add_Movie(self, movie):
     # add info to XML
     xml_movie_hash = 'mov_' + self.f_md5(movie['origin'] + movie['year'])
     #check if movie info exists
     xml_movie = self.movies.find(xml_movie_hash)
     if xml_movie is None:  #-- create new record
         # create serial record in XML
         xml_movie = SubElement(self.movies, xml_movie_hash)
         xml_movie.text = movie['name']
         SubElement(xml_movie, "origin").text = movie['origin']
         SubElement(xml_movie, "url").text = movie['url']
         SubElement(xml_movie, "genre").text = movie['genre']
         SubElement(xml_movie, "director").text = movie['director']
         SubElement(xml_movie, "actors").text = movie['actor']
         SubElement(xml_movie, "text").text = movie['descr']
         SubElement(xml_movie, "img").text = movie['image']
         # add year info
         SubElement(xml_movie, "year").text = movie['year']
         year_hash = self.Get_Movie_Year(movie['year'])
         # add movie category info
         SubElement(xml_movie, "categories")
         cat = xml_movie.find("categories")
         for cat_rec in movie['category']:
             cat_hash = self.Get_Movie_Type(cat_rec)
             if cat.find(cat_hash) is None:
                 SubElement(cat, cat_hash)
Example #2
0
 def Add_Movie(self, movie):
     # add info to XML
     xml_movie_hash = 'mov_' + self.f_md5(movie['origin'] + movie['year'])
     #check if movie info exists
     xml_movie = self.movies.find(xml_movie_hash)
     if xml_movie is None:   #-- create new record
         # create serial record in XML
         xml_movie = SubElement(self.movies, xml_movie_hash)
         xml_movie.text = movie['name']
         SubElement(xml_movie, "origin").text   = movie['origin']
         SubElement(xml_movie, "url").text      = movie['url']
         SubElement(xml_movie, "genre").text    = movie['genre']
         SubElement(xml_movie, "director").text = movie['director']
         SubElement(xml_movie, "actors").text   = movie['actor']
         SubElement(xml_movie, "text").text     = movie['descr']
         SubElement(xml_movie, "img").text      = movie['image']
         # add year info
         SubElement(xml_movie, "year").text     = movie['year']
         year_hash = self.Get_Movie_Year(movie['year'])
         # add movie category info
         SubElement(xml_movie, "categories")
         cat = xml_movie.find("categories")
         for cat_rec in movie['category']:
             cat_hash = self.Get_Movie_Type(cat_rec)
             if cat.find(cat_hash) is None:
                 SubElement(cat, cat_hash)
Example #3
0
def Save_Last_Serial_Info(tag, serial, serial_url, img, part):
    # get max history lenght
    try:
        max_history = (1, 5, 10, 20, 30, 50)[int(Addon.getSetting('history_len'))]
        if max_history > 99:
            max_history = 99
    except:
        max_history = 10

    sdate = today = date.today().isoformat()

    # load or create history file
    try:
        tree = ElementTree()
        tree.parse(os.path.join(Addon.getAddonInfo('path'), r'resources', r'data', r'history.xml'))
        xml1 = tree.getroot()
    except:
        # create XML structure
        xml1 = Element("SERIALU_NET_HISTORY")

    # shrink history to limit
    if len(xml1) > max_history:
        idx = 1
        for rec in xml1:
            if idx >= max_history:
                xml1.remove(rec)
            idx = idx + 1

    # format name
    if part.find('[/COLOR]') > -1:
        part = re.compile('[COLOR FF00FF00](.+?)[/COLOR]', re.MULTILINE|re.DOTALL).find(part)

    xml_hist = None
    # update sequince number for history records
    for rec in xml1:
        if rec.tag == tag:
            rec.find("ID").text = str(0).zfill(2)
            xml_hist = rec
        else:
            rec.find("ID").text = str(int(rec.find("ID").text)+1).zfill(2)

    if xml_hist == None:
        xml_hist = SubElement(xml1, tag)
        SubElement(xml_hist, "ID").text     = str(0).zfill(2)
        SubElement(xml_hist, "Serial").text = unescape(serial)
        SubElement(xml_hist, "URL").text    = serial_url
        SubElement(xml_hist, "Date").text   = sdate
        SubElement(xml_hist, "Part").text   = unescape(part)
        SubElement(xml_hist, "Image").text  = img
    else:
        xml_hist.find("Part").text   = unescape(part)
        xml_hist.find("Date").text   = sdate

    # sort history by IDs
    xml1[:] = sorted(xml1, key=getkey)

    ElementTree(xml1).write(os.path.join(Addon.getAddonInfo('path'), r'resources', r'data', r'history.xml'), encoding='utf-8')
Example #4
0
def Save_History(name, url, img):
    tag = 'ch_'+f_md5(url).hexdigest()

    # get max history lenght
    try:
        max_history = (1, 5, 10, 20, 30, 50)[int(Addon.getSetting('history_len'))]
        if max_history > 99:
            max_history = 99
    except:
        max_history = 10

    sdate = today = date.today().isoformat()

    # load or create history file
    try:
        tree = ElementTree()
        tree.parse(os.path.join(Addon.getAddonInfo('path'), r'resources', r'data', r'history.xml'))
        xml1 = tree.getroot()
    except:
        # create XML structure
        xml1 = Element("ULTIMATV_HISTORY")

    # shrink history to limit
    if len(xml1) > max_history:
        idx = 1
        for rec in xml1:
            if idx >= max_history:
                xml1.remove(rec)
            idx = idx + 1

    xml_hist = None
    # update sequince number for history records
    for rec in xml1:
        if rec.tag == tag:
            rec.find("ID").text = str(0).zfill(2)
            xml_hist = rec
        else:
            rec.find("ID").text = str(int(rec.find("ID").text)+1).zfill(2)

    if xml_hist == None:
        xml_hist = SubElement(xml1, tag)
        SubElement(xml_hist, "ID").text     = str(0).zfill(2)
        SubElement(xml_hist, "Channel").text = unescape(name)
        SubElement(xml_hist, "URL").text    = url
        SubElement(xml_hist, "Image").text  = img
        SubElement(xml_hist, "Date").text   = sdate
    else:
        xml_hist.find("Date").text   = sdate

    # sort history by IDs
    xml1[:] = sorted(xml1, key=getkey)

    ElementTree(xml1).write(os.path.join(Addon.getAddonInfo('path'), r'resources', r'data', r'history.xml'), encoding='utf-8')
Example #5
0
File: update.py Project: serbra/ru
def Get_Film_Info(url, xml_serials, xml_types, xml_genres, serial_found, dp):
    html = get_HTML(url)
    if html == '':
        return False

    html_container = re.compile(
        '<div class="container">(.+?)<div class="navigation">',
        re.MULTILINE | re.DOTALL).findall(html)

    # -- parsing web page ----------------------------------------------------------

    soup = BeautifulSoup(''.join(html_container[0].replace('<p>',
                                                           '  ').replace(
                                                               '</p>', '')))

    serials = soup.findAll("div", {"class": "entry"})
    for ser in serials:
        #try:
        # check if process was cancelled
        if (dp.iscanceled()): return
        # --
        i_name = unescape(ser.find("h2").find("a").text.strip())
        i_url = ser.find("h2").find("a")["href"]
        xbmc.log(' ***    ' + i_name.encode('utf-8'))
        #-- detail info
        info = ser.find("div", {"class": "content"})
        try:
            i_image = info.find("img")["src"]
        except:
            ser_name = ser.find("h2").find("a").text.strip(
            )  #i_name.replace(u'”', u'"').replace(u'“',u'"').replace(u'«',u'"').replace(u'»',u'"')
            search_mask = '<p><img class="m_pic" alt="' + ser_name + '" align="left" src="(.+?)" /></p>'
            img_alt = re.compile(search_mask,
                                 re.MULTILINE | re.DOTALL).findall(html)
            try:
                i_image = img_alt[0]
            except:
                search_mask = '<p><img class="m_pic" alt="' + ser_name + '"" align="left" src="(.+?)" /></p>'
                img_alt = re.compile(search_mask,
                                     re.MULTILINE | re.DOTALL).findall(html)
                try:
                    i_image = img_alt[0]
                except:
                    i_image = '-'
                    xbmc.log(i_name.encode('utf-8') + ' - image not found')

        o_name = '-'
        i_year = '-'
        i_country = '-'
        i_genre = '-'
        i_director = '-'
        i_actors = '-'
        i_text = '-'

        for inf in info.findAll("strong"):
            if inf.text.encode('utf-8') == 'Оригинальное название:':
                o_name = unescape(str(inf.nextSibling).strip())
            elif inf.text.encode('utf-8') == 'Год выхода на экран:':
                i_year = unescape(str(inf.nextSibling).strip())
            elif inf.text.encode('utf-8') == 'Страна:':
                i_country = unescape(str(inf.nextSibling).strip())
            elif inf.text.encode('utf-8') == 'Сериал относится к жанру:':
                i_genre = unescape(str(inf.nextSibling).strip())
            elif inf.text.encode('utf-8') == 'Постановщик':
                i_director = unescape(str(inf.nextSibling).strip())
            elif inf.text.encode(
                    'utf-8') == 'Актеры, принявшие участие в съемках:':
                i_actors = unescape(str(inf.nextSibling).strip())
            elif inf.text.encode('utf-8') == 'Краткое описание:':
                i_text = unescape(str(inf.nextSibling))

        full_text = i_text
        if o_name != '':
            full_text = full_text + (u'\nОригинальное название: ') + o_name
        if i_actors != '':
            full_text = full_text + (u'\nАктеры: ') + i_actors

        # add info to XML
        xml_serial_hash = 'ser_' + f_md5(
            (i_name + i_year).encode('utf-8')).hexdigest()
        #check if serial info exists
        xml_serial = xml_serials.find(xml_serial_hash)
        if xml_serial is None:  #-- create new record
            # create serial record in XML
            xml_serial = SubElement(xml_serials, xml_serial_hash)
            xml_serial.text = i_name
            SubElement(xml_serial, "name").text = i_name
            SubElement(xml_serial, "url").text = i_url
            SubElement(xml_serial, "year").text = i_year
            SubElement(xml_serial, "genre").text = i_genre
            SubElement(xml_serial, "director").text = i_director
            SubElement(xml_serial, "text").text = full_text
            SubElement(xml_serial, "img").text = i_image
            SubElement(xml_serial, "categories")
            SubElement(xml_serial, "genres")

        isCategory_found = 'n'
        # add serial category info
        categories = xml_serial.find("categories")
        for cat in ser.find("div", {"class": "cat"}).findAll("a"):
            if cat.text.encode('utf-8') <> 'Сериалы':
                cur_type_hash = 'sc_' + f_md5(
                    cat.text.strip().lower().encode('utf-8')).hexdigest()
                # check if category exists
                if xml_types.find(cur_type_hash) is None:
                    type = SubElement(xml_types, cur_type_hash)
                    SubElement(type, "name").text = unescape(
                        cat.text.strip()).capitalize()
                if categories.find(cur_type_hash) is None:
                    SubElement(categories, cur_type_hash)
                isCategory_found = 'y'

        isMultserial = 'n'
        # add serial genre info
        genres = xml_serial.find("genres")
        for gen in i_genre.split(','):
            cur_genre_hash = 'sg_' + f_md5(
                gen.strip().lower().encode('utf-8')).hexdigest()
            # check if category exists
            if xml_genres.find(cur_genre_hash) is None:
                genre = SubElement(xml_genres, cur_genre_hash)
                SubElement(genre,
                           "name").text = unescape(gen.strip()).capitalize()
            if genres.find(cur_genre_hash) is None:
                SubElement(genres, cur_genre_hash)
            # check if it's multserial
            if gen.encode(
                    'utf-8') == 'Мультсериал' and isCategory_found == 'n':
                isMultserial = 'y'

        # add multserial or foreighn serial types
        if isCategory_found == 'n':
            if isMultserial == 'y':
                # add serial category info
                categories = xml_serial.find("categories")
                cur_type_hash = 'sc_' + f_md5(
                    (u'Мультсериалы').lower().encode('utf-8')).hexdigest()
                # check if category exists
                if xml_types.find(cur_type_hash) is None:
                    type = SubElement(xml_types, cur_type_hash)
                    SubElement(type, "name").text = u'Мультсериалы'
                if categories.find(cur_type_hash) is None:
                    SubElement(categories, cur_type_hash)
            else:
                if i_country.encode('utf-8') == 'Россия':
                    # add serial category info
                    categories = xml_serial.find("categories")
                    cur_type_hash = 'sc_' + f_md5(
                        (u'Русские сериалы'
                         ).lower().encode('utf-8')).hexdigest()
                    # check if category exists
                    if xml_types.find(cur_type_hash) is None:
                        type = SubElement(xml_types, cur_type_hash)
                        SubElement(type, "name").text = u'Русские сериалы'
                    if categories.find(cur_type_hash) is None:
                        SubElement(categories, cur_type_hash)
                else:
                    # add serial category info
                    categories = xml_serial.find("categories")
                    cur_type_hash = 'sc_' + f_md5(
                        (u'Зарубежные сериалы'
                         ).lower().encode('utf-8')).hexdigest()
                    # check if category exists
                    if xml_types.find(cur_type_hash) is None:
                        type = SubElement(xml_types, cur_type_hash)
                        SubElement(type, "name").text = u'Зарубежные сериалы'
                    if categories.find(cur_type_hash) is None:
                        SubElement(categories, cur_type_hash)

        # update info in progress dialog
        serial_found = serial_found + 1
        #except:
        #xbmc.log(formatExceptionInfo())

    return serial_found
Example #6
0
class MovieDB:
    #-- init
    def __init__(self, mode):
        #--
        Addon = xbmcaddon.Addon(id='plugin.video.igru.net.ua')
        self.path = os.path.join(Addon.getAddonInfo('path'), r'resources',
                                 r'data')

        today = date.today()
        #--
        if mode == 'UPDATE':
            #load current serial list
            try:
                self.tree = ElementTree()
                self.tree.parse(os.path.join(self.path, 'movies.xml'))
                self.xml = self.tree.getroot()
                self.xml.find("LAST_UPDATE").text = today.isoformat()
                self.movies = self.xml.find('MOVIES')
                self.types = self.xml.find('TYPES')
                self.years = self.xml.find('YEARS')
                self.info = "Update FEPCOM.NET Info"
                self.isUpdate = 1
                self.pinfo = self.xml.find("LOADED_PAGES")
            except:
                # create XML structure
                self.xml = Element("IGRU_NET_UA")
                SubElement(self.xml, "LAST_UPDATE").text = today.isoformat()
                self.movies = SubElement(self.xml, "MOVIES")
                self.types = SubElement(self.xml, "TYPES")
                self.years = SubElement(self.xml, "YEARS")
                self.info = "Reload FEPCOM.NET Info"
                self.isUpdate = 0
                self.pinfo = SubElement(self.xml, "LOADED_PAGES")
        elif mode == 'READ':
            self.tree = ElementTree()
            self.tree.parse(os.path.join(self.path, 'movies.xml'))
            self.xml = self.tree.getroot()
            self.last_update = self.xml.find("LAST_UPDATE").text
            self.movies = self.xml.find('MOVIES')
            self.types = self.xml.find('TYPES')
            self.years = self.xml.find('YEARS')
            self.info = "Update FEPCOM.NET Info"
            self.isUpdate = -1
            self.pinfo = self.xml.find("LOADED_PAGES")
            self.pinfo.text = ''
        else:
            # create XML structure
            self.xml = Element("IGRU_NET_UA")
            SubElement(self.xml, "LAST_UPDATE").text = today.isoformat()
            self.movies = SubElement(self.xml, "MOVIES")
            self.types = SubElement(self.xml, "TYPES")
            self.years = SubElement(self.xml, "YEARS")
            self.info = "Reload FEPCOM.NET Info"
            self.isUpdate = 0
            self.pinfo = SubElement(self.xml, "LOADED_PAGES")

    #-- system functions -------------------------------------------------------
    def getkey(self, elem):
        return elem.text

    def getkey_name(self, elem):
        return elem.findtext("name")

    def f_md5(self, str):
        rez = md5(str.encode('utf8'))
        return rez.hexdigest()

    def movie_sort_compare(self, a, b):
        return cmp(a['name'], b['name'])

    #-- check if movie exists --------------------------------------------------
    def Is_Movie_Exists(self, url):
        is_found = 0

        for rec in self.movies:
            if rec.find('url').text == url:
                is_found = 1
                break

        return is_found

    #-- get number of loaded pages ---------------------------------------------
    def Get_Loaded_Pages(self, id):
        try:
            pages = int(self.pinfo.find('r' + str(id)).text)
        except:
            pages = 0

        return pages

    #-- set number of loaded pages ---------------------------------------------
    def Set_Loaded_Pages(self, id, pages):
        try:
            self.pinfo.find('r' + str(id)).text = str(pages)
        except:
            SubElement(self.pinfo, 'r' + str(id)).text = str(pages)

    #-- save to file -----------------------------------------------------------
    def Save_to_XML(self):
        #-- sort serials/categories/years
        self.movies[:] = sorted(self.movies, key=self.getkey)
        self.types[:] = sorted(self.types, key=self.getkey_name)
        self.years[:] = sorted(self.years, key=self.getkey_name, reverse=True)
        #-- save to XML file
        ElementTree(self.xml).write(os.path.join(self.path, 'movies.xml'),
                                    encoding='utf-8')

    #-- add movie --------------------------------------------------------------
    def Add_Movie(self, movie):
        # add info to XML
        xml_movie_hash = 'mov_' + self.f_md5(movie['origin'] + movie['year'])
        #check if movie info exists
        xml_movie = self.movies.find(xml_movie_hash)
        if xml_movie is None:  #-- create new record
            # create serial record in XML
            xml_movie = SubElement(self.movies, xml_movie_hash)
            xml_movie.text = movie['name']
            SubElement(xml_movie, "origin").text = movie['origin']
            SubElement(xml_movie, "url").text = movie['url']
            SubElement(xml_movie, "genre").text = movie['genre']
            SubElement(xml_movie, "director").text = movie['director']
            SubElement(xml_movie, "actors").text = movie['actor']
            SubElement(xml_movie, "text").text = movie['descr']
            SubElement(xml_movie, "img").text = movie['image']
            # add year info
            SubElement(xml_movie, "year").text = movie['year']
            year_hash = self.Get_Movie_Year(movie['year'])
            # add movie category info
            SubElement(xml_movie, "categories")
            cat = xml_movie.find("categories")
            for cat_rec in movie['category']:
                cat_hash = self.Get_Movie_Type(cat_rec)
                if cat.find(cat_hash) is None:
                    SubElement(cat, cat_hash)

    #-- get type ---------------------------------------------------------------
    def Get_Movie_Type(self, type_name):
        #-- store movie's category in XML
        xml_type_hash = 'st_' + self.f_md5(type_name)
        # check if type exists
        type = self.types.find(xml_type_hash)
        if type is None:
            type = SubElement(self.types, xml_type_hash)
            SubElement(type, "name").text = type_name
        #--
        return xml_type_hash

    #-- get year ---------------------------------------------------------------
    def Get_Movie_Year(self, year_name):
        #-- store movie's year in XML
        xml_type_hash = 'yr_' + self.f_md5(year_name)
        # check if year exists
        year = self.years.find(xml_type_hash)
        if year is None:
            year = SubElement(self.years, xml_type_hash)
            SubElement(year, "name").text = year_name
        #--
        return xml_type_hash

    #-- get type list ----------------------------------------------------------
    def Get_List_Type(self):
        return self.types

    #-- get year list ---------------------------------------------------------
    def Get_List_Year(self):
        return self.years

    #-- get movie list ----------------------------------------------------------
    def Get_List_Movie(self, par_tag, par_year, par_type_hash):
        movie_list = []

        for rec in self.movies:
            #-- get movie info
            i = self.Get_Movie_Info(rec)

            if unicode(i['year']).isnumeric():
                i_year = int(i['year'])
            else:
                i_year = 0
            # checkout by category or name/year
            if par_tag <> '*' and par_tag <> '':
                if par_tag not in i['name']:
                    continue
            if par_year <> '':
                if int(par_year) <> i_year:
                    continue
            if par_type_hash <> '':
                if rec.find('categories').find(par_type_hash) is None:
                    continue

            movie_list.append(i)
        #-- sort list
        movie_list.sort(self.movie_sort_compare)

        return movie_list, len(movie_list)

    #---------- get movie info -----------------------------------------------------
    def Get_Movie_Info(self, rec):
        mi = []
        mi = {}
        #-- name
        mi['name'] = rec.text.encode('utf8')
        #-- origin name
        try:
            mi['origin'] = rec.find('origin').text.encode('utf8')
        except:
            mi['origin'] = ''
        #-- image
        try:
            mi['img'] = rec.find('img').text.encode('utf8')
        except:
            mi['img'] = ''
        #-- url
        try:
            mi['url'] = rec.find('url').text.encode('utf8')
        except:
            mi['url'] = ''
        #-- year
        try:
            mi['year'] = rec.find('year').text.encode('utf8')
        except:
            mi['year'] = ''
        if unicode(mi['year'].decode('utf8')).strip().isnumeric(): pass
        else:
            try:
                mi['year'] = re.compile('([0-9][0-9][0-9][0-9])', re.MULTILINE
                                        | re.DOTALL).findall(mi['year'])[0]
            except:
                mi['year'] = '0000'
        #-- genre
        try:
            mi['genre'] = rec.find('genre').text.encode('utf8')
        except:
            mi['genre'] = ''
        #-- director
        try:
            mi['director'] = rec.find('director').text.encode('utf8')
        except:
            mi['director'] = ''
        #-- actors
        try:
            mi['actors'] = rec.find('actors').text.encode('utf8')
        except:
            mi['actors'] = ''
        #-- description
        try:
            mi['text'] = rec.find('text').text.encode('utf8')
        except:
            mi['text'] = ''
        #-----
        return mi
Example #7
0
class MovieDB:
    #-- init
    def __init__(self, mode):
        #--
        Addon = xbmcaddon.Addon(id='plugin.video.igru.net.ua')
        self.path = os.path.join(Addon.getAddonInfo('path'), r'resources', r'data')

        today = date.today()
        #--
        if mode == 'UPDATE':
            #load current serial list
            try:
                self.tree = ElementTree()
                self.tree.parse(os.path.join(self.path, 'movies.xml'))
                self.xml = self.tree.getroot()
                self.xml.find("LAST_UPDATE").text = today.isoformat()
                self.movies  = self.xml.find('MOVIES')
                self.types   = self.xml.find('TYPES')
                self.years   = self.xml.find('YEARS')
                self.info = "Update FEPCOM.NET Info"
                self.isUpdate= 1
                self.pinfo   = self.xml.find("LOADED_PAGES")
            except:
                # create XML structure
                self.xml = Element("IGRU_NET_UA")
                SubElement(self.xml, "LAST_UPDATE").text = today.isoformat()
                self.movies  = SubElement(self.xml, "MOVIES")
                self.types   = SubElement(self.xml, "TYPES")
                self.years   = SubElement(self.xml, "YEARS")
                self.info = "Reload FEPCOM.NET Info"
                self.isUpdate= 0
                self.pinfo   = SubElement(self.xml, "LOADED_PAGES")
        elif mode == 'READ':
             self.tree = ElementTree()
             self.tree.parse(os.path.join(self.path, 'movies.xml'))
             self.xml = self.tree.getroot()
             self.last_update = self.xml.find("LAST_UPDATE").text
             self.movies  = self.xml.find('MOVIES')
             self.types   = self.xml.find('TYPES')
             self.years   = self.xml.find('YEARS')
             self.info = "Update FEPCOM.NET Info"
             self.isUpdate= -1
             self.pinfo   = self.xml.find("LOADED_PAGES")
             self.pinfo.text = ''
        else:
            # create XML structure
            self.xml = Element("IGRU_NET_UA")
            SubElement(self.xml, "LAST_UPDATE").text = today.isoformat()
            self.movies  = SubElement(self.xml, "MOVIES")
            self.types   = SubElement(self.xml, "TYPES")
            self.years   = SubElement(self.xml, "YEARS")
            self.info = "Reload FEPCOM.NET Info"
            self.isUpdate= 0
            self.pinfo   = SubElement(self.xml, "LOADED_PAGES")


    #-- system functions -------------------------------------------------------
    def getkey(self, elem):
        return elem.text

    def getkey_name(self, elem):
        return elem.findtext("name")

    def f_md5(self, str):
        rez = md5(str.encode('utf8'))
        return rez.hexdigest()

    def movie_sort_compare(self, a, b):
        return cmp(a['name'], b['name'])

    #-- check if movie exists --------------------------------------------------
    def Is_Movie_Exists(self, url):
        is_found = 0

        for rec in self.movies:
            if rec.find('url').text == url:
                is_found = 1
                break

        return is_found

    #-- get number of loaded pages ---------------------------------------------
    def Get_Loaded_Pages(self, id):
        try:
            pages = int(self.pinfo.find('r'+str(id)).text)
        except:
            pages = 0

        return pages

    #-- set number of loaded pages ---------------------------------------------
    def Set_Loaded_Pages(self, id, pages):
        try:
            self.pinfo.find('r'+str(id)).text = str(pages)
        except:
            SubElement(self.pinfo, 'r'+str(id)).text = str(pages)

    #-- save to file -----------------------------------------------------------
    def Save_to_XML(self):
        #-- sort serials/categories/years
        self.movies[:]  = sorted(self.movies, key=self.getkey)
        self.types[:]   = sorted(self.types,  key=self.getkey_name)
        self.years[:]   = sorted(self.years,  key=self.getkey_name, reverse=True)
        #-- save to XML file
        ElementTree(self.xml).write(os.path.join(self.path, 'movies.xml'), encoding='utf-8')

    #-- add movie --------------------------------------------------------------
    def Add_Movie(self, movie):
        # add info to XML
        xml_movie_hash = 'mov_' + self.f_md5(movie['origin'] + movie['year'])
        #check if movie info exists
        xml_movie = self.movies.find(xml_movie_hash)
        if xml_movie is None:   #-- create new record
            # create serial record in XML
            xml_movie = SubElement(self.movies, xml_movie_hash)
            xml_movie.text = movie['name']
            SubElement(xml_movie, "origin").text   = movie['origin']
            SubElement(xml_movie, "url").text      = movie['url']
            SubElement(xml_movie, "genre").text    = movie['genre']
            SubElement(xml_movie, "director").text = movie['director']
            SubElement(xml_movie, "actors").text   = movie['actor']
            SubElement(xml_movie, "text").text     = movie['descr']
            SubElement(xml_movie, "img").text      = movie['image']
            # add year info
            SubElement(xml_movie, "year").text     = movie['year']
            year_hash = self.Get_Movie_Year(movie['year'])
            # add movie category info
            SubElement(xml_movie, "categories")
            cat = xml_movie.find("categories")
            for cat_rec in movie['category']:
                cat_hash = self.Get_Movie_Type(cat_rec)
                if cat.find(cat_hash) is None:
                    SubElement(cat, cat_hash)

    #-- get type ---------------------------------------------------------------
    def Get_Movie_Type(self, type_name):
        #-- store movie's category in XML
        xml_type_hash = 'st_'+self.f_md5(type_name)
        # check if type exists
        type = self.types.find(xml_type_hash)
        if type is None:
            type = SubElement(self.types, xml_type_hash)
            SubElement(type, "name").text = type_name
        #--
        return xml_type_hash

    #-- get year ---------------------------------------------------------------
    def Get_Movie_Year(self, year_name):
        #-- store movie's year in XML
        xml_type_hash = 'yr_'+self.f_md5(year_name)
        # check if year exists
        year = self.years.find(xml_type_hash)
        if year is None:
            year = SubElement(self.years, xml_type_hash)
            SubElement(year, "name").text = year_name
        #--
        return xml_type_hash

    #-- get type list ----------------------------------------------------------
    def Get_List_Type(self):
        return self.types

     #-- get year list ---------------------------------------------------------
    def Get_List_Year(self):
        return self.years

     #-- get movie list ----------------------------------------------------------
    def Get_List_Movie(self, par_tag, par_year, par_type_hash):
        movie_list = []

        for rec in self.movies:
            #-- get movie info
            i = self.Get_Movie_Info(rec)

            if unicode(i['year']).isnumeric():
                i_year      = int(i['year'])
            else:
                i_year      = 0
            # checkout by category or name/year
            if par_tag <> '*' and par_tag <> '':
                if par_tag not in i['name']:
                        continue
            if par_year <> '':
                if int(par_year) <> i_year:
                    continue
            if par_type_hash <> '':
                if rec.find('categories').find(par_type_hash) is None:
                    continue

            movie_list.append(i)
        #-- sort list
        movie_list.sort(self.movie_sort_compare)

        return movie_list, len(movie_list)

    #---------- get movie info -----------------------------------------------------
    def Get_Movie_Info(self, rec):
        mi = []
        mi = {}
        #-- name
        mi['name']     = rec.text.encode('utf8')
        #-- origin name
        try:    mi['origin']      = rec.find('origin').text.encode('utf8')
        except: mi['origin']      = ''
        #-- image
        try:    mi['img']          = rec.find('img').text.encode('utf8')
        except: mi['img']          = ''
        #-- url
        try:    mi['url']          = rec.find('url').text.encode('utf8')
        except: mi['url']          = ''
        #-- year
        try:    mi['year']         = rec.find('year').text.encode('utf8')
        except: mi['year']         = ''
        if unicode(mi['year'].decode('utf8')).strip().isnumeric(): pass
        else:
            try:
                mi['year'] = re.compile('([0-9][0-9][0-9][0-9])', re.MULTILINE|re.DOTALL).findall(mi['year'])[0]
            except:
                mi['year']= '0000'
        #-- genre
        try:    mi['genre']        = rec.find('genre').text.encode('utf8')
        except: mi['genre']        = ''
        #-- director
        try:    mi['director']     = rec.find('director').text.encode('utf8')
        except: mi['director']     = ''
        #-- actors
        try:    mi['actors']       = rec.find('actors').text.encode('utf8')
        except: mi['actors']       = ''
        #-- description
        try:    mi['text']         = rec.find('text').text.encode('utf8')
        except: mi['text']         = ''
        #-----
        return mi
    #---------------------------------------------------------------------------
Example #8
0
File: default.py Project: serbra/ru
def Save_Last_Serial_Info(tag, serial, serial_url, img, part):
    # get max history lenght
    try:
        max_history = (1, 5, 10, 20, 30,
                       50)[int(Addon.getSetting('history_len'))]
        if max_history > 99:
            max_history = 99
    except:
        max_history = 10

    sdate = today = date.today().isoformat()

    # load or create history file
    try:
        tree = ElementTree()
        tree.parse(
            os.path.join(Addon.getAddonInfo('path'), r'resources', r'data',
                         r'history.xml'))
        xml1 = tree.getroot()
    except:
        # create XML structure
        xml1 = Element("SERIALU_NET_HISTORY")

    # shrink history to limit
    if len(xml1) > max_history:
        idx = 1
        for rec in xml1:
            if idx >= max_history:
                xml1.remove(rec)
            idx = idx + 1

    # format name
    if part.find('[/COLOR]') > -1:
        part = re.compile('[COLOR FF00FF00](.+?)[/COLOR]',
                          re.MULTILINE | re.DOTALL).find(part)

    xml_hist = None
    # update sequince number for history records
    for rec in xml1:
        if rec.tag == tag:
            rec.find("ID").text = str(0).zfill(2)
            xml_hist = rec
        else:
            rec.find("ID").text = str(int(rec.find("ID").text) + 1).zfill(2)

    if xml_hist == None:
        xml_hist = SubElement(xml1, tag)
        SubElement(xml_hist, "ID").text = str(0).zfill(2)
        SubElement(xml_hist, "Serial").text = unescape(serial)
        SubElement(xml_hist, "URL").text = serial_url
        SubElement(xml_hist, "Date").text = sdate
        SubElement(xml_hist, "Part").text = unescape(part)
        SubElement(xml_hist, "Image").text = img
    else:
        xml_hist.find("Part").text = unescape(part)
        xml_hist.find("Date").text = sdate

    # sort history by IDs
    xml1[:] = sorted(xml1, key=getkey)

    ElementTree(xml1).write(os.path.join(Addon.getAddonInfo('path'),
                                         r'resources', r'data',
                                         r'history.xml'),
                            encoding='utf-8')