Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
25e01d13b0 | ||
|
ea63642b05 | ||
|
0827e17940 | ||
|
b871dbf76a | ||
|
1dd5de61e1 | ||
|
bc002b4d14 |
4065
Channel.json
4065
Channel.json
File diff suppressed because it is too large
Load Diff
29
LICENSE
29
LICENSE
@ -1,29 +0,0 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2017, wonipapa
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
263
README.md
263
README.md
@ -1,262 +1 @@
|
||||
## 변경사항
|
||||
### Version 2.0.0
|
||||
Python3.7 용으로 수정
|
||||
SKB 용으로 채널 정보 수정 및 id는 skb 채널 번호로 수정
|
||||
PHP 파일 삭제
|
||||
|
||||
|
||||
|
||||
# 원본 메시지 아래
|
||||
-- 아래
|
||||
# 공지
|
||||
리포지터리 삭제되었습니다
|
||||
|
||||
# EPG2XML
|
||||
이 프로그램은 EPG(Electronic Program Guide)를 웹상의 여러 소스에서 가져와서 XML로 출력하는 프로그램으로 python2.7 및 php5.4.45 이상에서 사용 가능하도록 제작되었다.
|
||||
python3과 php 5.4.45 이하에서는 정상적인 작동을 보장하지 못한다. 또한 외부의 소스를 분석하여 EPG 정보를 가공하여 보여주는 것이므로 외부 소스 사이트가 변경되거나 삭제되면 문제가 발생할 수 있다.
|
||||
|
||||
## 개발자 후원하기
|
||||
https://www.facebook.com/chericface
|
||||
페이스북을 사용하신다면 개발자 후원하는 방법이라고 생각해주시고 위의 링크 들어가서 좋아요 눌러주시면 감사하겠습니다.
|
||||
제가 관련된 곳에서 운영하는 페이스북인데 아직 초기라서 사람이 많이 없습니다. 화학공학 및 소재 관련 사이트입니다.
|
||||
감사합니다.
|
||||
|
||||
## 필요 모듈
|
||||
|
||||
### epg2xml.py
|
||||
BeautifulSoup(bs4), lxml, requests 모듈이 추가로 필요하다.
|
||||
설치 OS별로 모듈을 설치하기 위한 사전 설치 방법이 다를 수도 있으므로 검색해서 설치하도록 한다.
|
||||
pip install beautifulsoup4, pip install lxml, pip install requests 로 추가할 수 있다.
|
||||
* easy_install로 설치시 모듈이 인식되지 않는 경우가 있으므로 pip로 설치하기를 권한다.
|
||||
|
||||
### epg2xml.php
|
||||
json, dom, mbstring, openssl, curl 모듈이 필요하다. 일반적으로 PHP가 설치되어 있다면 대부분 설치되어 있는 모듈이나 설치되어 있지 않을 경우 추가로 설치해야 한다.
|
||||
|
||||
### epg2xml-web.php
|
||||
epg2xml.php와 동일하다.
|
||||
|
||||
## 설정방법
|
||||
### epg2xml.json
|
||||
epg2xml.json 안의 항목이 설정 가능한 항목이다.
|
||||
<pre>
|
||||
MyISP : 사용하는 ISP를 넣는다 .(ALL, KT, LG, SK가 사용가능하다)
|
||||
MyChannels : EPG 정보를 가져오고자 하는 채널 ID를 넣는다. ("1, 2, 3, 4" 또는 "1,2,3,4")
|
||||
output : EPG 정보 출력방향 (d: 화면 출력, o: 파일 출력, s:소켓출력)
|
||||
default_icon_url : 채널별 아이콘이 있는 url을 설정할 수 있다. 아이콘의 이름은 json 파일에 있는 Id.png로 기본설정되어 있다.
|
||||
default_rebroadcast : 제목에 재방송 정보 출력
|
||||
default_episode : 제목에 회차정보 출력
|
||||
default_verbose : EPG 정보 상세 출력
|
||||
default_xmltvns : 에피소드 정보 표시 방법
|
||||
default_fetch_limit : EPG 데이터 가져오는 기간.
|
||||
default_xml_filename : EPG 저장시 기본 저장 이름으로 tvheadend 서버가 쓰기가 가능한 경로로 설정해야 한다.
|
||||
default_xml_socket : External XMLTV 사용시 xmltv.sock가 있는 경로로 설정해준다.
|
||||
</pre>
|
||||
|
||||
### Channel.json
|
||||
Channel.json 파일의 최신버전은 https://github.com/wonipapa/Channel.json 에서 다운받을 수 있다.
|
||||
Channel.json 파일을 텍스트 편집기로 열어보면 각채널별 정보가 들어 있다.
|
||||
|
||||
## 옵션 소개
|
||||
### epg2xml.py, epg2xml.php 옵션
|
||||
실행시 사용가능한 인수는 --help 명령어로 확인이 가능하다.
|
||||
epg2xml.json의 설정을 옵션의 인수를 이용하여 변경할 수 있다.
|
||||
<pre>
|
||||
-h --help : 도움말 출력
|
||||
--version : 버전을 보여준다.
|
||||
-i : IPTV 선택 (ALL, KT, SK, LG 선택가능) ex) -i KT
|
||||
-d --display : EPG 정보를 화면으로 보여준다.
|
||||
-o --outfile : EPG 정보를 파일로 저장한다. ex) -o xmltv.xml
|
||||
-s --socket : EPG 정보를 xmltv.sock로 전송한다. ex) -s /var/run/xmltv.sock
|
||||
-l --limit : EPG 정보 가져올 기간으로 기본값은 2일이며 최대 7일까지 설정 가능하다. ex) -l 2
|
||||
--icon : 채널 icon 위치 URL ex) --icon http://www.example.com
|
||||
--rebroadcast : 제목에 재방송정보 표기 ex) --rebroadcast y
|
||||
--episode : 제목에 회차정보 표기 ex) --episode y
|
||||
--verbose : EPG 정보 상세하게 표기 ex) --verbose y
|
||||
</pre>
|
||||
|
||||
### epg2xml-web.php 옵션
|
||||
실행시 사용가능한 인수는 epg2xml.php?help 명령어로 확인이 가능하다.
|
||||
epg2xml.json의 설정을 옵션의 인수를 이용하여 변경할 수 있다.
|
||||
ex : http://domain/epg2xml.php?i=ALL&l=2
|
||||
|
||||
## 사용방법
|
||||
|
||||
### tv_grab_file 사용시 (https://github.com/nurtext/tv_grab_file_synology)
|
||||
tv_grab_file 안의 cat xmltv.xml 또는 wget 이 있는 부분을 아래와 같이 변경해준다.
|
||||
python 경로와 php의 경로는 /usr/bin에 있고, epg2xml 파일은 /home/hts에 있는 것으로 가정했다.
|
||||
이 경우 epg2xml.json의 output을 d로 해야 한다.
|
||||
#### PYTHON의 경우
|
||||
<pre>
|
||||
/usr/bin/python /home/hts/epg2xml.py 또는
|
||||
/home/hts/epg2xml.py
|
||||
</pre>
|
||||
|
||||
#### PHP CLI의 경우
|
||||
<pre>
|
||||
/usr/bin/php /home/hts/epg2xml.php 또는
|
||||
/home/hts/epg2xml.php
|
||||
</pre>
|
||||
|
||||
#### PHP WEB의 경우
|
||||
<pre>
|
||||
wget -O - http://www.examle.com/epg2xml-web.php 또는
|
||||
wget -O - http://www.example.com/epg2xml-web.php?i=ALL&l=2
|
||||
</pre>
|
||||
|
||||
### XMLTV SOCKET 사용시
|
||||
**xmltv.sock 사용시 socat 등을 사용하지 않고 바로 socket에 쓰기가 가능하다**
|
||||
|
||||
#### PYTHON의 경우
|
||||
<pre>
|
||||
/usr/bin/python /home/hts/epg2xml.py 또는
|
||||
/home/hts/epg2xml.py
|
||||
</pre>
|
||||
|
||||
#### PHP CLI의 경우
|
||||
<pre>
|
||||
/usr/bin/php /home/hts/epg2xml.php 또는
|
||||
/home/hts/epg2xml.php
|
||||
</pre>
|
||||
|
||||
#### PHP WEB의 경우
|
||||
php web 버전은 xmltv.sock을 지원하지 않는다.
|
||||
|
||||
## 라이센스
|
||||
BSD 3-clause "New" or "Revised" License
|
||||
|
||||
## WIKI
|
||||
https://github.com/wonipapa/epg2xml/wiki
|
||||
|
||||
## FAQ
|
||||
https://github.com/wonipapa/epg2xml/wiki/FAQ
|
||||
|
||||
## 변경사항
|
||||
### Version 1.2.6
|
||||
- SKB 함수 버그 수정
|
||||
- KT, LG, SK, SKB, NAVER 이외의 함수 삭제
|
||||
### Version 1.2.5
|
||||
- SKB 함수 수정
|
||||
- SKB 함수 수정(p1)
|
||||
- SKY 함수 수정(p2)
|
||||
- HCN 함수 삭제(p3)
|
||||
### Version 1.2.4
|
||||
- ISCS 함수 수정
|
||||
- SKB 함수 수정(p1)
|
||||
### Version 1.2.3
|
||||
- PHP 버전통합
|
||||
- PYTHON 버전 html Parser 변수 추가(libxml지원안하는 기기 편의 지원)
|
||||
- everyontv 함수 추가
|
||||
- Channel.json Enabled 항목 제거
|
||||
- 에피소드 넘버 xmltv_ns 옵션 항목 추가 (epg2xml.json)
|
||||
- 가져오는 날짜 최대 7일로 변경
|
||||
- KT 함수 수정
|
||||
- PHP 버전 socket 사용시 화면에 출력되는 문제 해결(p1)
|
||||
- PHP 버전 한글 깨지는 문제 수정(p2)
|
||||
- SK 함수 수정(p3)
|
||||
- 이터레이션 수정(p4)
|
||||
- oksusu함수 추가(p4)
|
||||
- PHP 버전 Pooq함수 복구(p5)
|
||||
### Version 1.2.2
|
||||
- My Channel 추가
|
||||
- 소스 추가
|
||||
- 에피소드 넘버 xmltv_ns 추가
|
||||
- PHP 공용함수 분리
|
||||
- POOQ 함수 기간에 관계없이 하루만 가져오는 것 수정
|
||||
- ISCS 함수 수정
|
||||
- HCN 함수 수정
|
||||
### Version 1.2.1
|
||||
- SKB 함수 추가
|
||||
- 가져오는 날짜 최대 2일로 변경
|
||||
- 타이틀이 1부, 2부 등 을 포함할 때 1부, 2부를 서브타이틀로 이동
|
||||
- Channel.json release date 삭제
|
||||
- Channel.json 채널 기본 설정 Enalble 0으로 변경
|
||||
- Channel 소스 변경
|
||||
- GCN 채널 삭제
|
||||
- readme.txt Readme.md로 통합
|
||||
### Version 1.2.0
|
||||
- 커넥션 관련 에러 예외 처리 추가
|
||||
- 채널 소스 변경
|
||||
- Channel.json release date 추가
|
||||
### Version 1.1.9
|
||||
- 언어 버전 사항 체크
|
||||
- 필요 모듈 사항 체크
|
||||
- 버그 수정
|
||||
- php 버전 웹 버전 추가
|
||||
- php 버전 file_get_contents를 curl 사용으로 수정
|
||||
### Version 1.1.8
|
||||
- KBS 함수 추가
|
||||
- 채널 변경 사항 반영
|
||||
- 스카이라이프 url 변경
|
||||
- EPG 누락 데이터 수정
|
||||
### Version 1.1.7
|
||||
- PHP 7.0 지원
|
||||
- 채널 변경 사항 반영
|
||||
- 라디오 채널 추가
|
||||
### Version 1.1.6
|
||||
- iptv 선택 항목에 ALL 추가
|
||||
- 에피소드 넘버 출력 수정
|
||||
- 시작 시간 에러 출력 수정
|
||||
- 타이틀 출력 수정
|
||||
- 서브타이틀 추출 수정
|
||||
- 데이터 중복 출력 문제 수정
|
||||
- php 버전이 5.6.3 이전일 때 DOM access 관련 에러 수정
|
||||
### Version 1.1.5
|
||||
- inline 변수 재추가
|
||||
### Version 1.1.4
|
||||
- epg2xml.json 파일 도입
|
||||
- inline 변수 삭제
|
||||
- PHP 버전 추가
|
||||
- 버그 수정
|
||||
### Version 1.1.3
|
||||
- 제목에 회차정보, 재방송 정보 추가시 오류 수정
|
||||
### Version 1.1.2
|
||||
- 재방송정보, 회차정보 옵션 추가
|
||||
### Version 1.1.1
|
||||
- sk 카테고리 오류 수정
|
||||
### Version 1.1.0
|
||||
- 채널 아이콘 추가
|
||||
- 오류 메시지 통합
|
||||
### Version 1.0.9
|
||||
- 소켓파일이 없을 때 오류 추가
|
||||
- 채널 변경 사항 반영
|
||||
### Version 1.0.8
|
||||
- 정지 시간 추가
|
||||
- 오류 출력 구문 디버그시만 출력으로 변경
|
||||
- 채널 소스 변경
|
||||
### Version 1.0.7
|
||||
- urllib2를 requests로 변경
|
||||
- User Agent 변경
|
||||
- 오류 처리 추가
|
||||
- 채널 변경 사항 반영
|
||||
- 채널 소스 변경
|
||||
- 지역 지상파 채널 추가
|
||||
### Version 1.0.6
|
||||
- urllib를 urllib2로 변경
|
||||
- User Agent 추가
|
||||
- 채널 변경 사항 반영
|
||||
### Version 1.0.5
|
||||
- epg.co.kr의 epg 정보 못가져오는 것 수정
|
||||
### Version 1.0.4
|
||||
- KODI에서 사용가능하도록 수정
|
||||
- 제목에서 서브타이틀 및 회차 분리
|
||||
- 서브타이틀 추가
|
||||
- 출연, 제작진 개인별로 분리
|
||||
### Version 1.0.3
|
||||
- Channel.json 파일 오류 수정
|
||||
- LG를 소스로 하는 EPG 정보 기간 오류 수정
|
||||
### Version 1.0.2
|
||||
- ISP별 분리된 채널통합
|
||||
- 개별 채널별 EPG 정보 수집가능하도록 Enabled 추가
|
||||
- getMyChannel 함수 삭제
|
||||
- 채널 변경 사항 반영
|
||||
- KT TRU TV 채널 삭제
|
||||
- ISP 선택 설정 추가
|
||||
- EPG 정보 가져오는 기간 설정 추가
|
||||
- 채널 아이콘 설정 URL 설정 추가
|
||||
- tvheadend 전용 카테고리 추가
|
||||
### Version 1.0.1
|
||||
- EPG 소스 변경
|
||||
- 등록된 채널 정보만 EPG 정보 가져오도록 설정
|
||||
- IPTV별 개인화
|
||||
### Version 1.0.0
|
||||
- first release
|
||||
Channel.json 파일및 Channel.json 리포지터리는 5월 1일부로 삭제하도록 하겠습니다.
|
||||
|
30
epg2xml.json
30
epg2xml.json
@ -1,30 +0,0 @@
|
||||
{
|
||||
"###_COMMENT_###" : "",
|
||||
"###_COMMENT_###" : "epg 정보를 가져오는 설정 파일",
|
||||
"###_COMMENT_###" : "사용하는 ISP 선택 (ALL, KT, LG, SK)",
|
||||
"MyISP": "SK",
|
||||
"###_COMMENT_###" : "### # My Channel EPG 정보 가져오는 채널 ID ###",
|
||||
"###_COMMENT_###" : "### 채널 ID를 , 로 구분하여 입력 ###",
|
||||
"###_COMMENT_###" : "output 셋팅은 (d, o, s) 셋중에 하나로 선택한다",
|
||||
"###_COMMENT_###" : " d - EPG 정보 화면 출력",
|
||||
"###_COMMENT_###" : " o - EPG 정보 파일로 저장",
|
||||
"###_COMMENT_###" : " s - EPG 정보 소켓으로 출력",
|
||||
"output": "s",
|
||||
"###_COMMENT_###" : "### TV channel icon url (ex : http://www.example.com/Channels) ###",
|
||||
"default_icon_url": "",
|
||||
"###_COMMENT_###" : "### 제목에 재방송 정보 출력 ###",
|
||||
"default_rebroadcast": "n",
|
||||
"###_COMMENT_###" : "#### 제목에 회차정보 출력 ###",
|
||||
"default_episode" : "y",
|
||||
"###_COMMENT_###" : "### EPG 정보 추가 출력 ###",
|
||||
"default_verbose" : "y",
|
||||
"###_COMMENT_###" : "### XMLTV_NS 정보 추가 출력 ###",
|
||||
"default_xmltvns" : "n",
|
||||
"###_COMMENT_###" : "### epg 데이터 가져오는 기간으로 1에서 7까지 설정가능 ###",
|
||||
"default_fetch_limit" : "4",
|
||||
"###_COMMENT_###" : "### epg 저장시 기본 저장 이름 (ex: /home/tvheadend/xmltv.xml) ###",
|
||||
"default_xml_file" : "xmltv.xml",
|
||||
"###_COMMENT_###" : "### # External XMLTV 사용시 기본 소켓 이름 (ex: /home/tvheadend/xmltv.sock) ###",
|
||||
"default_xml_socket" : "/sock/xmltv.sock",
|
||||
"###_COMMENT_###" : ""
|
||||
}
|
665
epg2xml.py
665
epg2xml.py
@ -1,665 +0,0 @@
|
||||
#!/usr/bin/env python3.7
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import print_function
|
||||
import importlib.util
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import locale
|
||||
import datetime
|
||||
import codecs
|
||||
import socket
|
||||
import re
|
||||
from xml.sax.saxutils import escape, unescape
|
||||
import argparse
|
||||
import pprint
|
||||
from functools import partial
|
||||
import time
|
||||
try:
|
||||
importlib.util.find_spec('bs4')
|
||||
from bs4 import BeautifulSoup, SoupStrainer
|
||||
except ImportError:
|
||||
print("Error : ", "BeautifulSoup 모듈이 설치되지 않았습니다.", file=sys.stderr)
|
||||
sys.exit()
|
||||
try:
|
||||
importlib.util.find_spec('lxml')
|
||||
from lxml import html
|
||||
except ImportError:
|
||||
print("Error : ", "lxml 모듈이 설치되지 않았습니다.", file=sys.stderr)
|
||||
sys.exit()
|
||||
try:
|
||||
importlib.util.find_spec('requests')
|
||||
import requests
|
||||
except ImportError:
|
||||
print("Error : ", "requests 모듈이 설치되지 않았습니다.", file=sys.stderr)
|
||||
sys.exit()
|
||||
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
sys.stdin.reconfigure(encoding='utf-8')
|
||||
|
||||
# if not sys.version_info[:2] == (2, 7):
|
||||
# print("Error : ", "python 2.7 버전이 필요합니다.", file=sys.stderr)
|
||||
# sys.exit()
|
||||
|
||||
# Set variable
|
||||
__version__ = '2.0.0'
|
||||
debug = False
|
||||
today = datetime.date.today()
|
||||
ua = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116'}
|
||||
timeout = 5
|
||||
htmlparser = 'lxml'
|
||||
CHANNEL_ERROR = ' 존재하지 않는 채널입니다.'
|
||||
CONTENT_ERROR = ' EPG 정보가 없습니다.'
|
||||
HTTP_ERROR = ' EPG 정보를 가져오는데 문제가 있습니다.'
|
||||
SOCKET_ERROR = 'xmltv.sock 파일을 찾을 수 없습니다.'
|
||||
JSON_FILE_ERROR = 'json 파일을 읽을 수 없습니다.'
|
||||
JSON_SYNTAX_ERROR = 'json 파일 형식이 잘못되었습니다.'
|
||||
|
||||
# Get epg data
|
||||
def getEpg():
|
||||
Channelfile = os.path.dirname(os.path.abspath(__file__)) + '/Channel.json'
|
||||
ChannelInfos = []
|
||||
try:
|
||||
with open(Channelfile, encoding="utf-8") as f: # Read Channel Information file
|
||||
Channeldatajson = json.load(f)
|
||||
except EnvironmentError:
|
||||
printError("Channel." + JSON_FILE_ERROR)
|
||||
sys.exit()
|
||||
except ValueError:
|
||||
printError("Channel." + JSON_SYNTAX_ERROR)
|
||||
sys.exit()
|
||||
print('<?xml version="1.0" encoding="UTF-8"?>')
|
||||
print('<!DOCTYPE tv SYSTEM "xmltv.dtd">\n')
|
||||
print('<tv generator-info-name="epg2xml ' + __version__ + '">')
|
||||
# My Channel 정의
|
||||
for Channeldata in Channeldatajson: #Get Channel & Print Channel info
|
||||
# if Channeldata['Id'] is 223:
|
||||
ChannelId = Channeldata['Id']
|
||||
ChannelName = escape(Channeldata['Name'])
|
||||
ChannelSource = Channeldata['Source']
|
||||
ChannelServiceId = Channeldata['ServiceId']
|
||||
ChannelIconUrl = escape(Channeldata['Icon_url'])
|
||||
if MyISP != "ALL" and Channeldata[MyISP+'Ch'] is not None:
|
||||
ChannelInfos.append([ChannelId, ChannelName, ChannelSource, ChannelServiceId])
|
||||
ChannelNumber = str(Channeldata[MyISP+'Ch']);
|
||||
ChannelISPName = escape(Channeldata[MyISP+' Name'])
|
||||
print(' <channel id="%s">' % (ChannelId))
|
||||
print(' <display-name>%s</display-name>' % (ChannelName))
|
||||
print(' <display-name>%s</display-name>' % (ChannelISPName))
|
||||
print(' <display-name>%s</display-name>' % (ChannelNumber))
|
||||
print(' <display-name>%s</display-name>' % (ChannelNumber+' '+ChannelISPName))
|
||||
if IconUrl:
|
||||
print(' <icon src="%s/%s.png" />' % (IconUrl, ChannelId))
|
||||
else :
|
||||
print(' <icon src="%s" />' % (ChannelIconUrl))
|
||||
print(' </channel>')
|
||||
elif MyISP == "ALL":
|
||||
ChannelInfos.append([ChannelId, ChannelName, ChannelSource, ChannelServiceId])
|
||||
print(' <channel id="%s">' % (ChannelId))
|
||||
print(' <display-name>%s</display-name>' % (ChannelName))
|
||||
if IconUrl:
|
||||
print(' <icon src="%s/%s.png" />' % (IconUrl, ChannelId))
|
||||
else :
|
||||
print(' <icon src="%s" />' % (ChannelIconUrl))
|
||||
print(' </channel>')
|
||||
|
||||
# Print Program Information
|
||||
for ChannelInfo in ChannelInfos:
|
||||
ChannelId = ChannelInfo[0]
|
||||
ChannelName = ChannelInfo[1]
|
||||
ChannelSource = ChannelInfo[2]
|
||||
ChannelServiceId = ChannelInfo[3]
|
||||
if(debug) : printLog(ChannelName + ' 채널 EPG 데이터를 가져오고 있습니다')
|
||||
if ChannelSource == 'KT':
|
||||
GetEPGFromKT(ChannelInfo)
|
||||
elif ChannelSource == 'LG':
|
||||
GetEPGFromLG(ChannelInfo)
|
||||
elif ChannelSource == 'SK':
|
||||
GetEPGFromSK(ChannelInfo)
|
||||
elif ChannelSource == 'SKB':
|
||||
GetEPGFromSKB(ChannelInfo)
|
||||
elif ChannelSource == 'NAVER':
|
||||
GetEPGFromNaver(ChannelInfo)
|
||||
print('</tv>')
|
||||
|
||||
# Get EPG data from KT
|
||||
def GetEPGFromKT(ChannelInfo):
|
||||
ChannelId = ChannelInfo[0]
|
||||
ChannelName = ChannelInfo[1]
|
||||
ServiceId = ChannelInfo[3]
|
||||
epginfo = []
|
||||
url = 'http://tv.kt.com/tv/channel/pSchedule.asp'
|
||||
for k in range(period):
|
||||
day = today + datetime.timedelta(days=k)
|
||||
params = {'ch_type':'1', 'view_type':'1', 'service_ch_no':ServiceId, 'seldate':day.strftime('%Y%m%d')}
|
||||
try:
|
||||
response = requests.post(url, data=params, headers=ua, timeout=timeout)
|
||||
response.raise_for_status()
|
||||
|
||||
|
||||
html_data = (response.content).decode("euc-kr")
|
||||
# data = unicode(html_data, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
|
||||
data = html_data
|
||||
|
||||
print(data)
|
||||
|
||||
|
||||
strainer = SoupStrainer('tbody')
|
||||
soup = BeautifulSoup(data, htmlparser, parse_only=strainer)
|
||||
html = soup.find_all('tr') if soup.find('tbody') else ''
|
||||
if(html):
|
||||
for row in html:
|
||||
for cell in [row.find_all('td')]:
|
||||
startTime = endTime = programName = subprogramName = desc = actors = producers = category = episode = ''
|
||||
rebroadcast = False
|
||||
for minute, program, category in zip(cell[1].find_all('p'), cell[2].find_all('p'), cell[3].find_all('p')):
|
||||
startTime = str(day) + ' ' + cell[0].text.strip() + ':' + minute.text.strip()
|
||||
startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M')
|
||||
startTime = startTime.strftime('%Y%m%d%H%M%S')
|
||||
programName = program.text.replace('방송중 ', '').strip()
|
||||
category = category.text.strip()
|
||||
for image in [program.find_all('img', alt=True)]:
|
||||
rating = 0
|
||||
grade = re.match('([\d,]+)',image[0]['alt'])
|
||||
if not (grade is None): rating = int(grade.group(1))
|
||||
else: rating = 0
|
||||
#ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
|
||||
epginfo.append([ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating])
|
||||
time.sleep(0.001)
|
||||
else:
|
||||
if(debug): printError(ChannelName + CONTENT_ERROR)
|
||||
else: pass
|
||||
except (requests.exceptions.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
else: pass
|
||||
if(epginfo) :
|
||||
epgzip(epginfo)
|
||||
|
||||
# Get EPG data from LG
|
||||
def GetEPGFromLG(ChannelInfo):
|
||||
ChannelId = ChannelInfo[0]
|
||||
ChannelName = ChannelInfo[1]
|
||||
ServiceId = ChannelInfo[3]
|
||||
epginfo = []
|
||||
url = 'http://www.uplus.co.kr/css/chgi/chgi/RetrieveTvSchedule.hpi'
|
||||
for k in range(period):
|
||||
day = today + datetime.timedelta(days=k)
|
||||
params = {'chnlCd': ServiceId, 'evntCmpYmd': day.strftime('%Y%m%d')}
|
||||
try:
|
||||
response = requests.post(url, data=params, headers=ua, timeout=timeout)
|
||||
response.raise_for_status()
|
||||
html_data = (response.content).decode("euc-kr")
|
||||
# data = unicode(html_data, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
|
||||
data = html_data
|
||||
data = data.replace('<재>', '<재>').replace(' [..','').replace(' (..', '')
|
||||
strainer = SoupStrainer('table')
|
||||
soup = BeautifulSoup(data, htmlparser, parse_only=strainer)
|
||||
html = soup.find('table').tbody.find_all('tr') if soup.find('table') else ''
|
||||
if(html):
|
||||
for row in html:
|
||||
for cell in [row.find_all('td')]:
|
||||
startTime = endTime = programName = subprogramName = desc = actors = producers = category = episode = ''
|
||||
rebroadcast = False
|
||||
rating = 0
|
||||
startTime = str(day) + ' ' + cell[0].text
|
||||
startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M')
|
||||
startTime = startTime.strftime('%Y%m%d%H%M%S')
|
||||
rating = 0 if cell[1].find('span', {'class': 'tag cte_all'}).text.strip()=="All" else int(cell[1].find('span', {'class': 'tag cte_all'}).text.strip())
|
||||
cell[1].find('span', {'class': 'tagGroup'}).decompose()
|
||||
pattern = '(<재>)?\s?(?:\[.*?\])?(.*?)(?:\[(.*)\])?\s?(?:\(([\d,]+)회\))?$'
|
||||
matches = re.match(pattern, cell[1].text.strip())
|
||||
if not (matches is None):
|
||||
programName = matches.group(2).strip() if matches.group(2) else ''
|
||||
subprogramName = matches.group(3).strip() if matches.group(3) else ''
|
||||
episode = matches.group(4) if matches.group(4) else ''
|
||||
rebroadcast = True if matches.group(1) else False
|
||||
category = cell[2].text.strip()
|
||||
#ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
|
||||
epginfo.append([ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating])
|
||||
time.sleep(0.001)
|
||||
else:
|
||||
if(debug): printError(ChannelName + CONTENT_ERROR)
|
||||
else: pass
|
||||
except (requests.exceptions.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
else: pass
|
||||
if(epginfo) :
|
||||
epgzip(epginfo)
|
||||
|
||||
# Get EPG data from SK
|
||||
def GetEPGFromSK(ChannelInfo):
|
||||
ChannelId = ChannelInfo[0]
|
||||
ChannelName = ChannelInfo[1]
|
||||
ServiceId = ChannelInfo[3]
|
||||
lastday = today + datetime.timedelta(days=period-1)
|
||||
url = 'http://m.btvplus.co.kr/common/inc/IFGetData.do'
|
||||
params = {'variable': 'IF_LIVECHART_DETAIL', 'pcode':'|^|start_time=' + today.strftime('%Y%m%d') + '00|^|end_time='+ lastday.strftime('%Y%m%d') + '24|^|svc_id=' + str(ServiceId)}
|
||||
try:
|
||||
response = requests.post(url, data=params, headers=ua, timeout=timeout)
|
||||
response.raise_for_status()
|
||||
json_data = response.text
|
||||
try:
|
||||
data = json.loads(json_data, encoding='utf-8')
|
||||
if (data['channel'] is None) :
|
||||
if(True): printError(ChannelName + CONTENT_ERROR)
|
||||
else: pass
|
||||
else :
|
||||
programs = data['channel']['programs']
|
||||
for program in programs:
|
||||
startTime = endTime = programName = subprogramName = desc = actors = producers = category = episode = ''
|
||||
rebroadcast = False
|
||||
rating = 0
|
||||
programName = program['programName'].replace('...', '>').encode('utf-8')
|
||||
pattern = '^(.*?)(?:\s*[\(<]([\d,회]+)[\)>])?(?:\s*<([^<]*?)>)?(\((재)\))?$'
|
||||
matches = re.match(pattern, programName.decode('utf-8'))
|
||||
if not (matches is None):
|
||||
programName = matches.group(1).strip() if matches.group(1) else ''
|
||||
subprogramName = matches.group(3).strip() if matches.group(3) else ''
|
||||
episode = matches.group(2).replace('회', '') if matches.group(2) else ''
|
||||
episode = '' if episode== '0' else episode
|
||||
rebroadcast = True if matches.group(5) else False
|
||||
startTime = datetime.datetime.fromtimestamp(int(program['startTime'])/1000)
|
||||
startTime = startTime.strftime('%Y%m%d%H%M%S')
|
||||
endTime = datetime.datetime.fromtimestamp(int(program['endTime'])/1000)
|
||||
endTime = endTime.strftime('%Y%m%d%H%M%S')
|
||||
desc = program['synopsis'] if program['synopsis'] else ''
|
||||
actors = program['actorName'].replace('...','').strip(', ') if program['actorName'] else ''
|
||||
producers = program['directorName'].replace('...','').strip(', ') if program['directorName'] else ''
|
||||
if not (program['mainGenreName'] is None) :
|
||||
category = program['mainGenreName']
|
||||
rating = int(program['ratingCd']) if program['ratingCd'] else 0
|
||||
programdata = {'channelId':ChannelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rebroadcast':rebroadcast, 'rating':rating}
|
||||
writeProgram(programdata)
|
||||
time.sleep(0.001)
|
||||
except ValueError:
|
||||
if(debug): printError(ChannelName + CONTENT_ERROR)
|
||||
else: pass
|
||||
except (requests.exceptions.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
else: pass
|
||||
|
||||
#Get EPG data from SKB
|
||||
def GetEPGFromSKB(ChannelInfo):
|
||||
ChannelId = ChannelInfo[0]
|
||||
ChannelName = ChannelInfo[1]
|
||||
ServiceId = ChannelInfo[3]
|
||||
url = 'http://m.skbroadband.com/content/realtime/Channel_List.do'
|
||||
epginfo = []
|
||||
for k in range(period):
|
||||
day = today + datetime.timedelta(days=k)
|
||||
params = {'key_depth2': ServiceId, 'key_depth3': day.strftime('%Y%m%d')}
|
||||
try:
|
||||
response = requests.get(url, params=params, headers=ua, timeout=timeout)
|
||||
response.raise_for_status()
|
||||
html_data = (response.content).decode("euc-kr")
|
||||
|
||||
# data = unicode(html_data, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
|
||||
data = html_data
|
||||
|
||||
data = re.sub("EUC-KR", 'utf-8', data)
|
||||
data = re.sub('<!--(.*?)-->', '', data, 0, re.I|re.S)
|
||||
data = re.sub('<span class="round_flag flag02">(.*?)</span>', '', data)
|
||||
data = re.sub('<span class="round_flag flag03">(.*?)</span>', '', data)
|
||||
data = re.sub('<span class="round_flag flag04">(.*?)</span>', '', data)
|
||||
data = re.sub('<span class="round_flag flag09">(.*?)</span>', '', data)
|
||||
data = re.sub('<span class="round_flag flag10">(.*?)</span>', '', data)
|
||||
data = re.sub('<span class="round_flag flag11">(.*?)</span>', '', data)
|
||||
data = re.sub('<span class="round_flag flag12">(.*?)</span>', '', data)
|
||||
data = re.sub('<strong class="hide">프로그램 안내</strong>', '', data)
|
||||
data = re.sub('<p class="cont">(.*)', partial(replacement, tag='p') , data)
|
||||
data = re.sub('<p class="tit">(.*)', partial(replacement, tag='p') , data)
|
||||
strainer = SoupStrainer('div', {'id':'uiScheduleTabContent'})
|
||||
soup = BeautifulSoup(data, htmlparser, parse_only=strainer)
|
||||
html = soup.find_all('li',{'class':'list'}) if soup.find_all('li') else ''
|
||||
if(html):
|
||||
for row in html:
|
||||
startTime = endTime = programName = subprogramName = desc = actors = producers = category = episode = ''
|
||||
rebroadcast = False
|
||||
rating = 0
|
||||
startTime = str(day) + ' ' + row.find('p', {'class':'time'}).text
|
||||
startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M')
|
||||
startTime = startTime.strftime('%Y%m%d%H%M%S')
|
||||
cell = row.find('p', {'class':'cont'})
|
||||
grade = row.find('i', {'class':'hide'})
|
||||
if not(grade is None):
|
||||
# rating = int(grade.text.decode('string_escape').replace('세 이상','').strip())
|
||||
rating = int(grade.text.replace('세 이상','').strip())
|
||||
|
||||
if(cell):
|
||||
if cell.find('span'):
|
||||
cell.span.decompose()
|
||||
# cell = cell.text.decode('string_escape').strip()
|
||||
#cell = cell.text.decode('string_escape').strip()
|
||||
|
||||
#print (chardet.detect(cell.text.strip()))
|
||||
cell=cell.text.strip()
|
||||
# print (chardet.detect(bytes(cell,'utf-8')))
|
||||
# cell = cell.text.strip()
|
||||
pattern = "^(.*?)(\(([\d,]+)회\))?(<(.*)>)?(\((재)\))?$"
|
||||
# print (chardet.detect(pattern))
|
||||
matches = re.match(pattern, cell)
|
||||
|
||||
if not(matches is None) :
|
||||
programName = matches.group(1) if matches.group(1) else ''
|
||||
subprogramName = matches.group(5) if matches.group(5) else ''
|
||||
rebroadcast = True if matches.group(7) else False
|
||||
episode = matches.group(3) if matches.group(3) else ''
|
||||
|
||||
#ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
|
||||
epginfo.append([ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating])
|
||||
time.sleep(0.001)
|
||||
else:
|
||||
if(debug): printError(ChannelName + CONTENT_ERROR)
|
||||
else: pass
|
||||
except (requests.exceptions.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
else: pass
|
||||
if(epginfo) :
|
||||
epgzip(epginfo)
|
||||
|
||||
# Get EPG data from Naver
|
||||
def GetEPGFromNaver(ChannelInfo):
|
||||
ChannelId = ChannelInfo[0]
|
||||
ChannelName = ChannelInfo[1]
|
||||
ServiceId = ChannelInfo[3]
|
||||
epginfo = []
|
||||
totaldate = []
|
||||
url = 'https://search.naver.com/p/csearch/content/batchrender_ssl.nhn'
|
||||
for k in range(period):
|
||||
day = today + datetime.timedelta(days=k)
|
||||
totaldate.append(day.strftime('%Y%m%d'))
|
||||
params = {'_callback': 'epg', 'fileKey': 'single_schedule_channel_day', 'pkid': '66', 'u1': 'single_schedule_channel_day', 'u2': ','.join(totaldate), 'u3': today.strftime('%Y%m%d'), 'u4': period, 'u5': ServiceId, 'u6': '1', 'u7': ChannelName + '편성표', 'u8': ChannelName + '편성표', 'where': 'nexearch'}
|
||||
try:
|
||||
response = requests.get(url, params=params, headers=ua, timeout=timeout)
|
||||
response.raise_for_status()
|
||||
json_data = re.sub(re.compile("/\*.*?\*/",re.DOTALL ) ,"" ,response.text.split("epg(")[1].strip(");").strip())
|
||||
try:
|
||||
data = json.loads(json_data, encoding='utf-8')
|
||||
for i, date in enumerate(data['displayDates']):
|
||||
for j in range(0,24):
|
||||
for program in data['schedules'][j][i]:
|
||||
startTime = endTime = programName = subprogramName = desc = actors = producers = category = episode = ''
|
||||
rebroadcast = False
|
||||
rating = 0
|
||||
programName = unescape(program['title'])
|
||||
startTime = date['date'] + ' ' + program['startTime']
|
||||
startTime = datetime.datetime.strptime(startTime, '%Y%m%d %H:%M')
|
||||
startTime = startTime.strftime('%Y%m%d%H%M%S')
|
||||
episode = program['episode'].replace('회','')
|
||||
rebroadcast = program['isRerun']
|
||||
rating = program['grade']
|
||||
#ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
|
||||
epginfo.append([ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating])
|
||||
time.sleep(0.001)
|
||||
except ValueError:
|
||||
if(debug): printError(ChannelName + CONTENT_ERROR)
|
||||
else: pass
|
||||
except (requests.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
else: pass
|
||||
if(epginfo) :
|
||||
epgzip(epginfo)
|
||||
|
||||
# Zip epginfo
|
||||
def epgzip(epginfo):
|
||||
epginfo = iter(epginfo)
|
||||
epg1 = next(epginfo)
|
||||
for epg2 in epginfo:
|
||||
programdata = {}
|
||||
ChannelId = epg1[0]
|
||||
startTime = epg1[1] if epg1[1] else ''
|
||||
endTime = epg2[1] if epg2[1] else ''
|
||||
programName = epg1[2] if epg1[2] else ''
|
||||
subprogramName = epg1[3] if epg1[3] else ''
|
||||
desc = epg1[4] if epg1[4] else ''
|
||||
actors = epg1[5] if epg1[5] else ''
|
||||
producers = epg1[6] if epg1[6] else ''
|
||||
category = epg1[7] if epg1[7] else ''
|
||||
episode = epg1[8] if epg1[8] else ''
|
||||
rebroadcast = True if epg1[9] else False
|
||||
rating = int(epg1[10]) if epg1[10] else 0
|
||||
programdata = {'channelId':ChannelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rebroadcast':rebroadcast, 'rating':rating}
|
||||
writeProgram(programdata)
|
||||
epg1 = epg2
|
||||
|
||||
# Write Program
|
||||
def writeProgram(programdata):
|
||||
ChannelId = programdata['channelId']
|
||||
startTime = programdata['startTime']
|
||||
endTime = programdata['endTime']
|
||||
programName = escape(programdata['programName']).strip()
|
||||
subprogramName = escape(programdata['subprogramName']).strip()
|
||||
matches = re.match('(.*) \(?(\d+부)\)?', unescape(programName))
|
||||
if not(matches is None):
|
||||
programName = escape(matches.group(1)).strip();
|
||||
subprogramName = escape(matches.group(2)) + ' ' + subprogramName
|
||||
subprogramName = subprogramName.strip()
|
||||
if programName is None:
|
||||
programName = subprogramName
|
||||
actors = escape(programdata['actors'])
|
||||
producers = escape(programdata['producers'])
|
||||
category = escape(programdata['category'])
|
||||
episode = programdata['episode']
|
||||
if episode:
|
||||
try:
|
||||
episode_ns = int(episode) - 1
|
||||
episode_ns = '0'+ '.' + str(episode_ns) + '.' + '0' + '/' + '0'
|
||||
except ValueError as ex:
|
||||
episode_ns = int(episode.split(',', 1)[0]) - 1
|
||||
episode_ns = '0'+ '.' + str(episode_ns) + '.' + '0' + '/' + '0'
|
||||
episode_on = episode
|
||||
rebroadcast = programdata['rebroadcast']
|
||||
if episode and addepisode == 'y': programName = programName + ' ('+ str(episode) + '회)'
|
||||
if rebroadcast == True and addrebroadcast == 'y' : programName = programName + ' (재)'
|
||||
if programdata['rating'] == 0 :
|
||||
rating = '전체 관람가'
|
||||
else :
|
||||
rating = '%s세 이상 관람가' % (programdata['rating'])
|
||||
if addverbose == 'y':
|
||||
desc = programName
|
||||
if subprogramName : desc = desc + '\n부제 : ' + subprogramName
|
||||
if rebroadcast == True and addrebroadcast == 'y' : desc = desc + '\n방송 : 재방송'
|
||||
if episode : desc = desc + '\n회차 : ' + str(episode) + '회'
|
||||
if category : desc = desc + '\n장르 : ' + category
|
||||
if actors : desc = desc + '\n출연 : ' + actors.strip()
|
||||
if producers : desc = desc + '\n제작 : ' + producers.strip()
|
||||
desc = desc + '\n등급 : ' + rating
|
||||
else:
|
||||
desc =''
|
||||
if programdata['desc'] : desc = desc + '\n' + escape(programdata['desc'])
|
||||
desc = re.sub(' +',' ', desc)
|
||||
contentTypeDict={'교양':'Arts / Culture (without music)', '만화':'Cartoons / Puppets', '교육':'Education / Science / Factual topics', '취미':'Leisure hobbies', '드라마':'Movie / Drama', '영화':'Movie / Drama', '음악':'Music / Ballet / Dance', '뉴스':'News / Current affairs', '다큐':'Documentary', '라이프':'Documentary', '시사/다큐':'Documentary', '연예':'Show / Game show', '스포츠':'Sports', '홈쇼핑':'Advertisement / Shopping'}
|
||||
contentType = ''
|
||||
for key, value in contentTypeDict.items():
|
||||
if key in category:
|
||||
contentType = value
|
||||
print(' <programme start="%s +0900" stop="%s +0900" channel="%s">' % (startTime, endTime, ChannelId))
|
||||
print(' <title lang="kr">%s</title>' % (programName))
|
||||
if subprogramName :
|
||||
print(' <sub-title lang="kr">%s</sub-title>' % (subprogramName))
|
||||
if addverbose=='y' :
|
||||
print(' <desc lang="kr">%s</desc>' % (desc))
|
||||
if actors or producers:
|
||||
print(' <credits>')
|
||||
if actors:
|
||||
for actor in actors.split(','):
|
||||
if actor.strip(): print(' <actor>%s</actor>' % (actor.strip()))
|
||||
if producers:
|
||||
for producer in producers.split(','):
|
||||
if producer.strip(): print(' <producer>%s</producer>' % (producer).strip())
|
||||
print(' </credits>')
|
||||
if category: print(' <category lang="kr">%s</category>' % (category))
|
||||
if contentType: print(' <category lang="en">%s</category>' % (contentType))
|
||||
if episode and addxmltvns == 'y' : print(' <episode-num system="xmltv_ns">%s</episode-num>' % (episode_ns))
|
||||
if episode and addxmltvns != 'y' : print(' <episode-num system="onscreen">%s</episode-num>' % (episode_on))
|
||||
if rebroadcast: print(' <previously-shown />')
|
||||
if rating:
|
||||
print(' <rating system="KMRB">')
|
||||
print(' <value>%s</value>' % (rating))
|
||||
print(' </rating>')
|
||||
print(' </programme>')
|
||||
|
||||
def printLog(*args):
|
||||
print(*args, file=sys.stderr)
|
||||
|
||||
def printError(*args):
|
||||
print("Error : ", *args, file=sys.stderr)
|
||||
|
||||
def replacement(match, tag):
|
||||
if not(match is None):
|
||||
tag = tag.strip()
|
||||
programName = unescape(match.group(1)).replace('<','<').replace('>','>').strip()
|
||||
programName = '<'+ tag + ' class="cont">' + programName
|
||||
return programName
|
||||
else:
|
||||
return '';
|
||||
|
||||
Settingfile = os.path.dirname(os.path.abspath(__file__)) + '/epg2xml.json'
|
||||
ChannelInfos = []
|
||||
try:
|
||||
with open(Settingfile, encoding="utf-8") as f: # Read Channel Information file
|
||||
Settings = json.load(f)
|
||||
MyISP = Settings['MyISP'] if 'MyISP' in Settings else 'ALL'
|
||||
default_output = Settings['output'] if 'output' in Settings else 'd'
|
||||
default_xml_file = Settings['default_xml_file'] if 'default_xml_file' in Settings else 'xmltv.xml'
|
||||
default_xml_socket = Settings['default_xml_socket'] if 'default_xml_socket' in Settings else 'xmltv.sock'
|
||||
default_icon_url = Settings['default_icon_url'] if 'default_icon_url' in Settings else None
|
||||
default_fetch_limit = Settings['default_fetch_limit'] if 'default_fetch_limit' in Settings else '2'
|
||||
default_rebroadcast = Settings['default_rebroadcast'] if 'default_rebroadcast' in Settings else 'y'
|
||||
default_episode = Settings['default_episode'] if 'default_episode' in Settings else 'y'
|
||||
default_verbose = Settings['default_verbose'] if 'default_verbose' in Settings else 'n'
|
||||
default_xmltvns = Settings['default_xmltvns'] if 'default_xmltvns' in Settings else 'n'
|
||||
except EnvironmentError:
|
||||
printError("epg2xml." + JSON_FILE_ERROR)
|
||||
sys.exit()
|
||||
except ValueError:
|
||||
printError("epg2xml." + JSON_SYNTAX_ERROR)
|
||||
sys.exit()
|
||||
|
||||
parser = argparse.ArgumentParser(description = 'EPG 정보를 출력하는 방법을 선택한다')
|
||||
argu1 = parser.add_argument_group(description = 'IPTV 선택')
|
||||
argu1.add_argument('-i', dest = 'MyISP', choices = ['ALL', 'KT', 'LG', 'SK'], help = '사용하는 IPTV : ALL, KT, LG, SK', default = MyISP)
|
||||
argu2 = parser.add_mutually_exclusive_group()
|
||||
argu2.add_argument('-v', '--version', action = 'version', version = '%(prog)s version : ' + __version__)
|
||||
argu2.add_argument('-d', '--display', action = 'store_true', help = 'EPG 정보 화면출력')
|
||||
argu2.add_argument('-o', '--outfile', metavar = default_xml_file, nargs = '?', const = default_xml_file, help = 'EPG 정보 저장')
|
||||
argu2.add_argument('-s', '--socket', metavar = default_xml_socket, nargs = '?', const = default_xml_socket, help = 'xmltv.sock(External: XMLTV)로 EPG정보 전송')
|
||||
argu3 = parser.add_argument_group('추가옵션')
|
||||
argu3.add_argument('--icon', dest = 'icon', metavar = "http://www.example.com/icon", help = '채널 아이콘 URL, 기본값: '+ default_icon_url, default = default_icon_url)
|
||||
argu3.add_argument('-l', '--limit', dest = 'limit', type=int, metavar = "1-7", choices = range(1,8), help = 'EPG 정보를 가져올 기간, 기본값: '+ str(default_fetch_limit), default = default_fetch_limit)
|
||||
argu3.add_argument('--rebroadcast', dest = 'rebroadcast', metavar = 'y, n', choices = 'yn', help = '제목에 재방송 정보 출력', default = default_rebroadcast)
|
||||
argu3.add_argument('--episode', dest = 'episode', metavar = 'y, n', choices = 'yn', help = '제목에 회차 정보 출력', default = default_episode)
|
||||
argu3.add_argument('--verbose', dest = 'verbose', metavar = 'y, n', choices = 'yn', help = 'EPG 정보 추가 출력', default = default_verbose)
|
||||
|
||||
args = parser.parse_args()
|
||||
if args.MyISP : MyISP = args.MyISP
|
||||
if args.display :
|
||||
default_output = "d"
|
||||
elif args.outfile :
|
||||
default_output = "o"
|
||||
default_xml_file = args.outfile
|
||||
elif args.socket :
|
||||
default_output = "s"
|
||||
default_xml_socket = args.socket
|
||||
if args.icon : default_icon_url = args.icon
|
||||
if args.limit : default_fetch_limit = args.limit
|
||||
if args.rebroadcast : default_rebroadcast = args.rebroadcast
|
||||
if args.episode : default_episode = args.episode
|
||||
if args.verbose : default_verbose = args.verbose
|
||||
|
||||
if MyISP:
|
||||
if not any(MyISP in s for s in ['ALL', 'KT', 'LG', 'SK']):
|
||||
printError("MyISP는 ALL, KT, LG, SK만 가능합니다.")
|
||||
sys.exit()
|
||||
else :
|
||||
printError("epg2xml.json 파일의 MyISP항목이 없습니다.")
|
||||
sys.exit()
|
||||
|
||||
if default_output :
|
||||
if any(default_output in s for s in ['d', 'o', 's']):
|
||||
if default_output == "d" :
|
||||
output = "display";
|
||||
elif default_output == "o" :
|
||||
output = "file";
|
||||
elif default_output == 's' :
|
||||
output = "socket";
|
||||
else :
|
||||
printError("default_output는 d, o, s만 가능합니다.")
|
||||
sys.exit()
|
||||
else :
|
||||
printError("epg2xml.json 파일의 output항목이 없습니다.");
|
||||
sys.exit()
|
||||
|
||||
IconUrl = default_icon_url
|
||||
|
||||
if default_rebroadcast :
|
||||
if not any(default_rebroadcast in s for s in ['y', 'n']):
|
||||
printError("default_rebroadcast는 y, n만 가능합니다.")
|
||||
sys.exit()
|
||||
else :
|
||||
addrebroadcast = default_rebroadcast
|
||||
else :
|
||||
printError("epg2xml.json 파일의 default_rebroadcast항목이 없습니다.");
|
||||
sys.exit()
|
||||
|
||||
if default_episode :
|
||||
if not any(default_episode in s for s in ['y', 'n']):
|
||||
printError("default_episode는 y, n만 가능합니다.")
|
||||
sys.exit()
|
||||
else :
|
||||
addepisode = default_episode
|
||||
else :
|
||||
printError("epg2xml.json 파일의 default_episode항목이 없습니다.");
|
||||
sys.exit()
|
||||
|
||||
if default_verbose :
|
||||
if not any(default_verbose in s for s in ['y', 'n']):
|
||||
printError("default_verbose는 y, n만 가능합니다.")
|
||||
sys.exit()
|
||||
else :
|
||||
addverbose = default_verbose
|
||||
else :
|
||||
printError("epg2xml.json 파일의 default_verbose항목이 없습니다.");
|
||||
sys.exit()
|
||||
|
||||
if default_xmltvns :
|
||||
if not any(default_xmltvns in s for s in ['y', 'n']):
|
||||
printError("default_xmltvns는 y, n만 가능합니다.")
|
||||
sys.exit()
|
||||
else :
|
||||
addxmltvns = default_xmltvns
|
||||
else :
|
||||
printError("epg2xml.json 파일의 default_verbose항목이 없습니다.");
|
||||
sys.exit()
|
||||
|
||||
if default_fetch_limit :
|
||||
if not any(str(default_fetch_limit) in s for s in ['1', '2', '3', '4', '5', '6', '7']):
|
||||
printError("default_fetch_limit 는 1, 2, 3, 4, 5, 6, 7만 가능합니다.")
|
||||
sys.exit()
|
||||
else :
|
||||
period = int(default_fetch_limit)
|
||||
else :
|
||||
printError("epg2xml.json 파일의 default_fetch_limit항목이 없습니다.");
|
||||
sys.exit()
|
||||
|
||||
if output == "file" :
|
||||
if default_xml_file :
|
||||
sys.stdout = codecs.open(default_xml_file, 'w+', encoding='utf-8')
|
||||
else :
|
||||
printError("epg2xml.json 파일의 default_xml_file항목이 없습니다.");
|
||||
sys.exit()
|
||||
elif output == "socket" :
|
||||
if default_xml_socket :
|
||||
try:
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
sock.connect(default_xml_socket)
|
||||
sockfile = sock.makefile('w')
|
||||
sys.stdout = sockfile
|
||||
except socket.error:
|
||||
printError(SOCKET_ERROR)
|
||||
sys.exit()
|
||||
else :
|
||||
printError("epg2xml.json 파일의 default_xml_socket항목이 없습니다.");
|
||||
sys.exit()
|
||||
getEpg()
|
149
skb.py
149
skb.py
@ -1,149 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import json
|
||||
from pprint import pprint
|
||||
import sys
|
||||
import codecs
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
sys.stdin.reconfigure(encoding='utf-8')
|
||||
|
||||
# reload(sys)
|
||||
# sys.setdefaultencoding('utf-8')
|
||||
|
||||
path = 'skbchannel.txt'
|
||||
skb_channels = []
|
||||
|
||||
channeljson = 'Channel.json'
|
||||
channeldatas = []
|
||||
|
||||
#print (sys.stdin.encoding)
|
||||
#print (sys.stdout.encoding)
|
||||
with open(channeljson, encoding="utf-8") as json_data:
|
||||
channeldatas=json.load(json_data)
|
||||
json_data.close()
|
||||
|
||||
with open(path, encoding="utf-8") as f:
|
||||
for line in f:
|
||||
inner_list = [elt.strip() for elt in line.split('\t')]
|
||||
skb_channels.append(inner_list)
|
||||
|
||||
def getChanneldata(a):
|
||||
#print ("Search:" + a[1])
|
||||
try:
|
||||
findchannel=None
|
||||
for channeldata in channeldatas:
|
||||
channelnames=[(channeldata['SK Name']), (channeldata['KT Name']), channeldata['LG Name']]
|
||||
# print (channelnames)
|
||||
if(a[1] in channelnames):
|
||||
findchannel = channeldata
|
||||
break
|
||||
|
||||
# print (findchannel['Source'])
|
||||
# if(findchannel['Source'] is "KT"):
|
||||
# print (findchannel)
|
||||
if(findchannel['Source']== "KT"):
|
||||
print (findchannel['Name'])
|
||||
if(len(a)<3):
|
||||
print ("ERR")
|
||||
findchannel['Name'] = a[1]
|
||||
findchannel['Id'] = int(a[0])
|
||||
findchannel['ServiceId'] = a[2]
|
||||
findchannel['SK Name']=a[1]
|
||||
findchannel['KT Name']=a[1]
|
||||
findchannel['LG Name']=a[1]
|
||||
|
||||
if(findchannel['Source']== "NAVER"):
|
||||
print (findchannel['Name'])
|
||||
if(len(a)<3):
|
||||
print ("ERR")
|
||||
findchannel['Name'] = a[1]
|
||||
findchannel['Id'] = int(a[0])
|
||||
findchannel['ServiceId'] = a[2]
|
||||
findchannel['SK Name']=a[1]
|
||||
findchannel['KT Name']=a[1]
|
||||
findchannel['LG Name']=a[1]
|
||||
|
||||
if(len(a)>2):
|
||||
findchannel = {"Id": 0,
|
||||
"Name": "",
|
||||
"KT Name": "",
|
||||
"KTCh": 0,
|
||||
"LG Name": "",
|
||||
"LGCh": 0,
|
||||
"SK Name": "",
|
||||
"SKCh": 0,
|
||||
"Radio Name": "",
|
||||
"RadioCh":0 ,
|
||||
"Icon_url": "",
|
||||
"Source": "SKB",
|
||||
"ServiceId": 0}
|
||||
findchannel['Name'] = a[1]
|
||||
findchannel['Id'] = int(a[0])
|
||||
findchannel['ServiceId'] = a[2]
|
||||
findchannel['SK Name']=a[1]
|
||||
findchannel['KT Name']=a[1]
|
||||
findchannel['LG Name']=a[1]
|
||||
# print (findchannel)
|
||||
if (findchannel==None):
|
||||
print ("error:" + a[1]+":"+a[0]+":"+str(len(a)))
|
||||
# print (findchannel)
|
||||
findchannel['Id']=int(a[0])
|
||||
findchannel['SK Name']=a[1]
|
||||
findchannel['SKCh']=int(a[0])
|
||||
except Exception as e:
|
||||
print ("error!!:" + a[1]+":"+a[0])
|
||||
print (e)
|
||||
return findchannel
|
||||
# else:
|
||||
# print (findchannel)
|
||||
|
||||
MyChannelInfos = []
|
||||
for skb_channel in skb_channels:
|
||||
MyChannelInfo = getChanneldata(skb_channel)
|
||||
# print(MyChannelInfo)
|
||||
if(MyChannelInfo != None):
|
||||
# MyChannelInfo['Id']=str(skb_channel[0])
|
||||
# MyChannelInfo['SKCh']= skb_channel[0]
|
||||
# print(MyChannelInfo)
|
||||
MyChannelInfos.append(MyChannelInfo)
|
||||
# else:
|
||||
# print("None"+skb_channel[1])
|
||||
with open('Channel.json','w',encoding="utf-8") as outfile:
|
||||
json.dump(MyChannelInfos, outfile, indent=2,ensure_ascii=False)
|
||||
#print SKB_CHANNEL
|
||||
#print skb_channel[0][1]
|
||||
|
||||
# //a = Channel name data
|
||||
# def getChannelNumber(a):
|
||||
# # print ("AAAA",a[0])
|
||||
# for skb_channel in skb_channels:
|
||||
# # print ("BBBB",skb_channel[1])
|
||||
# if((unicode(skb_channel[1]).find(a[0])>-1) and a[0]!=""):
|
||||
# return skb_channel[0]
|
||||
# elif((unicode(skb_channel[1]).find(a[1])>-1) and a[1]!=""):
|
||||
# return skb_channel[0]
|
||||
# elif((unicode(skb_channel[1]).find(a[2])>-1) and a[2]!=""):
|
||||
# return skb_channel[0]
|
||||
# return None
|
||||
#
|
||||
#
|
||||
# with open('Channel.json') as json_data:
|
||||
#
|
||||
# MyChannelInfo = []
|
||||
#
|
||||
# # print getChannelNumber('asf')
|
||||
# # getChannelNumber=""
|
||||
# for Channeldata in Channeldatajson:
|
||||
# test=[(Channeldata['SK Name']), (Channeldata['KT Name']), Channeldata['LG Name']]
|
||||
# channelNumber=getChannelNumber(test)
|
||||
# # print channelNumber
|
||||
# if(channelNumber is None):
|
||||
# print Channeldata['SK Name']
|
||||
# else :
|
||||
# # print channelNumber
|
||||
# Channeldata['Id']=channelNumber
|
||||
# MyChannelInfo.append(Channeldata)
|
||||
#
|
||||
# with open('data.txt','w') as outfile:
|
||||
# json.dump(MyChannelInfo, outfile)
|
248
skbchannel.txt
248
skbchannel.txt
@ -1,248 +0,0 @@
|
||||
23 연합뉴스TV
|
||||
24 YTN
|
||||
26 SBS CNBC
|
||||
150 토마토TV
|
||||
151 한국경제TV
|
||||
152 MTN
|
||||
153 매일경제TV
|
||||
154 팍스경제TV 622
|
||||
155 이데일리TV
|
||||
156 서울경제TV
|
||||
157 YTN 라이프
|
||||
158 CNN International
|
||||
159 CNN US
|
||||
160 BBC World News
|
||||
161 CGTN
|
||||
162 Bloomberg TV
|
||||
163 Channel News Asia
|
||||
164 내외경제TV
|
||||
165 부동산토마토 621
|
||||
166 FOX News Channel 791
|
||||
167 tbsTV
|
||||
260 NGC
|
||||
261 Discovery Channel
|
||||
262 YTN 사이언스
|
||||
263 Natgeo People
|
||||
264 History
|
||||
265 BBC earth
|
||||
266 Natgeo Wild HD
|
||||
267 리얼TV
|
||||
268 헬스메디TV
|
||||
269 쿠키건강TV
|
||||
270 아리랑TV
|
||||
271 소상공인방송
|
||||
273 한국직업방송
|
||||
274 MBC NET
|
||||
275 소비자TV
|
||||
276 NBS 한국농업방송 443
|
||||
277 CCTV4
|
||||
278 NHK World Premium
|
||||
279 TV5Monde
|
||||
280 법률방송
|
||||
281 채널i
|
||||
282 국방TV
|
||||
283 다큐원
|
||||
284 브릿지TV 446
|
||||
285 지방자치TV 447
|
||||
286 다문화TV 448
|
||||
300 CBS
|
||||
301 CTS
|
||||
302 CGNTV
|
||||
303 Good TV
|
||||
304 C채널
|
||||
305 BTN 불교TV
|
||||
306 BBS 불교방송
|
||||
307 가톨릭평화방송
|
||||
308 STB 상생방송
|
||||
309 원음방송
|
||||
3 tvN
|
||||
28 MBC Every1
|
||||
48 JTBC2
|
||||
49 E채널
|
||||
74 INSIGHT TV
|
||||
80 KBS joy
|
||||
81 SBS fun E
|
||||
83 E! Entertainment 789
|
||||
84 OtvN 527
|
||||
85 XtvN
|
||||
86 TVCHOSUN2 631
|
||||
87 코미디TV
|
||||
88 K star
|
||||
89 라이프타임
|
||||
90 FX
|
||||
91 FUN TV
|
||||
92 마이펫TV
|
||||
93 CMCTV 876
|
||||
94 Sky Petpark
|
||||
96 DIA TV
|
||||
97 채널A플러스 891
|
||||
98 MBN플러스 892
|
||||
99 skyENT 893
|
||||
213 CUBE TV
|
||||
290 KTV
|
||||
291 국회방송
|
||||
292 OUN
|
||||
293 복지TV
|
||||
2 공영쇼핑 332
|
||||
4 홈&쇼핑
|
||||
6 CJ오쇼핑
|
||||
8 현대홈쇼핑 321
|
||||
10 롯데홈쇼핑 323
|
||||
12 GS SHOP
|
||||
14 NS홈쇼핑
|
||||
17 SK stoa
|
||||
21 K쇼핑
|
||||
22 신세계쇼핑
|
||||
25 쇼핑엔티
|
||||
29 GS MY SHOP
|
||||
31 롯데OneTV
|
||||
33 CJ오쇼핑 플러스
|
||||
37 W쇼핑
|
||||
39 현대홈쇼핑+Shop
|
||||
41 NS Shop+
|
||||
200 JEI 재능 English
|
||||
201 플레이런TV
|
||||
202 EBS English
|
||||
203 EBS +1
|
||||
204 EBS +2
|
||||
205 edu TV
|
||||
118 SPOTV ON
|
||||
119 SPOTV ON 2 137
|
||||
120 SPOTV
|
||||
121 KBSN 스포츠
|
||||
122 SBS Sports
|
||||
123 MBC Sports+
|
||||
124 MBC SPORTS+2
|
||||
125 sky Sports
|
||||
126 JTBC3 FOX SPORTS 436
|
||||
127 SPOTV+
|
||||
128 SPOTV2
|
||||
129 IB Sports
|
||||
130 Billiards TV
|
||||
131 SBS GOLF
|
||||
132 JTBC GOLF
|
||||
133 Golf Channel Korea
|
||||
134 Eurosport
|
||||
135 Star Sports
|
||||
136 OGN
|
||||
137 SPOTV GAMES
|
||||
138 스크린골프존 138
|
||||
139 인도어스포츠
|
||||
240 바둑TV
|
||||
241 K-바둑
|
||||
242 브레인TV
|
||||
243 FTV
|
||||
244 FISHING TV
|
||||
245 ONT
|
||||
246 sky Travel
|
||||
247 Mountain TV
|
||||
249 폴라리스TV
|
||||
251 리빙TV
|
||||
27 M.net
|
||||
230 SBS MTV
|
||||
231 MBC Music
|
||||
232 GMTV
|
||||
233 아이넷 TV
|
||||
234 Arte TV
|
||||
235 STINGRAY CLASSICA 787
|
||||
237 Stingray CMusic 672
|
||||
238 이벤트TV
|
||||
239 BET
|
||||
79 DOG TV
|
||||
210 On style
|
||||
211 Fashion N
|
||||
212 채널 뷰 276
|
||||
214 KBS W
|
||||
215 Life U
|
||||
216 Fox life
|
||||
217 Gtv
|
||||
218 동아TV
|
||||
219 OBSW
|
||||
220 9colors
|
||||
221 NHK WORLD JAPAN 783
|
||||
222 JTBC4 259
|
||||
223 TRENDY 288
|
||||
224 CookTV 289
|
||||
225 Now제주TV 290
|
||||
226 육아방송
|
||||
227 실버아이TV
|
||||
228 시니어TV 291
|
||||
1 SBS 플러스
|
||||
30 KBS 드라마
|
||||
32 MBC 드라마
|
||||
34 Olive 431
|
||||
36 드라마큐브
|
||||
38 드라맥스
|
||||
40 sky Drama
|
||||
42 Highlight TV
|
||||
43 CNTV
|
||||
44 EDGE TV
|
||||
45 디원
|
||||
46 드라마H
|
||||
47 HQ+
|
||||
70 UXN
|
||||
71 UHD Dream TV
|
||||
72 Asia UHD
|
||||
73 UMAX 69
|
||||
101 FOX
|
||||
102 AXN
|
||||
103 채널J
|
||||
104 중화TV
|
||||
105 채널 Ching
|
||||
106 Asia N
|
||||
107 히어로액션
|
||||
108 채널차이나
|
||||
109 텔레노벨라
|
||||
110 채널W 172
|
||||
51 CATCH ON 1
|
||||
52 CATCH ON 2
|
||||
53 Ch CGV
|
||||
54 OCN
|
||||
55 SUPER ACTION
|
||||
56 Screen
|
||||
57 Mplex
|
||||
58 Cinef
|
||||
59 The Movie
|
||||
60 AsiaM 174
|
||||
61 인디필름
|
||||
62 Celestial Movies
|
||||
320 플레이보이TV
|
||||
321 미드나잇
|
||||
322 Viki
|
||||
323 허니TV
|
||||
324 핑크하우스
|
||||
325 디자이어TV
|
||||
182 뽀요TV 387
|
||||
183 캐리TV 388
|
||||
187 english gem 390
|
||||
188 신기한나라TV
|
||||
189 키즈톡톡 플러스
|
||||
190 KBS KIDS
|
||||
191 어린이TV
|
||||
192 JEI 재능TV
|
||||
193 bravo kids 370
|
||||
194 EBS KIDS 372
|
||||
195 Baby TV 785
|
||||
196 대교베이비TV 373
|
||||
170 Tooniverse
|
||||
171 디즈니채널
|
||||
172 디즈니주니어
|
||||
173 Animax
|
||||
174 애니원
|
||||
175 부메랑
|
||||
176 Nickelodeon
|
||||
177 카툰네트워크
|
||||
178 애니플러스
|
||||
179 애니박스
|
||||
180 DreamWorks 790
|
||||
15 JTBC
|
||||
16 MBN
|
||||
18 채널A
|
||||
19 TV CHOSUN 243
|
||||
5 SBS
|
||||
7 KBS2
|
||||
9 KBS1
|
||||
11 MBC
|
||||
13 EBS
|
||||
20 OBS
|
||||
95 EBS2
|
Loading…
x
Reference in New Issue
Block a user