# Path: crawler/gather/items.py
# class ChannelItem(Item):
#     office_id = Field()
#     short = Field()
#     name = Field()
#     image = Field()
#     url = Field()
# 
# class RoomItem(Item):
#     office_id = Field()
#     name = Field()
#     image = Field()
#     url = Field()
#     online = Field()
#     host = Field()
#     channel = Field()
#     followers = Field()
#     description = Field()
#     announcement = Field()
#     start_time = Field()


from scrapy import Spider, Request
from ..items import ChannelItem, RoomItem
import json
# -*- coding: utf-8 -*-




class LongzhuSpider(Spider):
    name = 'longzhu'
    allowed_domains = ['longzhu.com', 'plu.cn']
    start_urls = [
        'http://www.longzhu.com/channels'
    ]
    custom_settings = {
        'SITE': {
            'code': 'longzhu',
            'name': '龙珠',
            'description': '龙珠直播-游戏直播平台',
            'url': 'http://www.longzhu.com',
            'image': 'http://r.plures.net/plu/images/small-longzhu-logo.png',
            'show_seq': 5
        }
    }

    def parse(self, response):
        channel_list = {}
        for div_element in response.xpath('//div[@class="list-item-thumb"]'):
            a_element = div_element.xpath('a')[0]
            url = a_element.xpath('@href').extract_first()
            short = url[url.rfind('/') + 1:]

# Path: crawler/gather/items.py
# class ChannelItem(Item):
#     office_id = Field()
#     short = Field()
#     name = Field()
#     image = Field()
#     url = Field()
# 
# class RoomItem(Item):
#     office_id = Field()
#     name = Field()
#     image = Field()
#     url = Field()
#     online = Field()
#     host = Field()
#     channel = Field()
#     followers = Field()
#     description = Field()
#     announcement = Field()
#     start_time = Field()


# Path: crawler/gather/spiders/longzhu.py
from scrapy import Spider, Request
from ..items import ChannelItem, RoomItem
import json

# -*- coding: utf-8 -*-




class LongzhuSpider(Spider):
    name = 'longzhu'
    allowed_domains = ['longzhu.com', 'plu.cn']
    start_urls = [
        'http://www.longzhu.com/channels'
    ]
    custom_settings = {
        'SITE': {
            'code': 'longzhu',
            'name': '龙珠',
            'description': '龙珠直播-游戏直播平台',
            'url': 'http://www.longzhu.com',
            'image': 'http://r.plures.net/plu/images/small-longzhu-logo.png',
            'show_seq': 5
        }
    }

    def parse(self, response):
        channel_list = {}
        for div_element in response.xpath('//div[@class="list-item-thumb"]'):
            a_element = div_element.xpath('a')[0]
            url = a_element.xpath('@href').extract_first()
            short = url[url.rfind('/') + 1:]

            name = a_element.xpath('@title').extract_first()