aiyouhuyu.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 = 'aiyouhuyu'
  9. allowed_domains = ['bookapi.fensebook.com']
  10. source = 'zy_aiyouhuyu'
  11. source_name = 'aiyouhuyu哎呦互娱'
  12. source_id = 34
  13. appKey = 'ToZYZSY202304101759'
  14. appSecret = '9000bd89f6cc8e27619d10883f7f6b51'
  15. base_url = 'http://bookapi.fensebook.com/bookApi/{}?appKey='+appKey + '&appSecret='+appSecret
  16. category = [{'id': 1001, 'name': '都市', 'channel_id': 1, 'category_name': '都市爱情', 'category_id': 54},
  17. {'id': 1002, 'name': '玄幻', 'channel_id': 1, 'category_name': '武侠仙侠', 'category_id': 21},
  18. {'id': 1003, 'name': '仙侠', 'channel_id': 1, 'category_name': '武侠仙侠', 'category_id': 21},
  19. {'id': 1004, 'name': '历史', 'channel_id': 1, 'category_name': '历史穿越', 'category_id': 14},
  20. {'id': 1005, 'name': '灵异', 'channel_id': 1, 'category_name': '灵异恐怖', 'category_id': 81},
  21. {'id': 1006, 'name': '游戏', 'channel_id': 1, 'category_name': '游戏竞技', 'category_id': 19},
  22. {'id': 1007, 'name': '科幻', 'channel_id': 1, 'category_name': '玄幻奇幻', 'category_id': 23},
  23. {'id': 1008, 'name': '奇幻', 'channel_id': 1, 'category_name': '玄幻奇幻', 'category_id': 23},
  24. {'id': 1009, 'name': '军事', 'channel_id': 1, 'category_name': '历史穿越', 'category_id': 14},
  25. {'id': 1012, 'name': '武侠', 'channel_id': 1, 'category_name': '武侠仙侠', 'category_id': 21},
  26. {'id': 1014, 'name': '竞技', 'channel_id': 1, 'category_name': '游戏竞技', 'category_id': 19},
  27. {'id': 1016, 'name': '悬疑', 'channel_id': 1, 'category_name': '灵异恐怖', 'category_id': 81},
  28. {'id': 1019, 'name': '二次元', 'channel_id': 1, 'category_name': '其他作品', 'category_id': 127},
  29. {'id': 1020, 'name': '轻小说', 'channel_id': 1, 'category_name': '其他作品', 'category_id': 127},
  30. {'id': 1021, 'name': '现实', 'channel_id': 1, 'category_name': '其他作品', 'category_id': 127},
  31. {'id': 2001, 'name': '现代言情', 'channel_id': 2, 'category_name': '婚恋情感', 'category_id': 87},
  32. {'id': 2002, 'name': '古代言情', 'channel_id': 2, 'category_name': '穿越重生', 'category_id': 83},
  33. {'id': 2003, 'name': '幻想言情', 'channel_id': 2, 'category_name': '东方玄幻', 'category_id': 96},
  34. {'id': 2004, 'name': '青春校园', 'channel_id': 2, 'category_name': '青春校园', 'category_id': 104},
  35. {'id': 2007, 'name': '短篇', 'channel_id': 2, 'category_name': '其他', 'category_id': 107},
  36. {'id': 2009, 'name': '悬疑', 'channel_id': 2, 'category_name': '悬疑探险', 'category_id': 113},
  37. {'id': 2011, 'name': '穿越架空', 'channel_id': 2, 'category_name': '穿越重生', 'category_id': 83},
  38. {'id': 2012, 'name': '纯爱', 'channel_id': 2, 'category_name': '青春纯爱', 'category_id': 103},
  39. {'id': 2013, 'name': '二次元', 'channel_id': 2, 'category_name': '其他', 'category_id': 107},
  40. {'id': 2014, 'name': '科幻空间', 'channel_id': 2, 'category_name': '东方玄幻', 'category_id': 96},
  41. {'id': 2015, 'name': '玄幻言情', 'channel_id': 2, 'category_name': '东方玄幻', 'category_id': 96},
  42. {'id': 2016, 'name': '仙侠奇缘', 'channel_id': 2, 'category_name': '东方玄幻', 'category_id': 96},
  43. {'id': 2017, 'name': '浪漫青春', 'channel_id': 2, 'category_name': '青春纯爱', 'category_id': 103},
  44. {'id': 2018, 'name': '游戏竞技', 'channel_id': 2, 'category_name': '游戏', 'category_id': 113},
  45. {'id': 2019, 'name': '轻小说', 'channel_id': 2, 'category_name': '其他', 'category_id': 107},
  46. {'id': 2020, 'name': '现实生活', 'channel_id': 2, 'category_name': '其他', 'category_id': 107},
  47. {'id': 2021, 'name': '职场沉浮', 'channel_id': 2, 'category_name': '其他', 'category_id': 107}]
  48. def get_category(category_name):
  49. for item in category:
  50. if category_name == item['name']:
  51. return item
  52. return category[0]
  53. class aiyouhuyuProcess():
  54. name = name
  55. allowed_domains = allowed_domains
  56. source = source
  57. source_name = source_name
  58. source_id = source_id
  59. def get_start_url(self):
  60. return base_url.format('getBookList')
  61. def bid_list_result(self, response):
  62. result = json.loads(response.text)
  63. if result is None or result.get('data') is None:
  64. return []
  65. result_list = []
  66. for item in result['data']:
  67. result_list.append({'id': item['bookId']})
  68. return result_list
  69. def get_book_info_url(self, bid):
  70. return base_url.format('getBookInfo') + '&bookId={}'.format(bid)
  71. def book_info_result(self, response):
  72. result = json.loads(response.text)
  73. result = result.get('data')
  74. category_info = get_category(result['category'])
  75. return {
  76. 'bid': result['bookId'], 'name': result['bookName'], 'author': result['author'],
  77. 'intro': result['desc'], 'cover': result['cover'],
  78. 'keyword': '' if result['keyWords'] is None else result['keyWords'],
  79. 'status': result['isFinished'],'category': category_info['category_name'],'category_id':category_info['category_id'],
  80. 'channel': category_info['channel_id']
  81. }
  82. def get_chapter_list_url(self, bid):
  83. return base_url.format('getChapterList') + '&bookId={}'.format(bid)
  84. def chapter_list_result(self, response):
  85. result = json.loads(response.text)
  86. if result is None or result.get('data') is None:
  87. return []
  88. result_list = []
  89. i = 0
  90. for chapter_item in result['data']:
  91. i = i+1
  92. result_list.append({
  93. 'source_chapter_id': chapter_item['id'], 'name': chapter_item['title'],
  94. 'sequence': chapter_item['sort'], 'is_vip': 0 if int(chapter_item['vip']) == 1 else 1,
  95. 'size': chapter_item['words'], 'recent_update_at': chapter_item['updateTime']
  96. })
  97. return result_list
  98. def get_chapter_content_url(self, bid, cid):
  99. return base_url.format('getContent') + '&bookId={}&chapterId={}'.format(bid, cid)
  100. def chapter_content_result(self, response):
  101. result = json.loads(response.text)
  102. if result is None or result.get('data') is None:
  103. return {'content': ''}
  104. return {
  105. 'content': result['data']['content'],
  106. 'size': len(result['data']['content'])
  107. }
  108. class aiyouhuyuSpider(aiyouhuyuProcess,baseSpider):
  109. name = name
  110. custom_settings = {
  111. 'DOWNLOAD_DELAY': 0.1,
  112. 'SOURCE': source,
  113. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  114. }
  115. class aiyouhuyuUpdateSpider(aiyouhuyuProcess,baseUpdateSpider):
  116. name = name + "update"
  117. custom_settings = {
  118. 'DOWNLOAD_DELAY': 0.1,
  119. 'SOURCE': source,
  120. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  121. }
  122. class aiyouhuyuFixSpider(aiyouhuyuProcess,fixChapterSpider):
  123. name = name + 'fix'
  124. custom_settings = {
  125. 'DOWNLOAD_DELAY': 0.1,
  126. 'SOURCE': source,
  127. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  128. }
  129. class aiyouhuyuBookInfoSpider(aiyouhuyuProcess,baseUpdateBookStatusSpider):
  130. name = name + "bookinfo"
  131. custom_settings = {
  132. 'DOWNLOAD_DELAY': 0.1,
  133. 'SOURCE': source,
  134. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  135. }