Skip to content

Commit

Permalink
Github合并意见的修改
Browse files Browse the repository at this point in the history
  • Loading branch information
zheng_wenlong committed Feb 20, 2018
1 parent e62f431 commit d629445
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 105 deletions.
11 changes: 5 additions & 6 deletions apps/Work/Worker.py
Expand Up @@ -169,9 +169,7 @@ def GET(self):
feeds = bk.feeds
book.feeds = []
for feed in feeds:
if feed.url.startswith("http://www.cartoonmad.com") \
or feed.url.startswith("http://ac.qq.com") \
or feed.url.startswith("http://m.ac.qq.com"):
if feed.url.startswith( ("http://www.cartoonmad.com", "http://ac.qq.com", "http://m.ac.qq.com") ) :
self.ProcessComicRSS(username, user, feed)
else:
book.feeds.append((feed.title, feed.url, feed.isfulltext))
Expand Down Expand Up @@ -373,11 +371,12 @@ def ProcessComicRSS(self, username, user, feed):
sections = OrderedDict()
toc_thumbnails = {} #map img-url -> manifest-href

if feed.url.startswith("http://ac.qq.com") \
or feed.url.startswith("http://m.ac.qq.com"):
if feed.url.startswith( ("http://ac.qq.com", "http://m.ac.qq.com") ):
book = TencentBaseBook(imgindex=imgindex, opts=opts, user=user)
else:
elif feed.url.startswith( "http://www.cartoonmad.com" ):
book = CartoonMadBaseBook(imgindex=imgindex, opts=opts, user=user)
else:
return "Failed to push book <%s>!"%title

book.title = feed.title
book.description = feed.title
Expand Down
108 changes: 36 additions & 72 deletions books/comic/tencentbase.py
@@ -1,10 +1,8 @@
#!/usr/bin/env python3
# encoding: utf-8
#http://ac.qq.com或者http://m.ac.qq.com网站的免费漫画的基类,简单提供几个信息实现一个子类即可推送特定的漫画
import datetime
import json
import re, urlparse, json, datetime, base64
from time import sleep
import re
from config import TIMEZONE
from lib.urlopener import URLOpener
from lib.autodecoder import AutoDecoder
Expand All @@ -30,6 +28,7 @@ def ParseFeedUrls(self):
userName = self.UserName()
for item in self.feeds:
title, url = item[0], item[1]
comic_id = ""

lastCount = LastDelivered.all().filter('username = ', userName).filter("bookname = ", title).get()
if not lastCount:
Expand All @@ -38,7 +37,14 @@ def ParseFeedUrls(self):
else:
oldNum = lastCount.num

comic_id = url.split("/")[6]
urlpaths = urlparse.urlsplit(url.lower()).path.split("/")
if ( (u"id" in urlpaths) and (urlpaths.index(u"id")+1 < len(urlpaths)) ):
comic_id = urlpaths[urlpaths.index(u"id")+1]

if ( (not comic_id.isdigit()) or (comic_id=="") ):
self.log.warn('can not get comic id: %s' % url)
break

chapterList = self.getChapterList(comic_id)
for deliverCount in range(5):
newNum = oldNum + deliverCount
Expand Down Expand Up @@ -70,95 +76,53 @@ def UpdateLastDelivered(self, title, num):
def getChapterList(self, comic_id):
decoder = AutoDecoder(isfeed=False)
opener = URLOpener(self.host, timeout=60)
chapterList = []

getChapterListUrl = 'http://m.ac.qq.com/GetData/getChapterList?id={}'.format(comic_id)
result = opener.open(getChapterListUrl)
if result.status_code != 200 or not result.content:
self.log.warn('fetch comic page failed: %s' % url)
return None
return chapterList

content = result.content
content = self.AutoDecodeContent(content, decoder, self.page_encoding, opener.realurl, result.headers)

contentJson = json.loads(content)
count = contentJson['length']
chapterList = []
for i in range(count + 1):
for item in contentJson:
if isinstance(contentJson[item], dict) and contentJson[item].get('seq') == i:
chapterList.append({item: contentJson[item]})
break
count = contentJson.get('length', 0)
if (count != 0):
for i in range(count + 1):
for item in contentJson:
if isinstance(contentJson[item], dict) and contentJson[item].get('seq') == i:
chapterList.append({item: contentJson[item]})
break
else:
self.log.warn('comic count is zero.')

return chapterList

#获取漫画图片列表
def getImgList(self, chapterJson, comic_id):
decoder = AutoDecoder(isfeed=False)
opener = URLOpener(self.host, timeout=60)

imgList = []

cid = list(chapterJson.keys())[0]
getImgListUrl = 'http://ac.qq.com/ComicView/index/id/{0}/cid/{1}'.format(comic_id, cid)
result = opener.open(getImgListUrl)
if result.status_code != 200 or not result.content:
self.log.warn('fetch comic page failed: %s' % url)
return None
return imgList

content = result.content
cid_page = self.AutoDecodeContent(content, decoder, self.page_encoding, opener.realurl, result.headers)
filter_result = re.findall(r"data\s*:\s*'(.+?)'", cid_page)
if len(filter_result) != 0:
base64data = filter_result[0][1:]
img_detail_json = json.loads(base64.decodestring(base64data))
for img_url in img_detail_json.get('picture', []):
if ( 'url' in img_url ):
imgList.append(img_url['url'])
else:
self.log.warn('no url in img_url:%s' % img_url)

base64data = re.findall(r"data\s*:\s*'(.+?)'", cid_page)[0][1:]
img_detail_json = json.loads(self.__decode_base64_data(base64data))
imgList = []
for img_url in img_detail_json.get('picture'):
imgList.append(img_url['url'])
return imgList

#漫画Base64解码数据
def __decode_base64_data(self, base64data):
base64DecodeChars = [- 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1,
63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
50, 51, -1, -1, -1, -1, -1]
data_length = len(base64data)
i = 0
out = ""
c1 = c2 = c3 = c4 = 0
while i < data_length:
while True:
c1 = base64DecodeChars[ord(base64data[i]) & 255]
i += 1
if not (i < data_length and c1 == -1):
break
if c1 == -1:
break
while True:
c2 = base64DecodeChars[ord(base64data[i]) & 255]
i += 1
if not (i < data_length and c2 == -1):
break
if c2 == -1:
break
out += chr(c1 << 2 | (c2 & 48) >> 4)
while True:
c3 = ord(base64data[i]) & 255
i += 1
if c3 == 61:
return out
c3 = base64DecodeChars[c3]
if not (i < data_length and c3 == - 1):
break
if c3 == -1:
break
out += chr((c2 & 15) << 4 | (c3 & 60) >> 2)
while True:
c4 = ord(base64data[i]) & 255
i += 1
if c4 == 61:
return out
c4 = base64DecodeChars[c4]
if not (i < data_length and c4 == - 1):
break
out += chr((c3 & 3) << 6 | c4)
return out

2 changes: 1 addition & 1 deletion config.py
Expand Up @@ -45,7 +45,7 @@
GENERATE_HTML_TOC = True

#if convert color image to gray or not, good for reducing size of book if you read it in Kindle only
COLOR_TO_GRAY = True
COLOR_TO_GRAY = False

#Split long image(height of image is bigger than some value) to multiple images or not?
#This feature is disabled if it be set to None or 0.
Expand Down
25 changes: 0 additions & 25 deletions readme.md
Expand Up @@ -65,31 +65,6 @@ config.py | DOMAIN | 你申请的应用的域名 |
3. 将KindleEar目录放到Uploader目录下,双击uploader.bat即开始上传,根据提示输入你的相关信息即可,在第一次成功部署之后,适用uploader再次升级KindleEar则不需要再次输入。
**此uploader仅适用于Windows系统。**

# 漫画使用说明
目前支持以下网站的漫画
http://www.cartoonmad.com
http://ac.qq.com
http://m.ac.qq.com

漫画的订阅方法有两种

1. 新增书籍并上传订阅

进入books/comic/下,在该目录拷贝conan.py并任意命名,修改其中的下列位置。这里使用【食戟之灵】举例,考虑conan.py到soma.py。

位置|修改前|修改后|说明|
------|--------------|--------------|-----------------------|
第7行|return Conan | return Soma | 使用Soma作为类名 |
第9行|class Conan(CartoonMadBaseBook): | class Soma(CartoonMadBaseBook): | 使用Soma作为类名 |
第10行|title = u'[漫画]名侦探柯南'|title = u'[漫画]食戟之灵'|漫画名为【食戟之灵】|
第11行|description = u'日本漫画家青山刚昌创作的侦探漫画'|description = u'由附田祐斗原作,佐伯俊作画,料理研究家森崎友纪协力于集英社旗下的漫画杂志《周刊少年JUMP》上的连载作品。'|漫画的简单说明|
第17行|feeds = [(u'[漫画]名侦探柯南', 'http://www.cartoonmad.com/comic/1066.html')]|feeds = [(u'[漫画]食戟之灵', 'http://www.cartoonmad.com/comic/1698.html')]|在网站上搜索到该漫画的网址|
修改完以后,重新上传到GAE,点击新的书籍【[漫画]食戟之灵】进行订阅。

2. 通过Feeds订阅

相比较方法1,方法2比较简单,在【我的订阅】页面的【自定义RSS】框中,添加书籍标题和URL。内容同方法1的第17行一致。投递时需要打开【自动定时投递自定义RSS】选项。

# 许可协议
KindleEar is licensed under the [AGPLv3](http://www.gnu.org/licenses/agpl-3.0.html) license.
大体的许可框架是此应用代码你可以任意使用,任意修改,可以商用,但是必须将你修改后的代码开源并保留原始版权声明。
Expand Down
58 changes: 58 additions & 0 deletions static/faq.html
Expand Up @@ -52,6 +52,7 @@ <h1><a href="/">KindleEar</a></h1>
<li><a href="#savetopocket">保存到Pocket功能如何使用?</a></li>
<li><a href="#wrongemail">投递日志状态wrong SRC_EMAIL的解决方案。</a></li>
<li><a href="#tips">其他的一些小Tips。</a></li>
<li><a href="#comic">漫画订阅说明</a></li>
<li><a href="#issues">我还有更多问题,到哪里去问?</a></li>
</ul>
</div>
Expand Down Expand Up @@ -338,6 +339,63 @@ <h2>其他的一些小Tips。</h2>
<li>因Evernote的免费政策,通过邮件保存到Evernote仅支持5个邮件,需要更多则需要升级Evernote账户。</li>
</ul>
</p>

<span id="comic"></span>
<h2>漫画订阅说明</h2>
<p class="answer">
目前支持以下网站的漫画<br/>
<ul>
<a href="http://www.cartoonmad.com">动漫狂</a><br/>
<a href="http://ac.qq.com">腾讯动漫</a><br/>
<a href="http://m.ac.qq.com">腾讯动漫移动版</a><br/>
</ul>
漫画的订阅方法有两种,可以选择其中任意一种。<br/>
这里使用【食戟之灵】举例,先从动漫狂中搜索得到该漫画的URL。<br/>
<ul>
<li>1. 通过Feeds订阅</li>
这种方法比较简单,在【我的订阅】页面的【自定义RSS】框中,添加书籍标题和URL进行订阅。<br/>
注意:投递时需要打开【自动定时投递自定义RSS】选项。<br/>

<li>2. 新建书籍并上传订阅</li>
进入books/comic/下,在该目录拷贝conan.py并任意命名,修改其中的下列位置以后,重新上传到GAE,点击新的书籍【[漫画]食戟之灵】进行订阅。<br/>
拷贝conan.py到soma.py。<br/>
<table border="1">
<tr>
<td>位置</td>
<td>修改前</td>
<td>修改后</td>
<td>说明</td>
</tr>
<tr>
<td>7行</td>
<td>return Conan</td>
<td>return Soma</td>
<td>使用"Soma"作为类名</td>
</tr>
<tr>
<td>9行</td>
<td>class Conan(CartoonMadBaseBook):</td>
<td>class Soma(CartoonMadBaseBook):</td>
<td>使用"Soma"作为类名</td>
</tr>
<td>10行</td>
<td>title = u'[漫画]名侦探柯南'</td>
<td>title = u'[漫画]食戟之灵'</td>
<td>漫画名为【食戟之灵】</td>
</tr>
<td>11行</td>
<td>description = u'日本漫画家青山刚昌创作的侦探漫画'</td>
<td>description = u'由附田祐斗原作,佐伯俊作画的连载作品。'</td>
<td>漫画的简单说明</td>
</tr>
<td>17行</td>
<td>feeds = [(u'[漫画]名侦探柯南', 'http://www.cartoonmad.com/comic/1066.html')]</td>
<td>feeds = [(u'[漫画]食戟之灵', 'http://www.cartoonmad.com/comic/1698.html')]</td>
<td>在网站上搜索到该漫画的网址</td>
</tr>
</table>
</ul>
</p>

<span id="issues"></span>
<h2>我还有更多问题,到哪里去问?</h2>
Expand Down
2 changes: 1 addition & 1 deletion templates/my.html
Expand Up @@ -9,7 +9,7 @@
{{feed.title}}
{% if feed.isfulltext %} <img alt="{{_("Fulltext")}}" src="static/fulltext.gif" border="0" />{% endif %}
{% if feed.url.startswith("http://www.cartoonmad.com") %} <img alt="{{_("CartoonMad")}}" src="static/comic.gif" border="0" />{% endif %}
{% if feed.url.startswith("http://ac.qq.com") or feed.url.startswith("http://m.ac.qq.com") %} <img alt="{{_("Tencent")}}" src="static/comic.gif" border="0" />{% endif %}
{% if feed.url.startswith(("http://ac.qq.com", "http://m.ac.qq.com")) %} <img alt="{{_("Tencent")}}" src="static/comic.gif" border="0" />{% endif %}
</div>
<div class="cornerControls">
{#<a href="/delfeed/{{feed.key().id()}}" class="actionButton">{{_("Delete")}}</a>#}
Expand Down

0 comments on commit d629445

Please sign in to comment.