crawler_channel_account_videos.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. """
  2. @author: luojunhui
  3. @tool: pycharm && deepseek
  4. """
  5. import json
  6. from applications.db import DatabaseConnector
  7. from config import long_articles_config
  8. from coldStartTasks.crawler.channels import get_channel_account_videos
  9. class CrawlerChannelAccountVideos:
  10. """
  11. crawler channel account videos
  12. """
  13. def __init__(self):
  14. self.db_client = DatabaseConnector(db_config=long_articles_config)
  15. self.db_client.connect()
  16. def get_channel_account_list(self):
  17. """
  18. get channel account list from database
  19. """
  20. return
  21. def crawler_each_account(self, channel_account_id: str, channel_account_name: str):
  22. """
  23. get channel account videos
  24. """
  25. response = get_channel_account_videos(channel_account_id)
  26. if response['ret'] == 200:
  27. response_data = response['data']
  28. last_buffer = response_data['lastBuffer']
  29. continue_flag = response_data['continueFlag']
  30. video_list = response_data['object']
  31. for video in video_list[:1]:
  32. video_id = video['id']
  33. account_name = video['nickname']
  34. object_desc = video['objectDesc']
  35. title = object_desc['description']
  36. media = object_desc['media'][0]
  37. url = media['Url']
  38. decode_key = media['decodeKey']
  39. url_token = media['urlToken']
  40. download_url = url + url_token
  41. print(json.dumps(video, ensure_ascii=False, indent=4))
  42. else:
  43. print(f"crawler channel account {channel_account_name} videos failed")
  44. return
  45. if __name__ == '__main__':
  46. crawler_channel_account_videos = CrawlerChannelAccountVideos()
  47. account_id = 'v2_060000231003b20faec8c5eb8a1cc3d1c902e43cb0774ec288165f96c810e3553f5069c92d73@finder'
  48. crawler_channel_account_videos.crawler_each_account(channel_account_id=account_id, channel_account_name="")