예제 #1
0
def search(q):
    q = q.replace(' ', '-')
    q = q.replace("'", '')
    doc = get_doc(_SEARCH_URL + q)
    rtree = select_all(doc, 'div.search-wrapper')
    results = PlayItemList()
    for l in rtree:
        el = select_one(l, 'h4 a')
        url = get_attr(el, 'href')
        title = get_text(el)
        el = select_one(l, "div.search-result-image a img")
        img = get_attr(el, 'src')
        el = select_one(l, ".search-episode-count")
        matched = int(get_attr(el, 'data-matched_episodes'))
        episodes = get_text(el)
        episodes = int(episodes[0:episodes.find(' ')])
        action = None
        if episodes > matched:
            action = MoreEpisodesAction(url, title)
        eps = select_all(l, ".episode")
        for e in eps:
            el = select_one(e, ".episode-title a")
            url = _PREFIX + get_attr(el, 'href')
            subtitle = get_text(el)
            el = select_one(e, ".description")
            synopsis = get_text_content(el)
            item = PlayItem(title, img, url, subtitle, synopsis)
            results.add(item)
            if action:
                item.add_action(action)
                break
    return results
예제 #2
0
def _extract(doc):
    rtree = select_all(doc, 'li.list-item')
    results = PlayItemList()
    for l in rtree:
        a = select_one(l, 'a')
        url = get_attr(a, 'href')
        if url is None:
            continue
        if url.startswith('/iplayer'):
            url = "http://www.bbc.co.uk" + url

        pdiv = select_one(l, 'div.primary')
        idiv = select_one(pdiv, 'div.r-image')
        if idiv is None:
            idiv = select_one(pdiv, 'div.rs-image')
            idiv = select_one(idiv, 'source')
            img = get_attr(idiv, 'srcset')
        else:
            img = get_attr(idiv, 'data-ip-src')

        sdiv = select_one(l, 'div.secondary')
        title = get_text(select_one(sdiv, 'div.title'))
        subtitle = get_text(select_one(sdiv, 'div.subtitle'))
        synopsis = get_text(select_one(sdiv, 'p.synopsis'))
        item = PlayItem(title, img, url, subtitle, synopsis)
        a = select_one(l, 'a.view-more-container')
        if a is not None:
            link = "http://bbc.co.uk" + a.get('href')
            item.add_action(MoreEpisodesAction(link, title))
        results.add(item)
    return results
예제 #3
0
def _extract_grid(doc):
    rtree = select_all(doc, 'li.grid__item')
    results = PlayItemList()
    for l in rtree:
        a = select_one(l, 'a')
        url = get_attr(a, 'href')
        if url is None:
            continue
        if url.startswith('/iplayer'):
            url = "http://www.bbc.co.uk" + url
        idiv = select_one(l, 'div.rs-image')
        idiv = select_one(idiv, 'img')
        img = get_attr(idiv, 'srcset').split()[0]

        sdiv = select_one(l, 'div.content-item__info__text')
        avail = select_one(sdiv, 'div.content-item__labels')
        if get_text_content(avail) == "Not available":
            continue

        title = get_text_content(select_one(sdiv, 'div.content-item__title'))
        subtitle = get_text_content(
            select_one(sdiv, 'div.content-item__description'))
        if title.endswith("..."):
            title = title[:-3]
        if subtitle.endswith("..."):
            subtitle = subtitle[:-3]

        item = PlayItem(title, img, url, subtitle)
        a = select_one(l, 'a.js-view-all-episodes')
        if a is not None:
            link = "http://bbc.co.uk" + a.get('href')
            item.add_action(MoreEpisodesAction(link, title))
        results.add(item)
    return results
예제 #4
0
def _extract(doc):
    rtree = select_all(doc, 'li.browse-content-item-videos')
    results = PlayItemList()
    for l in rtree:
        el = select_one(l, 'a')
        href = get_attr(el, 'href')
        if href is None:
            continue
        url = _PREFIX + href
        el = select_one(l, 'img')
        img = get_attr(el, 'src')
        el = select_one(l, 'div.browse-content-top-line')
        subtitle = get_text(el)
        el = select_one(l, 'div.browse-content-second-line')
        title = get_text(el)
        results.add(PlayItem(title, img, url, subtitle))
    return results

    results = PlayItemList()
    for l in rtree:
        el = select_one(l, 'a')
        url = get_attr(el, 'href')
        if not url.startswith('/talks/'):
            continue
        url = _PREFIX + url
        title = get_text(el)
        el = select_one(l, 'img')
        img = get_attr(el, 'src')
        el = select_one(l, 'div.search__result__description')
        synopsis = get_text(el)
        results.add(PlayItem(title, img, url, synopsis=synopsis))
    return results
예제 #5
0
def feed(idx):
    url = _FEEDLIST[idx]['url']
    doc = get_doc(url)
    rtree = select_all(doc, "a.complex-link")
    results = PlayItemList()
    for l in rtree:
        url = get_attr(l, 'href')
        el = select_one(l, '.tout__title')
        if el is None:
            continue
        title = get_text(el)
        el = select_one(l, 'img.fluid-media__media')
        img = get_attr(el, 'src')
        el = select_one(l, 'p.tout__meta')
        subtitle = get_text_content(el)
        if subtitle == 'No episodes available':
            continue
        item = PlayItem(title, img, url, subtitle)
        if subtitle != '1 episode':
            item.add_action(MoreEpisodesAction(url, title))
        results.add(item)
    if idx == 0:
        global _SHOWLIST
        _SHOWLIST = results
    return results
예제 #6
0
 def __init__(self):
     self.__dict__ = self._shared_state
     self.api = Api()
     self.play_item = PlayItem()
     self.state = State()
     self.player = Player()
     self.demo = DemoOverlay(12005)
예제 #7
0
def search(q):
  shows = get_json(_ALL_SHOWS_URL)
  results = PlayItemList()
  for i in shows:
    if not 'episode' in i['url']:
      continue
    if q.lower() in i['title'].lower():
      item = PlayItem(i['title'], i['image']['jelly'], i['url']['episode'], i['synopses'])
      print i['url']['episode'] 
      item.add_action(MoreEpisodesAction(i['url']['episode'], i['title']))
      results.add(item)
      #results.add(PlayItem(i['title'], i['image']['jelly'], i['url']['episode'], i['synopses']))
  return results
예제 #8
0
def _extract_search(search_json):
    results = PlayItemList()
    for track in search_json:
        kind = track['kind']
        if kind != 'track':
            continue
        title = track['title']
        user = track['user']['username']
        if track['duration'] != track['full_duration']:
            continue
        duration_s = track['duration'] // 1000
        duration = str(timedelta(seconds=duration_s))
        plays = 'likes: ' + \
            human_format(track['likes_count']) + ' plays: ' + \
            human_format(track['playback_count'])
        subtitle = user + '<br/> duration: ' + duration + ' ' + plays
        if track['artwork_url'] and track['artwork_url'] != '':
            img = track['artwork_url'].replace('-large.', '-t300x300.')
        elif track['user']['avatar_url'] and track['user']['avatar_url'] != '':
            img = track['user']['avatar_url'].replace('-large.', '-t300x300.')
        else:
            img = '/img/icons/music.svg'
        url = track['permalink_url']
        results.add(PlayItem(title, img, url, subtitle))
    return results
예제 #9
0
def _extract_popular(doc):
    rtree = select_all(doc, 'li.most-popular__item')
    results = PlayItemList()

    for l in rtree:
        a = select_one(l, 'a')
        url = get_attr(a, 'href')
        if url is None:
            continue
        if url.startswith('/iplayer'):
            url = "http://www.bbc.co.uk" + url
        idiv = select_one(l, 'div.rs-image')
        idiv = select_one(idiv, 'source')
        img = get_attr(idiv, 'srcset')
        img = img.split()[0]

        idiv = select_one(l, 'div.content-item__info__text')
        title = get_text(select_one(idiv, 'div.content-item__title'))
        pdiv = select_one(idiv, 'div.content-item__info__primary')
        subtitle = get_text(select_one(pdiv, 'div.content-item__description'))
        pdiv = select_one(idiv, 'div.content-item__info__secondary')
        synopsis = get_text(select_one(pdiv, 'div.content-item__description'))
        item = PlayItem(title, img, url, subtitle, synopsis)
        results.add(item)
    return results
예제 #10
0
def feed(idx):
    url = _FEEDLIST[idx]['url']
    doc = get_doc(url)
    rtree = select_all(doc, 'li.programme')
    results = PlayItemList()
    for l in rtree:
        el = select_one(l, '.programme-title a')
        url = _PREFIX + get_attr(el, 'href')
        title = get_text(el)
        el = select_one(l, 'img')
        img = get_attr(el, 'src')
        subtitle = get_text(select_one(l, '.episode-info span.episode-free'))
        item = PlayItem(title, img, url, subtitle)
        if (subtitle is not None) and (not subtitle.startswith('1 ')):
            item.add_action(MoreEpisodesAction(url, title))
        results.add(item)
    return results
예제 #11
0
def feed(idx):
    folder = _FEEDLIST[idx]['folder']
    results = PlayItemList()
    files = os.listdir(folder)
    for f in files:
        title = os.path.splitext(f)[0]
        url = 'file://' + os.path.join(folder, f)
        results.add(PlayItem(title, '/img/icons/file-o.svg', url))
    return results
예제 #12
0
def _extract(text):
    start = text.find('var data = {')
    end = text.find('console.debug(data);', start)
    data = json.loads(text[start + 11:end - 14])
    results = PlayItemList()
    for item in data['filtered']['data']:
        url = item['clip']['link']
        title = item['clip']['name']
        img = item['clip']['pictures']['sizes'][-1]['link']
        results.add(PlayItem(title, img, url))
    return results
예제 #13
0
def _extract(data):
    results = PlayItemList()
    rtree = data['results']
    for r in rtree:
        title = replace_entity(r['title'])
        img = r['thumbnailUrl']
        if 'url' in r:
            url = r['url']
        else:
            url = r['URL']
        results.add(PlayItem(title, img, url))
    return results
예제 #14
0
def _extract(doc):
    rtree = select_all(doc, '#browse_content li a')
    results = PlayItemList()
    for l in rtree:
        url = _PREFIX + l.get('href')
        title = get_attr(l, 'title')
        if title is None:
            break
        el = select_one(l, 'img')
        img = get_attr(el, 'src')
        el = select_one(l, 'time')
        subtitle = get_text(el)
        results.add(PlayItem(title, img, url, subtitle))
    return results
예제 #15
0
def _extract(doc):
    results = PlayItemList()
    rtree = select_all(doc, 'div.col')
    for r in rtree:
        el = select_one(r, "h4")
        title = get_text(el)
        if not title:
            continue
        el = select_one(r, "img")
        img = get_attr(el, "src")
        el = select_one(r, "a.js-click-video")
        url = get_attr(el, "href")
        results.add(PlayItem(title, img, url))
    return results
예제 #16
0
def feed(idx):
  doc = get_doc(_FEEDLIST[idx]['url'])
  rtree = select_all(doc, 'div.thumbs li')
  results = PlayItemList()
  for l in rtree:
    el = select_one(l, 'a')
    url = get_attr(el, 'href')
    el = select_one(l, 'img')
    img = get_attr(el, 'src')
    el = select_one(l, 'h4.talk-link__speaker')
    subtitle = get_text(el)
    el = select_one(l, 'a span')
    title = get_text(el)
    results.add(PlayItem(title, img, url, subtitle))
  return results
예제 #17
0
def search(q):
    url = _SEARCH_URL + q + "&range=1-50"
    count = 0
    results = PlayItemList()
    shows = get_json(url)
    for ep_info in shows["entries"]:
        video_key = ep_info["id"]
        title = ep_info["title"]
        description = ep_info["description"]
        thumbnail = ep_info["plmedia$defaultThumbnailUrl"]
        video_url = VIDEO_URL % video_key.split("/")[-1]
        item = PlayItem(title, thumbnail, video_url, description)
        results.add(item)

    return results
예제 #18
0
def feed(idx):
  doc = get_doc(_FEEDLIST[idx]['url'])
  rtree = select_all(doc, 'div.post-block')
  results = PlayItemList()
  for l in rtree:
    el = select_one(l, 'a')
    url = get_attr(el, 'href')
    el = select_one(l, 'img')
    img = get_attr(el, 'src')
    el = select_one(l, 'div.post-block__content')
    subtitle = get_text(el)
    el = select_one(l, 'a.post-block__title__link')
    title = get_text(el)
    results.add(PlayItem(title, img, url, subtitle))
  return results
예제 #19
0
def feed(idx):
    url = _FEEDLIST[idx]['url']
    count = 0
    results = PlayItemList()
    shows = get_json(url)
    for ep_info in shows["entries"]:
        video_key = ep_info["id"]
        title = ep_info["title"]
        description = ep_info["description"]
        thumbnail = ep_info["plmedia$defaultThumbnailUrl"]
        video_url = VIDEO_URL % video_key.split("/")[-1]
        item = PlayItem(title, thumbnail, video_url, description)
        results.add(item)

    return results
예제 #20
0
def search(q):
  url = _SEARCH_URL + q
  count = 0
  results = PlayItemList()
  shows = get_json(url)
  for ep_info in shows:
    video_key = ep_info["episodeHouseNumber"]
    series_title = ep_info["seriesTitle"]
    title = ep_info.get("title", None)
    episode_title = format_episode_title(series_title, title)
    thumbnail = ep_info["thumbnail"]
    video_url = API_URL + "/programs/" + video_key
    item = PlayItem(series_title, thumbnail, video_url, title, episode_title)
    results.add(item)

  return results
예제 #21
0
def _extract(data):
  results = PlayItemList()
  if not 'data' in data or data['data']['totalItems'] == 0:
    return results
  rtree = data['data']['items']
  for r in rtree:
    title = r['title']
    img = r['thumbnail']['sqDefault']
    url = r['player']['default']
    m, s = divmod(r['duration'], 60)
    h, m = divmod(m, 60)
    subtitle = 'Duration: ' + "%d:%02d:%02d" % (h, m, s)
    if 'viewCount' in r:
      subtitle = subtitle + ', Views: ' + "{:,}".format(r['viewCount'])
    results.add(PlayItem(title, img, url, subtitle))
  return results
예제 #22
0
def _extract(data):
    results = PlayItemList()
    rtree = data['items']
    for r in rtree:
        title = r['snippet']['title']
        subtitle = r['snippet']['publishedAt'][:10]
        synopsis = r['snippet']['description']
        if len(synopsis) > 200:
            synopsis = synopsis[:200] + "..."
        img = r['snippet']['thumbnails']['default']['url']
        if isinstance(r['id'], basestring):
            vid = r['id']
        else:
            vid = r['id']['videoId']
        url = 'https://www.youtube.com/watch?v=' + vid
        results.add(PlayItem(title, img, url, subtitle, synopsis))
    return results
예제 #23
0
def showmore(link):
    doc = get_doc(link)
    rtree = select_all(doc, "a.complex-link")
    results = PlayItemList()
    for l in rtree:
        url = get_attr(l, 'href')
        el = select_one(l, 'img.fluid-media__media')
        img = get_attr(el, 'src')
        el = select_one(l, 'h3')
        title = get_text(el)
        el = select_one(l, 'time')
        subtitle = get_text(el)
        el = select_one(l, 'p.tout__summary')
        synopsis = get_text(el)
        item = PlayItem(title, img, url, subtitle, synopsis)
        results.add(item)
    return results
예제 #24
0
def search(q):
    doc = get_doc(_SEARCH_URL, params={'q': q})
    rtree = select_all(doc, 'article.search__result')
    results = PlayItemList()
    for l in rtree:
        el = select_one(l, 'a')
        url = get_attr(el, 'href')
        if not url.startswith('/talks/'):
            continue
        url = _PREFIX + url
        title = get_text(el)
        el = select_one(l, 'img')
        img = get_attr(el, 'src')
        el = select_one(l, 'div.search__result__description')
        synopsis = get_text(el)
        results.add(PlayItem(title, img, url, synopsis=synopsis))
    return results
예제 #25
0
def feed(idx):
  url = _FEEDLIST[idx]['url']
  count = 0 
  results = PlayItemList()
  shows = get_json(url)
  for index_list in shows["index"]:
    for ep_info in index_list["episodes"]:
      video_key = ep_info["episodeHouseNumber"]
      series_title = ep_info["seriesTitle"]
      title = ep_info.get("title", None)
      #episode_title = format_episode_title(series_title, title)
      episode_title = ep_info["description"] 
      thumbnail = ep_info["thumbnail"]
      video_url = API_URL + "/programs/" + video_key 
      item = PlayItem(series_title, thumbnail, video_url, title, episode_title) 
      if ep_info["livestream"] == "0":
        results.add(item)

  return results
예제 #26
0
def _extract(data):
    videos = data['videos']
    results = PlayItemList()
    for v in videos:
        title = v['title']
        img = v['thumbnailUrl']
        url = "http://www.vevo.com/watch/"
        if 'artists' in v:
            artist = v['artists'][0]
        else:
            artist = v['primaryArtists'][0]
        subtitle = artist['name']
        url = url + artist['urlSafeName'] + '/'
        if 'urlSafeTitle' in v:
            url = url + v['urlSafeTitle'] + '/'
        else:
            url = url + v['title'] + '/'
        url = url + v['isrc']
        results.add(PlayItem(title, img, url, subtitle))
    return results
예제 #27
0
def showmore(link):
    doc = get_doc(link)
    rtree = select_all(doc, 'div.views-row')
    results = PlayItemList()
    for l in rtree:
        el = select_one(l, 'a')
        url = _PREFIX + get_attr(el, 'href')
        el = select_one(el, 'img')
        img = get_attr(el, 'src')
        el = select_one(l, 'span.date-display-single')
        subtitle = get_text(el)
        el = select_one(l, 'div.field-season-number')
        title1 = get_text_content(el)
        el = select_one(l, 'div.field-episode-number')
        title = title1 + " " + get_text_content(el)
        el = select_one(l, 'div.field-name-field-short-synopsis')
        synopsis = get_text_content(el)
        item = PlayItem(title, img, url, subtitle, synopsis)
        results.add(item)
    return results
예제 #28
0
def _extract(data):
    results = PlayItemList()
    if not ('tracks' in data or 'collection' in data):
        return results
    if 'tracks' in data:
        rtree = data['tracks']
    else:
        rtree = data['collection']
    for r in rtree:
        if not 'title' in r:
            continue
        if not r['streamable']:
            continue
        title = r['title']
        if r['artwork_url']:
            img = r['artwork_url']
        else:
            img = r['user']['avatar_url']
        url = r['permalink_url']
        subtitle = 'Plays: ' + number_commas(r['playback_count'])
        subtitle = subtitle + ', Likes: ' + number_commas(r['likes_count'])
        results.add(PlayItem(title, img, url, subtitle))
    return results
예제 #29
0
def _extract(doc):
    rtree = select_all(doc, 'div.thumb-block')
    results = PlayItemList()
    for l in rtree:
        ti = select_one(l, 'div.thumb-inside')
        ael = select_one(ti, 'a')
        url = _ROOT_URL + get_attr(ael, 'href')
        imgel = select_one(ael, 'img')
        img = get_attr(imgel, 'data-src')
        img = img.replace('THUMBNUM', '2')
        tu = select_one(l, 'div.thumb-under')
        el = select_one(tu, 'a')
        title = get_text(el)
        el = select_one(tu, 'p.metadata')
        lxml.etree.strip_tags(el, '*')
        strings = el.text.replace('\n', ' ').split(' ')
        strings = [x for x in strings if x.strip()]
        if len(strings) == 2:
            size = strings[0]
            rating = "NA"
            duration = strings[1]
        elif len(strings) == 3:
            size = strings[0]
            rating = strings[1]
            duration = strings[2]
        elif len(strings) == 4:
            size = strings[0]
            rating = strings[1]
            duration = strings[2] + " " + strings[3]
        subtitle = _subtitle({
            'Duration': duration,
            'Size': size,
            'Rating': rating
        })
        results.add(PlayItem(title, img, url, subtitle))
    return results
예제 #30
0
def feed(idx):
  url = _FEEDLIST[idx]['url']
  doc = get_doc(url)
  
  livetree = select_all(doc, "div.genie-container")
  results = PlayItemList()
  
  for l in livetree:
    img = get_attr(l, "data-video-posterframe")
    title = get_attr(l, "data-video-channel-id")
    item = PlayItem(title.upper(), img, url, 'Watch LIVE TV')
    results.add(item)
  
  rtree = select_all(doc, "a.complex-link")
  for l in rtree:
    url = get_attr(l, 'href')
    el = select_one(l, '.tout__title')
    if el is None:
      el = select_one(l, '.slice__title')
      if el is None:
        continue
    title = get_text(el)
    el = select_one(l, 'img.fluid-media__media')
    img = get_attr(el, 'src')
    el = select_one(l, 'p.tout__summary')
    if el is None:
      el = select_one(l, 'p.tout__meta')
      if el is None:
        el = select_one(l, 'p.slice__meta')
    subtitle = get_text_content(el)
    if subtitle == 'No episodes available':
      continue    
    item = PlayItem(title, img, url, subtitle)
    if subtitle != '1 episode':
      item.add_action(MoreEpisodesAction(url, title))
    results.add(item)
    
      
  return results