yuyuedu.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. # -*- coding: utf-8 -*-
  2. from content_spider.baseSpider import baseSpider
  3. from content_spider.baseSpider import baseUpdateSpider
  4. from content_spider.baseSpider import fixChapterSpider
  5. from content_spider.baseSpider import baseUpdateBookStatusSpider
  6. import time
  7. import json
  8. name = 'yuyuedu'
  9. allowed_domains = ['api.yuread.cn']
  10. source = 'zy_yuyuedu'
  11. source_name = 'yuyuedu娱阅读星河'
  12. source_id = 36
  13. base_url = 'http://api.xingheread.cn/zhiyu/{}'
  14. category = [
  15. {"sid": "1","title": "男生频道","pid": "0","channel_id":1,'category_name': '武侠仙侠', 'category_id': 21},
  16. {"sid": "2","title": "女生频道","pid": "0","channel_id":2,'category_name': '婚恋情感', 'category_id': 98},
  17. {"sid": "3","title": "现代都市","pid": "1","channel_id":1,'category_name': '都市爱情', 'category_id': 54},
  18. {"sid": "4","title": "玄幻仙侠","pid": "1","channel_id":1,'category_name': '武侠仙侠', 'category_id': 21},
  19. {"sid": "5","title": "历史竞技","pid": "1","channel_id":1,'category_name': '历史穿越', 'category_id': 14},
  20. {"sid": "6","title": "悬疑灵异","pid": "1","channel_id":1,'category_name': '灵异恐怖', 'category_id': 81},
  21. {"sid": "7","title": "科幻末世","pid": "1","channel_id":1,'category_name': '玄幻奇幻', 'category_id': 23},
  22. {"sid": "8","title": "现代言情","pid": "2","channel_id":2,'category_name': '婚恋情感', 'category_id': 98},
  23. {"sid": "9","title": "穿越古言","pid": "2","channel_id":2,'category_name': '穿越重生', 'category_id': 83},
  24. {"sid": "10","title": "玄幻奇幻","pid": "2","channel_id":2,'category_name': '东方玄幻', 'category_id': 96},
  25. {"sid": "11","title": "灵异言情","pid": "2","channel_id":2,'category_name': '鬼夫言情', 'category_id': 115},
  26. {"sid": "12","title": "唯美同人","pid": "2","channel_id":2,'category_name': '耽美同人', 'category_id': 106},
  27. {"sid": "13","title": "官场商场","pid": "3","channel_id":1,'category_name': '官场沉浮', 'category_id': 55},
  28. {"sid": "14","title": "热血青春","pid": "3","channel_id":1,'category_name': '青春爱情', 'category_id': 94},
  29. {"sid": "15","title": "异术超能","pid": "3","channel_id":1,'category_name': '现代修真', 'category_id': 68},
  30. {"sid": "16","title": "热血都市","pid": "3","channel_id":1,'category_name': '都市爱情', 'category_id': 54},
  31. {"sid": "17","title": "社会百态","pid": "3","channel_id":1,'category_name': '其他作品', 'category_id': 127},
  32. {"sid": "18","title": "乡村生活","pid": "3","channel_id":1,'category_name': '其他作品', 'category_id': 127},
  33. {"sid": "19","title": "西方玄幻","pid": "4","channel_id":1,'category_name': '西方玄幻', 'category_id': 22},
  34. {"sid": "20","title": "东方玄幻","pid": "4","channel_id":1,'category_name': '武侠仙侠', 'category_id': 21},
  35. {"sid": "21","title": "异世修真","pid": "4","channel_id":1,'category_name': '玄幻奇幻', 'category_id': 23},
  36. {"sid": "22","title": "神话魔法","pid": "4","channel_id":1,'category_name': '玄幻奇幻', 'category_id': 23},
  37. {"sid": "23","title": "战争幻想","pid": "5","channel_id":1,'category_name': '玄幻奇幻', 'category_id': 23},
  38. {"sid": "24","title": "历史传记","pid": "5","channel_id":1,'category_name': '特种军旅', 'category_id': 51},
  39. {"sid": "25","title": "架空历史","pid": "5","channel_id":1,'category_name': '历史穿越', 'category_id': 14},
  40. {"sid": "26","title": "体育竞技","pid": "5","channel_id":1,'category_name': '游戏竞技', 'category_id': 19},
  41. {"sid": "27","title": "虚拟网游","pid": "5","channel_id":1,'category_name': '游戏竞技', 'category_id': 19},
  42. {"sid": "28","title": "风水秘术","pid": "6","channel_id":1,'category_name': '灵异恐怖', 'category_id': 81},
  43. {"sid": "29","title": "悬疑推理","pid": "6","channel_id":1,'category_name': '灵异恐怖', 'category_id': 81},
  44. {"sid": "30","title": "恐怖惊悚","pid": "6","channel_id":1,'category_name': '灵异恐怖', 'category_id': 81},
  45. {"sid": "31","title": "末世危机","pid": "7","channel_id":1,'category_name': '西方玄幻', 'category_id': 22},
  46. {"sid": "32","title": "位面空间","pid": "7","channel_id":1,'category_name': '西方玄幻', 'category_id': 22},
  47. {"sid": "33","title": "星际幻想","pid": "7","channel_id":1,'category_name': '西方玄幻', 'category_id': 22},
  48. {"sid": "34","title": "科幻机甲","pid": "7","channel_id":1,'category_name': '西方玄幻', 'category_id': 22},
  49. {"sid": "35","title": "婚恋职场","pid": "8","channel_id":2,'category_name': '婚恋情感', 'category_id': 98},
  50. {"sid": "36","title": "总裁豪门","pid": "8","channel_id":2,'category_name': '豪门总裁', 'category_id': 88},
  51. {"sid": "37","title": "现代重生","pid": "8","channel_id":2,'category_name': '都市异能', 'category_id': 118},
  52. {"sid": "38","title": "社会女性","pid": "8","channel_id":2,'category_name': '婚恋情感', 'category_id': 98},
  53. {"sid": "39","title": "青春校园","pid": "8","channel_id":2,'category_name': '青春校园', 'category_id': 104},
  54. {"sid": "40","title": "技能女强","pid": "9","channel_id":2,'category_name': '都市职场', 'category_id': 116},
  55. {"sid": "41","title": "宫斗宅斗","pid": "9","channel_id":2,'category_name': '宫斗宅斗', 'category_id': 120},
  56. {"sid": "42","title": "经商种田","pid": "9","channel_id":2,'category_name': '经商种田', 'category_id': 84},
  57. {"sid": "43","title": "民国旧影","pid": "9","channel_id":2,'category_name': '清穿民国', 'category_id': 122},
  58. {"sid": "44","title": "女尊天下","pid": "9","channel_id":2,'category_name': '女尊王朝', 'category_id': 123},
  59. {"sid": "45","title": "魔法幻情","pid": "10","channel_id":2,'category_name': '古典仙侠', 'category_id': 97},
  60. {"sid": "46","title": "玄幻女强","pid": "10","channel_id":2,'category_name': '东方玄幻', 'category_id': 96},
  61. {"sid": "47","title": "仙侠修真","pid": "10","channel_id":2,'category_name': '东方玄幻', 'category_id': 96},
  62. {"sid": "48","title": "科幻末世","pid": "10","channel_id":2,'category_name': '东方玄幻', 'category_id': 96},
  63. {"sid": "49","title": "空间网游","pid": "10","channel_id":2,'category_name': '游戏', 'category_id': 119},
  64. {"sid": "50","title": "现代灵异","pid": "11","channel_id":2,'category_name': '女生灵异', 'category_id': 95},
  65. {"sid": "51","title": "民国灵异","pid": "11","channel_id":2,'category_name': '鬼夫言情', 'category_id': 115},
  66. {"sid": "52","title": "古代灵异","pid": "11","channel_id":2,'category_name': '鬼夫言情', 'category_id': 115},
  67. {"sid": "53","title": "现代耽美","pid": "12","channel_id":2,'category_name': '耽美同人', 'category_id': 106},
  68. {"sid": "54","title": "古代耽美","pid": "12","channel_id":2,'category_name': '耽美同人', 'category_id': 106},
  69. {"sid": "55","title": "明星同人","pid": "12","channel_id":2,'category_name': '耽美同人', 'category_id': 106},
  70. {"sid": "56","title": "动漫同人","pid": "12","channel_id":2,'category_name': '耽美同人', 'category_id': 106},
  71. {"sid": "57","title": "短篇","pid": "3","channel_id":1,'category_name': '轻小说', 'category_id': 126},
  72. {"sid": "58","title": "短篇","pid": "8","channel_id":2,'category_name': '其他', 'category_id': 107}
  73. ]
  74. def get_category(sort_id):
  75. for item in category:
  76. if str(sort_id) == item['sid']:
  77. return item
  78. return category[0]
  79. class yuyueduProcess():
  80. name = name
  81. allowed_domains = allowed_domains
  82. source = source
  83. source_name = source_name
  84. source_id = source_id
  85. def get_start_url(self):
  86. return base_url.format('bookList')
  87. def bid_list_result(self, response):
  88. result = json.loads(response.text)
  89. if result is None or result.get('data') is None:
  90. return []
  91. result_list = []
  92. for item in result['data']:
  93. result_list.append({'id': item['bookid']})
  94. return result_list
  95. def get_book_info_url(self, bid):
  96. return base_url.format('bookInfo') + '?bookId={}'.format(bid)
  97. def book_info_result(self, response):
  98. result = json.loads(response.text)
  99. result = result['data']
  100. category_info = get_category(result['sort_id']);
  101. return {
  102. 'bid': result['bookid'], 'name': result['title'], 'author': result['author'],
  103. 'intro': result['description'], 'cover': result['cover'], 'keyword': result['tag'],
  104. 'status': result['is_finish'], 'category': category_info['category_name'],'category_id':category_info['category_id'],
  105. 'channel': category_info['channel_id']
  106. }
  107. def get_chapter_list_url(self, bid):
  108. return base_url.format('chapterList') + '?bookId={}'.format(bid)
  109. def chapter_list_result(self, response):
  110. result = json.loads(response.text)
  111. if result is None or result.get('data') is None:
  112. return []
  113. result_list = []
  114. i = 0
  115. for chapter_item in result['data']:
  116. i = i+1
  117. result_list.append({
  118. 'source_chapter_id': chapter_item['id'], 'name': chapter_item['title'],
  119. 'sequence': i, 'is_vip': chapter_item['isvip'],
  120. 'size': 0, 'recent_update_at': chapter_item['update_time']
  121. })
  122. return result_list
  123. def get_chapter_content_url(self, bid, cid):
  124. return base_url.format('content') + '?bookId={}&chapterId={}'.format(bid, cid)
  125. def chapter_content_result(self, response):
  126. result = json.loads(response.text)
  127. if result is None:
  128. return {'content': ''}
  129. return {
  130. 'content': result['data']['content'],
  131. 'size': len(result['data']['content'])
  132. }
  133. class yuyueduSpider(yuyueduProcess,baseSpider):
  134. name = name
  135. custom_settings = {
  136. 'DOWNLOAD_DELAY': 0.1,
  137. 'SOURCE': source,
  138. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  139. }
  140. class yuyueduUpdateSpider(yuyueduProcess,baseUpdateSpider):
  141. name = name + "update"
  142. custom_settings = {
  143. 'DOWNLOAD_DELAY': 0.1,
  144. 'SOURCE': source,
  145. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  146. }
  147. class yuyueduFixSpider(yuyueduProcess,fixChapterSpider):
  148. name = name + 'fix'
  149. custom_settings = {
  150. 'DOWNLOAD_DELAY': 0.1,
  151. 'SOURCE': source,
  152. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  153. }
  154. class yuyueduBookInfoSpider(yuyueduProcess,baseUpdateBookStatusSpider):
  155. name = name + "bookinfo"
  156. custom_settings = {
  157. 'DOWNLOAD_DELAY': 0.1,
  158. 'SOURCE': source,
  159. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  160. }