Exemple #1
0
    def load_from_xmltv(self, channel_id, day_text):
        '''

		'''
        var_url = urlopen('https://xmltv.xmltv.se/' + channel_id + '_' +
                          day_text + '.xml')
        epg_xml = parse(var_url)
        result = []
        count = 0
        for programme in epg_xml.iterfind('programme'):
            provider = self.get_attrib(programme, 'channel')
            start = self.string_to_timestamp(
                self.get_attrib(programme, 'start'))
            stop = self.string_to_timestamp(self.get_attrib(programme, 'stop'))
            title = self.get_text(programme.find('title'), '')
            desc = self.get_text(programme.find('desc'), '')
            category = self.get_text(programme.find('category'), '')
            episode = programme.find('episode-num')
            episode_num = None
            channel_info = self.search_channel_info(provider)
            url = None
            media_type = None
            if channel_info:
                url = channel_info['url']
                media_type = channel_info['mediatype']
            if episode:
                num_system = self.get_attrib(episode, 'system')
                if num_system == 'xmltv_ns':
                    episode_num = self.get_text(episode)

            count += 1

            plugin_name = self.plugin_names[0]
            self.providers.add(provider)
            self.categories.add(category)
            new_movie = Movie(source=plugin_name,
                              source_type=defaults.MOVIE_TYPE_STREAM,
                              provider=provider,
                              category=category,
                              title=title,
                              timestamp=str(int(start)),
                              duration=stop - start,
                              description=desc,
                              url=url)
            new_movie.add_stream(media_type, '', url)
            if not plugin_name in self.movies:
                self.movies[plugin_name] = {}
            self.movies[plugin_name][new_movie.uri()] = new_movie
            movie_info = MovieInfo.movie_to_movie_info(new_movie, category)
            movie_info['recordable'] = True
            result.append(movie_info)
        print("epg loaded, {0} entries".format(count))
        return result
	def loadChannels(self):
		plugin_name=self.plugin_names[0]
		source_type=defaults.MOVIE_TYPE_STREAM
		try:
			with open(os.path.join(	self.origin_dir,self.config.read('channel_file'))) as fd:
				root = xmltodict.parse(fd.read())
				for track in root['playlist']['trackList']['track']:
					provider=track['title']
					#print (track['album'])
					location=track['location']
					url_st=urlparse(location)
					full_url = urlunparse((
							#url_st.scheme,
							self.config.read('scheme'),
							#url_st.netloc,
							self.config.read('netloc'),
							url_st.path,
							url_st.params,
							url_st.query,
							url_st.fragment,
					))
					#print(full_url)



					self.providers.add(provider)
					new_movie = Movie(
						source=plugin_name,
						source_type=source_type,
						provider=provider,
						category='live',
						title=provider+" Live",
						timestamp="0",
						duration=0,
						description='',
						url=full_url
					)
					new_movie.add_stream('ts','',full_url)
					if not plugin_name in self.movies:
						self.movies[plugin_name]={}
					self.movies[plugin_name][new_movie.uri()]=new_movie


		except Exception as e:
			print(str(e))
Exemple #3
0
	def loadChannels(self):
		for server in self.serverConfig:
			try:
				f = requests.get(server['url'])
				content=f.text
				match = re.search(r'<ol class="items">(.*)</ol>',content,re.DOTALL)
				if match:
					lines=match.group(1).split('\n')
					item_regex=re.compile(r'<li value=".*"><a href="(.*)" vod  tvid=".*">(.*)</a>')
					plugin_name=self.plugin_names[0]
					source_type=defaults.MOVIE_TYPE_STREAM
					with self.lock:
						for line in lines:
							item_match=re.search(item_regex,line)
							if item_match:
								full_url=urljoin(server['url'],item_match.group(1))
								provider=item_match.group(2)
								self.providers.add(provider)
								new_movie = Movie(
									source=plugin_name,
									source_type=source_type,
									provider=provider,
									category='live',
									title=provider+" Live",
									timestamp="0",
									duration=0,
									description='',
									url=full_url
								)
								new_movie.add_stream('ts','',item_match.group(1))
								if not plugin_name in self.movies:
									self.movies[plugin_name]={}
								self.movies[plugin_name][new_movie.uri()]=new_movie


			except Exception as e:
				print(str(e))
    def load_filmlist(self, file_name):
        print(os.path.abspath(file_name))
        try:  # does the file exist at all already?
            filmlist_time_stamp = os.path.getmtime(file_name)
        except:
            filmlist_time_stamp = 0
        print("timestamp", filmlist_time_stamp, time.time())
        if filmlist_time_stamp < time.time(
        ) - 60 * 60 * 48:  # file is older as 48 hours
            print("Retrieve film list")
            try:
                var_url = urlopen('https://res.mediathekview.de/akt.xml')
                server_list = parse(var_url)
                print(server_list)
                url = None
                prio = 999  # dummy start value
                for item in server_list.iterfind('Server'):
                    this_prio = int(item.findtext('Prio'))
                    if this_prio < prio:  # filter for the server with the lowest prio
                        prio = this_prio
                        url = item.findtext('URL')
                        print(url)
                        print(prio)
                        print()
                if url:
                    try:
                        urlretrieve(url, file_name + '.pack')
                    except Exception as e:
                        print('failed filmlist download', str(e))
                    try:
                        with open(file_name, 'wb') as unpack_file_handle:
                            unpack_file_handle.write(
                                lzma.open(file_name + '.pack').read())
                    except Exception as e:
                        print('failed filmlist unpack', str(e))

            except Exception as e:
                print('failed filmlist server list download')
        loader_remember_data = {'provider': '', 'category': ''}
        '''
		Bootstrap to read the filmlist:
		1. read the list of actual filmlist URLs from https://res.mediathekview.de/akt.xml
		'''

        #with open('/home/steffen//Desktop/workcopies/schnipsl/Filmliste-akt') as data:
        with open(file_name) as data:
            count = 0
            for liste in JsonSlicer(data, ('X'), path_mode='map_keys'):
                count += 1
                data_array = liste[1]
                # "Sender"	0,
                # "Thema" 	1,
                # "Titel"	2,
                # "Datum"	3,
                # "Zeit"	4,
                # "Dauer"	5,
                # "Größe [MB]"	6,
                # "Beschreibung"	7,
                # "Url"				8,
                # "Website"			9,
                # "Url Untertitel"	10,
                # "Url RTMP"		11,
                # "Url Klein"		12,
                # "Url RTMP Klein"	13,
                # "Url HD"			14,
                # "Url RTMP HD"		15,
                # "DatumL"			16,
                # "Url History"		17,
                # "Geo"				18,
                # "neu"				19
                provider = data_array[0]
                category = data_array[1]
                if provider:
                    loader_remember_data['provider'] = provider
                else:
                    provider = loader_remember_data['provider']
                if category:
                    loader_remember_data['category'] = category
                else:
                    category = loader_remember_data['category']
                if category == 'Livestream':
                    source_type = defaults.MOVIE_TYPE_STREAM
                    plugin_name = self.plugin_names[1]
                    provider = provider.replace('Livestream', '').strip()
                    #print("Livestream")
                else:
                    plugin_name = self.plugin_names[0]
                    source_type = defaults.MOVIE_TYPE_RECORD
                self.providers.add(provider)
                new_movie = Movie(source=plugin_name,
                                  source_type=source_type,
                                  provider=provider,
                                  category=category,
                                  title=data_array[2],
                                  timestamp=data_array[16],
                                  duration=self.time_string_to_secs(
                                      data_array[5]),
                                  description=data_array[7],
                                  url=data_array[8])
                new_movie.add_stream('mp4', '', data_array[8])
                if not plugin_name in self.movies:
                    self.movies[plugin_name] = {}
                self.movies[plugin_name][new_movie.uri()] = new_movie

        print("filmlist loaded, {0} entries", count)
Exemple #5
0
    def get_epg_from_linvdr(self, provider, url):
        # reduce the pids to the ones containing SDT (0x11) and EIT (0x12)
        print('original URL:', url)
        url_st = urlparse(url)
        queries = url_st.query
        new_queries = ""
        if queries:
            for eq in queries.split("&"):
                key = eq.split("=")[0]
                value = eq.split("=")[1]
                if key == 'pids':
                    value = "0,17,18"
                new_queries += key + "=" + value + "&"
        new_queries = new_queries.strip("&")
        url = urlunparse((
            url_st.scheme,
            url_st.netloc,
            url_st.path,
            url_st.params,
            new_queries,
            url_st.fragment,
        ))

        attr = [
            os.path.join(self.origin_dir, 'epg_grap.sh'), url, provider,
            str(self.config.read('epgloops')),
            str(self.config.read('epgtimeout'))
        ]  # process arguments
        print("epg_grap started", provider, url, repr(attr))
        try:
            self.process = subprocess.Popen(attr,
                                            stdout=subprocess.PIPE,
                                            stderr=subprocess.PIPE)
            cleaner = Timer(
                600, self.cleanProcess
            )  # if epg_grap won't exit, try to terminate its process in 30 seconds
            cleaner.start()
            epg_out, err = self.process.communicate()
            #self.process.wait() # oops... not needed? harmless!
            cleaner.cancel()
            if err:
                print("epg_grap ended with an error:\n%s" % (err))
            else:
                print("epg_grap' ended")
                epg_json_string = epg_out.decode()
                epg_json = json.loads(epg_json_string)
                result = {}
                count = 0
                for json_movie in epg_json['details'].values():
                    start = json_movie['unixTimeBegin']
                    stop = json_movie['unixTimeEnd']
                    if json_movie['title']:
                        title = json_movie['title'] + ' - ' + json_movie['name']
                    else:
                        title = json_movie['name']
                    desc = json_movie['description']
                    category = ''
                    count += 1

                    # we'll use the name of the stream source plugin instead the name of the EPG plugin itself
                    # plugin_name = self.plugin_names[0]
                    plugin_name = self.stream_source
                    self.providers.add(provider)
                    self.categories.add(category)
                    new_movie = Movie(source=plugin_name,
                                      source_type=defaults.MOVIE_TYPE_STREAM,
                                      provider=provider,
                                      category=category,
                                      title=title,
                                      timestamp=str(int(start)),
                                      duration=stop - start,
                                      description=desc,
                                      url=url)
                    new_movie.add_stream('ts', '', url)
                    if not plugin_name in self.movies:
                        self.movies[plugin_name] = {}
                    self.movies[plugin_name][new_movie.uri()] = new_movie
                    movie_info = MovieInfo.movie_to_movie_info(
                        new_movie, category)
                    movie_info['recordable'] = True
                    result[start] = movie_info
                print("epg loaded, {0} entries".format(count))
                return result
        except Exception as ex:
            print("epg_grap could not be started. Error: %s" % (ex))
        return