Exemplo n.º 1
0
def ConstructEpisodeSearch(element):

    daysRemaining = None
    res = re.search(
        "(\\d+)", " ".join(
            element.xpath(".//div[@class='remaining-time']//text()")).strip())
    if res:
        daysRemaining = res.groups()[0]

    return MediaItems.Episode(
        id=ITV_URL + element.xpath(".//a/@href")[0],
        title=" ".join(
            element.xpath(".//div[@class='episode-title']//text()")).strip(),
        shortSynopsis=" ".join(
            element.xpath(".//div[@class='description']//text()")).strip(),
        daysRemaining=daysRemaining)
Exemplo n.º 2
0
def ConstructEpisode(element, pageUri):

    id = pageUri
    if len(element.xpath(
            ".//div[contains(@class, 'node-episode')]/a[1]/@href")) > 0:
        id = ITV_URL + element.xpath(
            ".//div[contains(@class, 'node-episode')]/a[1]/@href")[0]
    elif len(element.xpath("./a")) > 0:
        id = ITV_URL + element.xpath("./a[1]/@href")[0]

    title = 'Unknown'
    if len(element.xpath("//h2[@class='title episode-title']")) > 0:
        title = element.xpath("//h2[@class='title episode-title']")[0].text
    elif len(element.xpath(".//div[@class='programme-title']")) > 0:
        title = " ".join(
            element.xpath(".//div[@class='programme-title']//text()")).strip()

    seasonNumber = ''
    if len(
            element.xpath(
                ".//div[contains(@class, 'field-name-field-season-number')]//text()"
            )) > 0:
        seasonNumber = element.xpath(
            ".//div[contains(@class, 'field-name-field-season-number')]//text()"
        )[0]

    episodeNumber = ''
    if len(
            element.xpath(
                ".//div[contains(@class, 'field-name-field-episode-number')]//text()"
            )) > 0:
        episodeNumber = element.xpath(
            ".//div[contains(@class, 'field-name-field-episode-number')]//text()"
        )[0]

    daysRemaining = None
    if len(element.xpath(".//div[@class='offer-duration']")) > 0:
        daysRemaining = re.search(
            "(\\d*)",
            element.xpath(".//div[@class='offer-duration']")
            [0].text.strip()).groups()[0]
    #elif len() > 0:
    #	re.search("(\\d*)",element.xpath(".//div[@class='offer-duration']")[0].text.strip()).groups()[0]

    shortSynopsis = ''
    if len(
            element.xpath(
                ".//div[contains(@class,'field-name-field-short-synopsis')]//text()"
            )) > 0:
        shortSynopsis = element.xpath(
            ".//div[contains(@class,'field-name-field-short-synopsis')]//text()"
        )[0]

    duration = None
    if len(
            element.xpath(
                ".//div[contains(@class, 'field-name-field-duration')]//text()"
            )) > 0:
        res = re.search(
            "(?:(?:(\\d+)(?:\s*hours?\s*))|(?:(\\d+)(?:\s*minutes?))){1,2}",
            " ".join(
                element.xpath(
                    ".//div[contains(@class, 'field-name-field-duration')]//text()"
                )).strip())
        if res:
            duration = (int(res.groups()[0]) if res.groups()[0] else 0) * 60
            duration += (int(res.groups()[1]) if res.groups()[1] else 0)

    lastBroadcast = datetime.datetime.strptime(
        element.xpath(
            ".//div[contains(@class, 'field-name-field-broadcastdate')]//span/@content"
        )[0][:-6], '%Y-%m-%dT%H:%M:%S')

    posterFrameUri = None
    if len(
            element.xpath(
                ".//div[contains(@class,'field-name-field-image')]//img/@src")
    ) > 0:
        posterFrameUri = element.xpath(
            ".//div[contains(@class,'field-name-field-image')]//img/@src")[0]
    elif len(element.xpath(".//param[@name='poster']")) > 0:
        posterFrameUri = element.xpath(".//param[@name='poster']/@value")[0]

    if posterFrameUri:
        posterFrameUri = posterFrameUri.replace('player_image_thumb_standard',
                                                'posterframe')

    return MediaItems.Episode(
        id=id,
        title=title,
        seasonNumber=seasonNumber,
        episodeNumber=episodeNumber,
        duration=duration,
        lastBroadcast=lastBroadcast,
        daysRemaining=daysRemaining,
        shortSynopsis=shortSynopsis,
        posterFrameUri=posterFrameUri,
        #channel                    = element.xpath('./d:AdditionalInfo/d:Channel',namespaces={'d' : ITV_XML_NS})[0].text,
        #channelLogoUrl             = element.xpath('./d:AdditionalInfo/d:ChannelLogoUrl',namespaces={'d' : ITV_XML_NS})[0].text,
    )