def ololink(params): caption = 'If you have trouble:goto:https://sites.google.com/site/kokiarbic/help' action = {'info': 1} cap_link = util.makeLink(action) util.addMenuItem(caption, cap_link, icon, fanart, False) url = (params['video']) videoPage = requests.get(url) if videoPage and videoPage.status_code == 200: cont = videoPage.text vidlinks = util.extractAll(cont, '"playerst"', '/iframe>') for vidlink in vidlinks: t = 'Movielink' v = util.extract(vidlink, 'SRC="', '"') or util.extract( vidlink, 'src="', '"') paramz = {'play': 1} paramz['title'] = t paramz['videolink'] = v paramz['image'] = params['image'] link = util.makeLink(paramz) util.addMenuItem(paramz['title'], link, 'DefaultVideo.png', paramz['image'], False) else: util.showError(ADDON_ID, 'Could not open URL %s to create menu' % (url)) util.endListing()
def getCategories(url): param = {'category': 1} content = util.getURL(url, hdr) if content != False: cats = util.extractAll(content, '<div class="item">', '<div class="item">') for film in cats: param['title'] = makeAscii(util.extract(film, 'title="', '"')) param['url'] = 'http://www.likuoo.com' + util.extract( film, '<a href="', '" title="') param['poster'] = util.extract(film, 'src="', '" title="') param['fanart'] = param['poster'] xbmc.log("Play URL:" + param['url'], xbmc.LOGERROR) if param['url'] != None: u = sys.argv[0] + "?url=" + param[ 'url'] + "&mode=2&name=" + urllib.quote_plus( param['title']) + "&poster=" + param['poster'] liz = xbmcgui.ListItem(param['title'], iconImage="DefaultVideo.png", thumbnailImage=param['poster']) liz.setInfo(type="Video", infoLabels={ "Title": param['title'], "Plot": "" }) liz.setProperty("Poster_Image", param['poster']) ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=True) xbmcplugin.endOfDirectory(int(sysarg))
def pages(params): page = int(params['page']) p = 'page:' + str(page) util.addMenuItem(p, None, None, None, False) Baseurl = 'http://el7l.tv/online2/12/_%D8%A7%D9%81%D9%84%D8%A7%D9%85_%D8%B9%D8%B1%D8%A8%D9%8A%D8%A9/' url = Baseurl + '%d.html' % (page) response = requests.get(url) if response and response.status_code == 200: cont = response.text videos = util.extractAll(cont, '<div class="file_index">', '/div>') for video in videos: t = util.extract(video, 'alt="', '"') v = util.extract(video, 'a href="http://el7l.tv/online', '"') vp = 'http://el7l.tv/play' + v i = util.extract(video, 'img src="', '"') params = {'listing': 1} params['title'] = t params['video'] = vp params['image'] = i link = util.makeLink(params) util.addMenuItem(params['title'], link, 'DefaultVideo.png', params['image'], True) else: util.showError(ADDON_ID, 'Could not open URL %s to create menu' % (url)) parms = {'old': 1, 'page': str(page + 1)} page_link = util.makeLink(parms) util.addMenuItem('Next Page:>> ', page_link, None, None, True) util.endListing()
def search(): dialog = xbmcgui.Dialog() i = dialog.input('Enter Movie Name:', type=xbmcgui.INPUT_ALPHANUM) q = urllib.quote(i, safe="%/:=&?~#+!$,;'@()*[]") baseurl = 'https://www.google.com.sa/search?rlz=1C1CHZL_enSA679SA679&espv=2&q=el7al.tv+' print q url = baseurl + q + '&oq=el7al.tv+' + q + '&gs_l=serp.3...33231.51533.0.52317.42.30.8.0.0.0.211.4360.0j21j4.25.0....0...1c.1.64.serp..11.22.2813.0..0j30i10k1j0i13k1j0i13i30k1j0i7i30k1j35i39k1j0i131k1j0i10i30k1j0i13i10k1.w4AW4pCV-E4' response = requests.get(url) if response and response.status_code == 200: cont = response.text videos = util.extractAll(cont, '<a href="/url?q=http://el7l.tv/online', 'class="_cD"') for video in videos: t = util.extract(video, '>', '</a>') t1 = (t.replace('\n', '').replace('\t', '').replace('</b>', '').replace('<b>', '').lstrip()) u1 = (util.extract(video, '/', '&')) u = 'http://el7l.tv/play/' + u1 params = {'search': 1} params['url'] = u params['title'] = t1 link = util.makeLink(params) util.addMenuItem(params['title'], link, None, None, True) util.endListing() else: util.showError(ADDON_ID, 'Could not open URL %s to create menu' % (url))
def menuLink(params): caption = 'try HD first: #1--OK.ru ,#2--openload(try it several clicks until work) ' action = {'info': 1} cap_link = util.makeLink(action) util.addMenuItem(caption, cap_link, icon, fanart, False) url = (params['video']) videoPage = requests.get(url) if videoPage and videoPage.status_code == 200: cont = videoPage.text vidlinks = util.extractAll(cont, '<div id="tab', '/div>') for vidlink in vidlinks: t = util.extract(vidlink, '://', '/') v = util.extract(vidlink, 'SRC="', '"') or util.extract( vidlink, 'src="', '"') paramz = {'play': 1} paramz['title'] = t paramz['videolink'] = v paramz['image'] = params['image'] link = util.makeLink(paramz) util.addMenuItem(paramz['title'], link, 'DefaultVideo.png', paramz['image'], False) else: util.showError(ADDON_ID, 'Could not open URL %s to create menu' % (url)) util.endListing()
def getVids(params) : param={'play':1} content=util.getURL(params['url'], hdr) if content!=False: films=util.extractAll(content, '<div class="item">', '<div class="item">') for film in films: param['title']=makeAscii(util.extract(film, 'title="', '"')) param['url']=util.extract(film, '<a href="', '" title="') param['poster']=util.extract(film, 'src="', '" title="') param['fanart']=param['poster'] if param['url']!=None: u=sys.argv[0]+"?url="+param['url']+"&play="+str(4)+"&name="+urllib.quote_plus(param['title'])+"&poster="+param['poster'] liz=xbmcgui.ListItem(param['title'], iconImage="DefaultVideo.png", thumbnailImage=param['poster']) liz.setInfo( type="Video", infoLabels={ "Title": param['title'],"Plot": ""} ) liz.setProperty("Poster_Image", param['poster']) ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True) next=util.extract(content, '<span class="current">', '</span>') #xbmc.log(">>>>>"+str(next), xbmc.LOGERROR) if next!=None: next=int(next)+1 #xbmc.log('http://www.likuoo.com/new/'+str(next), xbmc.LOGERROR) if 'http://www.likuoo.com/new/'+str(next) in content: util.addDir("Next >", 'http://www.likuoo.com/new/'+str(next), 2, "","") xbmcplugin.endOfDirectory(int(sysarg))
def playVideo(params): content=util.getURL(params['url'].encode('utf-8'), hdr) if content!=False: """if "https://openload" in content: xbmc.log("openload", xbmc.LOGERROR) download=util.extract(content, '<iframe src="https://openload', '"') openloadurl ='http://openload'+download.encode('utf-8') videourl=resolve(openloadurl) ol=util.getURL(openloadurl, hdr) videourl=util.extract(ol, '<source type="video/mp4" src="', '"') """ if 'videourl' not in locals() and "http://videowood.tv/embed/" in content: xbmc.log("videowood", xbmc.LOGERROR) download=util.extract(content, 'http://videowood.tv/embed/', '"') videowoodurl='http://videowood.tv/embed/'+download vw=util.getURL(videowoodurl, hdr) #xbmc.log(vw, xbmc.LOGERROR) videourls=util.extractAll(vw, "file: '", "',") for vid in videourls: if '.mp4' in vid: videourl=vid break try: videourl except: result="eval("+util.extract(vw, "eval(", "</script") xbmc.log(result, xbmc.LOGERROR) result=jsunpack.unpack(result) xbmc.log(result, xbmc.LOGERROR) if 'videourl' not in locals() and "videomega.tv" in content: xbmc.log("videomega", xbmc.LOGERROR) videosource=content if re.search("videomega.tv/iframe.js", videosource, re.DOTALL | re.IGNORECASE): hashref = re.compile("""javascript["']>ref=['"]([^'"]+)""", re.DOTALL | re.IGNORECASE).findall(videosource) elif re.search("videomega.tv/iframe.php", videosource, re.DOTALL | re.IGNORECASE): hashref = re.compile(r"iframe\.php\?ref=([^&]+)&", re.DOTALL | re.IGNORECASE).findall(videosource) else: hashkey = re.compile("""hashkey=([^"']+)""", re.DOTALL | re.IGNORECASE).findall(videosource) if len(hashkey) > 1: i = 1 hashlist = [] for x in hashkey: hashlist.append('Part ' + str(i)) i += 1 vmvideo = dialog.select('Multiple parts found', hashlist) hashkey = hashkey[vmvideo] else: hashkey = hashkey[0] hashpage = getHtml('http://videomega.tv/validatehash.php?hashkey='+hashkey, params['url'].encode('utf-8')) hashref = re.compile('ref="([^"]+)', re.DOTALL | re.IGNORECASE).findall(hashpage) videopage = getHtml('http://videomega.tv/view.php?ref='+hashref[0], params['url'].encode('utf-8')) videourl = re.compile('<source src="([^"]+)"', re.DOTALL | re.IGNORECASE).findall(videopage) videourl = videourl[0] xbmc.log(videourl, xbmc.LOGERROR) util.playMedia(params['name'], params['poster'],videourl, "Video")
def playVideo(params): content=util.getURL(params['url'], hdr) if content!=False: vidID=util.extract(content, 'file: "http://videos.woodrocket.com/vid/', '.mp4", label: "480p"') source=util.extract(content, 'sources: [', '],') if 'label: "720p HD"' in source: util.playMedia(params['name'], params['poster'], "http://videos.woodrocket.com/vid/"+vidID+".hd.mp4", "Video") else: util.playMedia(params['name'], params['poster'], "http://videos.woodrocket.com/vid/"+vidID+".mp4", "Video")
def getGenres(url, hdr): content=util.getURL(url, hdr) if content!=False: allGenres=util.extract(content, '<ul class="scrolling cat">', '</ul>') genres=util.extractAll(allGenres, '<a href', 'a>') for genre in genres: util.addDir(util.extract(genre, '>', '</'), util.extract(genre, '="', '"'), 1, "") xbmcplugin.endOfDirectory(int(sysarg))
def handle_arrival_msg(self): msg = self.network_layer.recv() if self.send_state == State.ACK_0: if (not util.is_corrupt(msg)) and util.is_ack(msg, 0): # Make sure the timer is stopped upon transition to waiting for # messages from above. self.timer.stop() if config.DEBUG: print("Received ACK 0") self.send_state = State.SEQ_1 else: if config.DEBUG: print( "Corrupt or out-of-order packet received in state ACK0" ) elif self.send_state == State.ACK_1: if (not util.is_corrupt(msg)) and util.is_ack(msg, 1): self.timer.stop() if config.DEBUG: print("Received ACK 1") self.send_state = State.SEQ_0 else: if config.DEBUG: print( "Corrupt or out-of-order packet received in state ACK1" ) elif self.recv_state == State.SEQ_0: if (not util.is_corrupt(msg)) and util.has_seq( msg, self.recv_state.value): if config.DEBUG: print("Received DATA 0") payload = util.extract(msg) self.msg_handler(payload) self.segment = util.make_segment(config.MSG_TYPE_ACK, self.recv_state.value, b'') self.oncethru = 1 self.recv_state = State.SEQ_1 else: if config.DEBUG: print( "Corrupt or out-of-order packet received in state SEQ0" ) if self.oncethru == 1: self.network_layer.send(self.segment) elif self.recv_state == State.SEQ_1: if (not util.is_corrupt(msg)) and util.has_seq( msg, self.recv_state.value): if config.DEBUG: print("Received DATA 1") payload = util.extract(msg) self.msg_handler(payload) self.segment = util.make_segment(config.MSG_TYPE_ACK, self.recv_state.value, b'') self.recv_state = State.SEQ_0 else: if config.DEBUG: print( "Corrupt or out-of-order packet received in state SEQ1" ) self.network_layer.send(self.segment)
def getStudios(url, hdr): content=util.getURL(url, hdr) if content!=False: studios=util.extractAll(content, '<a href="http://ivhunter.com/studios', 'a>') for studio in studios: if util.extract(studio, '">', '</')!="Studios": util.addDir(util.extract(studio, '">', '</'), "http://ivhunter.com/studios/"+util.extract(studio, '/', '/'), 1, "") xbmcplugin.endOfDirectory(int(sysarg))
def buildSubMenu(params): content=util.getURL('http://www.asianteensfor.me/javlist/blank/', hdr) if content!=False: xoxo=util.extract(content, '<ul id="'+params['url']+'">', '</ul>') subOptions=util.extractAll(xoxo, '<li class="cat-item', '</li>') for sub in subOptions: name=util.extract(sub, '/" >', '</a>') url=util.extract(sub, '<a href="', '" >') util.addDir(name, url, 5, "","") xbmcplugin.endOfDirectory(int(sysarg))
def getCategories(params) : param={'categories':1} content=util.getURL(params['url'], hdr) if content!=False: contents=util.extract(content, '<ul class="small-block-grid-4 videos-cats">', '</ul>') films=util.extractAll(contents, '<li>', '</li>') for film in films: title=util.extract(film, '<div class="media-panel-title category-title">', '</div>') param['title']=util.extract(title, '">', '</a>') param['plot']=util.extract(film, '<div class="media-panel-info">', '</div>') param['url']=util.extract(title, '<a href="', '"') param['poster']=util.extract(film, '<img src="', '" />') param['fanart']=param['poster'] if param['url']!=None: u=sys.argv[0]+"?url="+param['url']+"&mode=2&name="+urllib.quote_plus(param['title'])+"&poster="+param['poster'] liz=xbmcgui.ListItem(param['title'], iconImage="DefaultVideo.png", thumbnailImage=param['poster']) liz.setInfo( type="Video", infoLabels={ "Title": param['title'],"Plot": param['plot']} ) liz.setProperty("Fanart_Image", param['fanart']) liz.setProperty("Landscape_Image", param['fanart']) liz.setProperty("Poster_Image", param['poster']) ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True) next=util.extract(content, '<div class="pagination">', '</div>') if next!=None: next=util.extract(next, '<li class="active">', '</a>') if next!=None: url=util.extract(next, '<a href="', '"') util.addDir("Next >", url, 2, "","") xbmcplugin.endOfDirectory(int(sysarg))
def getIdols(url, hdr): content=util.getURL(url, hdr) if content!=False: alphabet=util.extractAll(content, '<ul class="links">', '</ul>') for letter in alphabet: idols=util.extractAll(letter, '<li>', '</li>') for idol in idols: if util.makeAscii(util.extract(idol, 'title="', '"'))!="": util.addDir(util.makeAscii(util.extract(idol, 'title="', '"')), util.extract(idol, 'href="', '"').encode('utf-8'), 1, "") xbmcplugin.endOfDirectory(int(sysarg))
def getStars(params): content=util.getURL(params['url'], hdr) if content!=False: alphabet=util.extractAll(content, "<ul class='small-block-grid-5 stars'>", '</ul>') for letter in alphabet: stars=util.extractAll(letter, '<li>', '</li>') for star in stars: name=util.extract(star, '">', '</a>') url=util.extract(star, 'href="', '"') util.addDir(name, url, 2, "","") xbmcplugin.endOfDirectory(int(sysarg))
def getStars(params): content = util.getURL(params['url'], hdr) if content != False: alphabet = util.extractAll(content, "<ul class='small-block-grid-5 stars'>", '</ul>') for letter in alphabet: stars = util.extractAll(letter, '<li>', '</li>') for star in stars: name = util.extract(star, '">', '</a>') url = util.extract(star, 'href="', '"') util.addDir(name, url, 2, "", "") xbmcplugin.endOfDirectory(int(sysarg))
def buildMenu(): url = WEB_PAGE_BASE response = urllib2.urlopen(url) if response and response.getcode() == 200: content = response.read() makeLinks = util.extract(content, '"nav navbar-nav menu"', '</ul>') links = util.extractAll(makeLinks,'a href="','</a>') for link in links: params = {'makeCategories':1} params['link'] = util.extract(link,'href="','\"') #params['title'] = util.extract(link,'/1">','</a>') print makeLinks
def getVids(url) : param={'play':1} content=util.getURL(url, hdr) if content!=False: films=util.extractAll(content, '<vid>', '</vid>') movielist = "[" currentrow = 0 itemlist = list() for film in films: param['title']=replaceHTMLCodes(util.extract(film, '<name>', '</name>')) param['plot']=makeAscii(replaceHTMLCodes(util.extract(film, '<plot>', '</plot>'))) param['starring']=makeAscii(replaceHTMLCodes(util.extract(film, '<starring>', '</starring>'))) param['studio']=makeAscii(replaceHTMLCodes(util.extract(film, '<studio>', '</studio>'))) param['date']=util.extract(film, '<date>', '</date>') param['url']=util.extract(film, '<url>', '</url>') param['poster']=util.extract(film, 'class="cover" src="', '" />') param['fanart']=util.extract(film, 'class="preview" src="', '" />') u=sys.argv[0]+"?url="+param['url']+"&play="+str(4)+"&name="+param['title']+"&poster="+param['poster'] liz=xbmcgui.ListItem(param['title'], iconImage="DefaultVideo.png", thumbnailImage=param['poster']) liz.setInfo( type="Video", infoLabels={ "Title": param['title'],"Plot": param['plot']} ) liz.setProperty("Fanart_Image", param['fanart']) liz.setProperty("Landscape_Image", param['fanart']) liz.setProperty("Poster_Image", param['poster']) #moo movielist += json.dumps({ 'title': param["title"], 'url': param["url"] }) + "," linkMenu = [] #reset item context menu for a reason linkMenu.append(('Download', 'RunPlugin(plugin://%s/?action=download&videoname=%s&videourl=%s)' % (ADDON_ID,param['title'],param['url']))) #liz.addContextMenuItems(linkMenu,replaceItems=True) entry = (u,liz,True,linkMenu); itemlist.append(entry) movielist = movielist[:-1] + "]" if len(itemlist) > 0: #movielist = urllib.unquote_plus(str(movielist)) settings.setSetting(id="movielist", value=movielist) for item in itemlist: linkMenu = item[3] linkMenu.append(('Download All', 'RunPlugin(plugin://%s/?action=downloadall)' % (ADDON_ID))) item[1].addContextMenuItems(linkMenu,replaceItems=True) del itemlist[-1] ok=xbmcplugin.addDirectoryItems(handle=int(sys.argv[1]),items=itemlist) if "Older posts" in content: next=util.extract(content, '<div id="next">', '</div>') url=util.extract(next, '"', '"') util.addDir("Next >", url, 5, "","") xbmcplugin.endOfDirectory(int(sysarg))
def showVideos(url, hdr): content=util.getURL(url, hdr) toReturn=[] if content!=False: gs = goslate.Goslate() allfilms=util.extract(content, '<div class="nag cf">', '<!-- end .loop-content -->') if allfilms!=None: films=util.extractAll(allfilms, '<div id="post-', '<!-- end #post-') for film in films: details=util.extract(film, '<div class="thumb">', '</div>') title=util.replaceHTMLCodes(util.extract(details, 'title="', ' href')) if '[' in title and ']' in title: videoCode=util.extract(title.encode("utf-8"), "[", "]") videoTitle=gs.translate(util.extract(title.encode('utf-8'), "]", '"'), 'en').title() title=util.makeAscii("["+videoCode+"] ")+videoTitle.encode('utf-8') plot="no plot" starring="no starring" studio="no studio" date="no date" url=util.extract(film, 'href="', '"') poster=util.extract(film, '<img src="', '" alt').replace("pl.jpg", "ps.jpg") fanart=poster.replace("ps.jpg", "pl.jpg") toReturn.append([title, plot, starring, studio, date, url, poster, fanart]) checkNext=util.extract(content, '<a class="nextpostslink" rel="next" href="', '"') if checkNext!=None: toReturn.append(['next', checkNext]) return toReturn
def buildSubMenu(params): response = urllib2.urlopen(params['video']) if response and response.getcode() == 200: content = response.read() videos = util.extractAll(content, '<td width="40%" align="center">', '/td>') for video in videos: params = {'play':1} params['video'] = WEB_PAGE_BASE + util.extract(video, 'a href="', '\"') params['image'] = WEB_PAGE_BASE + util.extract(video, 'img src="', '\"') params['title'] = util.extract(video, '<p align="center">', '</p>') link = util.makeLink(params) util.addMenuItem(params['title'], link, 'DefaultVideo.png', params['image'], False) util.endListing() else: util.showError(ADDON_ID, 'Could not open URL %s to create menu' % (url))
def buildMainMenu(): util.addDir("Recently Added","Recently Added", 2, "","") # get the rest of the menu items from the website, should be easier to update content=util.getURL('http://www.asianteensfor.me/javlist/blank/', hdr) if content!=False: xoxo=util.extract(content, '<ul class="xoxo">','</body>') headings=util.extractAll(xoxo, '<li id="lc_taxonomy-', '</ul></div></li>') for heading in headings: name=util.extract(heading, '<h3 class="widget-title">', '</h3>') url="lct-widget-"+name.lower() util.addDir(name, url, 3, "","") util.addDir("Search","Search", 4, "","") xbmcplugin.endOfDirectory(int(sysarg))
def buildMenu(): url = WEB_PAGE_BASE + '/livetv' response = urllib2.urlopen(url) if response and response.getcode() == 200: content = response.read() video = util.extract(content, '<a class="channel_link"', '</a>') params = {'play':1} params['video'] = WEB_PAGE_BASE + util.extract(video,'href="','\"') params['image'] = util.extract(video,'img src="','\"') params['title'] = util.extract(video,'channel="','\"') link = util.makeLink(params) util.addMenuItem(params['title'], link, 'DefaultVideo.png', params['image'], False) else: util.showError(ADDON_ID, 'Could not open URL %s to create menu' %(url))
def playVideo(params): url = 'http://embed.redtube.com/video/info/?id=' + params['video'] response = urllib2.urlopen(url) if response and response.getcode() == 200: content = response.read() videoLink = util.extract(content, '<url src=\'', '\'>') util.playMedia(params['title'], params['image'], videoLink, 'Video')
def extract_yast_packages(data): """ Extract package metadata from yast metadata file """ extracted = extract(data, 'gz') pkgs = re.findall(b'=Pkg: (.*)', extracted) plen = len(pkgs) packages = set() if plen > 0: ptext = 'Extracting packages: ' progress_info_s.send(sender=None, ptext=ptext, plen=plen) for i, pkg in enumerate(pkgs): progress_update_s.send(sender=None, index=i + 1) name, version, release, arch = str(pkg).split() package = PackageString(name=name.lower(), epoch='', version=version, release=release, arch=arch, packagetype='R') packages.add(package) else: info_message.send(sender=None, text='No packages found in repo') return packages
def playVideo(params): content = util.getURL(params['url'], hdr) if content != False: vidID = util.extract(content, 'file: "http://videos.woodrocket.com/vid/', '.mp4", label: "480p"') source = util.extract(content, 'sources: [', '],') if 'label: "720p HD"' in source: util.playMedia( params['name'], params['poster'], "http://videos.woodrocket.com/vid/" + vidID + ".hd.mp4", "Video") else: util.playMedia( params['name'], params['poster'], "http://videos.woodrocket.com/vid/" + vidID + ".mp4", "Video")
def collect_Pages(self, response): # Here, we collect all available pages from the index. If the 'page number' is equal to '...', # we resend the same request back to this page. This will load the same page again, but a new series of pages # ie the first series of pages are 1-40, the second is 41-80, etc. If the request is in one of these 'series' # then, we collect pass the request to the index_page function. requests = [] counter = 1 pages = response.xpath('//*[@id="datagrid_results"]/tr[42]/td/font/a') for page in pages: href = extract(page.xpath('@href')) index = ( href.lstrip("javascript:__doPostBack(").rstrip("', '')"))[1:] formData = {'__EVENTTARGET': index} # Here, if the link asks us to get a new set of pages, we call this function again. Otherwise, we send the request to the index_Page function. # The logic is controlled by the 'counter'. if counter == len(pages): request = scrapy.http.FormRequest.from_response( response, formdata=formData, callback=self.collect_Pages) counter = 1 else: request = scrapy.http.FormRequest.from_response( response, formdata=formData, callback=self.index_Page) counter += 1 requests.append(request) for request in requests: yield request
def make_crowd_data(corpus, data, list_wid, dic_wid, dic_pid_data, features, labels): """ make util.crowd_data """ #make sentences and crowdlabs inv_labels = {v: k for (k, v) in labels.items()} sentences = [] clabs = [] for pid in corpus.docs: inp = make_input({pid: corpus.docs[pid]}) sens = util.extract(inp, features, labels) if pid not in dic_pid_data: # TODO(yinfeiy): find out why it is missing here print pid, continue sentences.extend(sens) for sen in sens: # a sentence sen_clab = [] for i in dic_pid_data[pid]: # a crowd annotation d = data[i] # d = (wid, pid, spans) wlabs = [0] * len(sen) for j in range(len(sen)): # a word if is_inside(inv_labels, sen[j].label, d[2]): wlabs[j] = 1 sen_clab.append(util.crowdlab(dic_wid[d[0]], int(d[1]), wlabs)) clabs.append(sen_clab) return util.crowd_data(sentences, clabs)
def index_Page(self, response): # Index page collects all the links to the veterinarian page. After collecting the links, make a request. rows = response.xpath('//*[@id="datagrid_results"]/tr') requests = [] for row in rows: status = extract(row.xpath('td[5]/span/text()')) if status == 'Active': href = extract(row.xpath('td[1]/table/tr/td/a/@href')) url = 'http://verify.sos.ga.gov/verification/' + href request = scrapy.http.Request(url, callback=self.parse_Profile) requests.append(request) for request in requests: yield request
def playVideo(params): response = urllib2.urlopen(params['video']) if response and response.getcode() == 200: content = response.read() videoLink = util.extract(content, 'flashvars.File = "', '"') util.playMedia(params['title'], params['image'], videoLink, 'Video') else: util.showError(ADDON_ID, 'Could not open URL %s to get video information' % (params['video']))
def showVideos(url, hdr): content=util.getURL(url, hdr) toReturn=[] if content!=False: gs = goslate.Goslate() allfilms=util.extract(content, '<div class="items">', '<div class="lateral">') films=util.extractAll(allfilms, '<div class="item">', '<div class="item">') for film in films: title=util.replaceHTMLCodes(util.extract(film, '<h2>', 'h2>')) if '[' in title and ']' in title: videoCode=util.extract(title.encode("utf-8"), "[", "]") videoTitle=gs.translate(util.extract(title.encode('utf-8'), "]", '</'), 'en').title() title=util.makeAscii("["+videoCode+"] ")+videoTitle.encode('utf-8') else: title=gs.translate(title.encode('utf-8').replace("</", ""), 'en').title() plot="no plot" starring="no starring" studio="no studio" date="no date" url=util.extract(film, '<a href="', '"') poster=util.extract(film, '<img src="', '" alt') fanart=poster.replace("ps.jpg", "pl.jpg") toReturn.append([title, plot, starring, studio, date, url, poster, fanart]) if '<link rel="next" href="' in content: toReturn.append(["next", util.extract(content, '<link rel="next" href="', '"')]) return toReturn
def buildMenu(): url = WEB_PAGE_BASE response = urllib2.urlopen(url) if response and response.getcode() == 200: content = response.read() videos = util.extractAll(content, '<video duration', '</video>') for video in videos: params = {'play': 1} params['video'] = util.extract(video, 'video_id="', '"') params['image'] = util.extract(video, 'default_thumb="', '"') params['title'] = util.extract(video, '<title><![CDATA[', ']]') link = util.makeLink(params) util.addMenuItem(params['title'], link, 'DefaultVideo.png', params['image'], False) util.endListing() else: util.showError(ADDON_ID, 'Could not open URL %s to create menu' % (url))
def playVideo(params): response = urllib2.urlopen(params['video']) if response and response.getcode() == 200: content = response.read() videoLink = util.extract(content, 'src=\'" + "', '\"') print videoLink else: util.showError(ADDON_ID, 'Could not open URL %s to get video information' % (params['video']))
def playVideo(params): link = WEB_PAGE_BASE + params['link'] response = urllib2.urlopen(link) if response and response.getcode() == 200: content = response.read() videoLink = util.extract(content, "source src='", "'") util.playMedia(params['title'], params['image'], videoLink, 'Video') else: util.showError(ADDON_ID, 'Could not open URL %s to get video information' % (params['video']))
def playVideo(params): response = urllib2.urlopen(params['video']) if response and response.getcode() == 200: content = response.read() videoLink = util.extract(content, 'src=\'" + "', '\"') link=videoLink.replace('1000','2500') util.playMedia(params['title'], params['image'], link, 'Video') else: util.showError(ADDON_ID, 'Could not open URL %s to get video information' % (params['video']))
def getCategories(url): param={'category':1} content=util.getURL(url, hdr) if content!=False: cats=util.extractAll(content, '<div class="item">', '<div class="item">') for film in cats: param['title']=makeAscii(util.extract(film, 'title="', '"')) param['url']='http://www.likuoo.com'+util.extract(film, '<a href="', '" title="') param['poster']=util.extract(film, 'src="', '" title="') param['fanart']=param['poster'] xbmc.log("Play URL:"+param['url'], xbmc.LOGERROR) if param['url']!=None: u=sys.argv[0]+"?url="+param['url']+"&mode=2&name="+urllib.quote_plus(param['title'])+"&poster="+param['poster'] liz=xbmcgui.ListItem(param['title'], iconImage="DefaultVideo.png", thumbnailImage=param['poster']) liz.setInfo( type="Video", infoLabels={ "Title": param['title'],"Plot": ""} ) liz.setProperty("Poster_Image", param['poster']) ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True) xbmcplugin.endOfDirectory(int(sysarg))
def buildPlay(inputParams): url = WEB_PAGE_BASE + inputParams['link'] response = urllib2.urlopen(url) if response and response.getcode() == 200: content = response.read() links = util.extractAll(content, '<div class="col">', '</span>') for link in links: params = {'makePlay':1} params['title'] = util.extract(link,'data-original-title="','\"') params['link'] = util.extract(link,'href="','\"') params['image'] = util.extract(link,'img src="','"') link = util.makeLink(params) util.addMenuItem(params['title'], link, params['image'], params['image'], True) util.endListing() xbmc.executebuiltin("Container.SetViewMode(506)") else: util.showError(ADDON_ID, 'Could not open URL SHOW %s to create menu' %(url))
def buildMenu(): url = 'http://play.fpt.vn/' response = urllib2.urlopen(url) if response and response.getcode() == 200: content = response.read() makeLinks = util.extract(content, '"nav navbar-nav menu"', '</ul>') links = util.extractAll(makeLinks,'<li >','a>') for link in links: params = {'key':'makeMenu'} params['link'] = util.extract(link,'href="','\"') params['title'] = util.extract(link,'\">','</') link = util.makeLink(params) util.addMenuItem(params['title'], link, 'DefaultVideo.png', 'DefaultVideo.png', True) util.endListing() xbmc.executebuiltin("Container.SetViewMode(500)") else: util.showError(ADDON_ID, 'Could not open URL CATEGORIES %s to create menu' %(url))
def buildCategories(): url = WEB_PAGE_BASE + '/the-loai/music' response = urllib2.urlopen(url) if response and response.getcode() == 200: content = response.read() links = util.extractAll(content, 'idscroll="', '<ul class="thumn">') for link in links: params = {'makeCategories':1} params['link'] = util.extract(link,'href="','\"') params['title'] = util.extract(link,'/1">','</a>') link = util.makeLink(params) util.addMenuItem(params['title'], link, 'DefaultVideo.png', 'DefaultVideo.png', True) util.endListing() xbmc.executebuiltin("Container.SetViewMode(506)") else: util.showError(ADDON_ID, 'Could not open URL CATEGORIES %s to create menu' %(url))
def getCategories(params): param = {'categories': 1} content = util.getURL(params['url'], hdr) if content != False: contents = util.extract(content, '<ul class="small-block-grid-4 videos-cats">', '</ul>') films = util.extractAll(contents, '<li>', '</li>') for film in films: title = util.extract( film, '<div class="media-panel-title category-title">', '</div>') param['title'] = util.extract(title, '">', '</a>') param['plot'] = util.extract(film, '<div class="media-panel-info">', '</div>') param['url'] = util.extract(title, '<a href="', '"') param['poster'] = util.extract(film, '<img src="', '" />') param['fanart'] = param['poster'] if param['url'] != None: u = sys.argv[0] + "?url=" + param[ 'url'] + "&mode=2&name=" + urllib.quote_plus( param['title']) + "&poster=" + param['poster'] liz = xbmcgui.ListItem(param['title'], iconImage="DefaultVideo.png", thumbnailImage=param['poster']) liz.setInfo(type="Video", infoLabels={ "Title": param['title'], "Plot": param['plot'] }) liz.setProperty("Fanart_Image", param['fanart']) liz.setProperty("Landscape_Image", param['fanart']) liz.setProperty("Poster_Image", param['poster']) ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=True) next = util.extract(content, '<div class="pagination">', '</div>') if next != None: next = util.extract(next, '<li class="active">', '</a>') if next != None: url = util.extract(next, '<a href="', '"') util.addDir("Next >", url, 2, "", "") xbmcplugin.endOfDirectory(int(sysarg))
def playVideo(params): response = urllib2.urlopen(params['video']) if response and response.getcode() == 200: content = response.read() videoLink = util.extract(content, 'src=\'" + "', '\"') link = videoLink.replace('1000', '2500') util.playMedia(params['title'], params['image'], link, 'Video') else: util.showError( ADDON_ID, 'Could not open URL %s to get video information' % (params['video']))
def buildMenu(): url = WEB_PAGE_BASE + '/livetv' response = urllib2.urlopen(url) if response and response.getcode() == 200: content = response.read() videos = util.extractAll(content, '<a class="channel_link"', '</a>') for video in videos: params = {'play': 1} params['video'] = WEB_PAGE_BASE + util.extract( video, 'href="', '\"') params['image'] = util.extract(video, 'img src="', '\"') params['title'] = util.extract(video, 'channel="', '\"') link = util.makeLink(params) util.addMenuItem(params['title'], link, 'DefaultVideo.png', params['image'], False) xbmc.executebuiltin("Container.SetViewMode(52)") util.endListing() else: util.showError(ADDON_ID, 'Could not open URL %s to create menu' % (url))
def buildMenu(): url = WEB_PAGE_BASE + 'tv_rec.php' response = urllib2.urlopen(url) if response and response.getcode() == 200: content = response.read() videos = util.extractAll(content, '<td class="td_ser">', '</td>') for video in videos: params = {'play': 1} params['video'] = WEB_PAGE_BASE + util.extract( video, '<a href="', '"') params['image'] = "" params['title'] = util.extract( video, 'title="', '"').decode('windows-1251').encode('utf-8') link = util.makeLink(params) util.addMenuItem(params['title'], link, 'DefaultVideo.png', params['image'], False) util.endListing() else: util.showError(ADDON_ID, 'Could not open URL %s to create menu' % (url))
def searchp(params): url = (params['url']) videoPage = requests.get(url) if videoPage and videoPage.status_code == 200: cont = videoPage.text vidlinks = util.extractAll(cont, '<div id="tab', '/div>') for vidlink in vidlinks: t = util.extract(vidlink, '://', '/') v = util.extract(vidlink, 'SRC="', '"') or util.extract( vidlink, 'src="', '"') paramz = {'play': 1} paramz['title'] = t paramz['videolink'] = v paramz['image'] = icon link = util.makeLink(paramz) util.addMenuItem(paramz['title'], link, paramz['image'], None, False) util.endListing() else: util.showError(ADDON_ID, 'Could not open URL %s to create menu' % (url))
def getPopular(url, hdr): param={'play':1} toReturn=[] content=util.getURL(url, hdr) if content!=False: gs = goslate.Goslate() popularFilms=util.extract(content, '<div id="slider1"', '<div class="peliculas">') films=util.extractAll(popularFilms, '<a href', '</a>') for film in films: title=util.extract(film, 'alt="', 'width=') if '[' in title and ']' in title: videoCode=util.extract(title.encode("utf-8"), "[", "]") videoTitle=gs.translate(util.extract(title.encode('utf-8'), "]", '"'), 'en').title() title=util.makeAscii("["+videoCode+"] ")+videoTitle.encode('utf-8') else: title=gs.translate(title.encode('utf-8').replace("width=", ""), 'en').title() plot="no plot" starring="no starring" studio="no studio" date="no date" url=util.extract(film, '="', '"') poster=util.extract(film, '<img src="', '" alt') fanart=poster.replace("ps.jpg", "pl.jpg") toReturn.append([title, plot, starring, studio, date, url, poster, fanart]) return toReturn
def getPopular(url, hdr): toReturn=[] content=util.getURL(url, hdr) if content!=False: gs = goslate.Goslate() popularFilms=util.extract(content, '<div id="dp-widget-posts-2" class="widget widget-posts">', '<!--end #sidebar-->') films=util.extractAll(popularFilms, '<div class="thumb">', '</div>') for film in films: title=util.extract(film, 'title="', 'href') if '[' in title and ']' in title: videoCode=util.extract(title.encode("utf-8"), "[", "]") videoTitle=gs.translate(util.extract(title.encode('utf-8'), "]", '"'), 'en').title() title=util.makeAscii("["+videoCode+"] ")+videoTitle.encode('utf-8') else: title=gs.translate(title.encode('utf-8').replace('"', ""), 'en').title() plot="no plot" starring="no starring" studio="no studio" date="no date" url=util.extract(film, 'href="', '"') poster=util.extract(film, '<img src="', '" alt') fanart=poster.replace("ps.jpg", "pl.jpg") toReturn.append([title, plot, starring, studio, date, url, poster, fanart]) return toReturn
def handle_arrival_msg(self): msg = self.network_layer.recv() # TODO: impl protocol to handle arrived packet from network layer. # call self.msg_handler() to deliver to application layer. if msg and util.is_sender(msg): if self.sender_type == config.MSG_TYPE_ACK and not util.is_corrupt( msg) and self.sender_seq == 0 and util.valid_seq(msg, 0): self.stop_time() self.sender_seq = 1 self.sender_type = config.MSG_TYPE_DATA elif self.sender_type == config.MSG_TYPE_ACK and not util.is_corrupt( msg) and self.sender_seq == 1 and util.valid_seq(msg, 1): self.stop_time() self.sender_type = config.MSG_TYPE_DATA self.sender_seq = 0 elif msg and not util.is_sender(msg): if self.expect_seq == 0: if not util.is_corrupt(msg) and util.valid_seq( msg, self.expect_seq): data = util.extract(msg) self.msg_handler(data) self.receiver_pack = util.make_pack_with_header( config.MSG_TYPE_ACK, 0) self.network_layer.send(self.receiver_pack) self.expect_seq = 1 elif util.is_corrupt(msg) or not util.valid_seq( msg, self.expect_seq): self.network_layer.send(self.receiver_pack) elif self.expect_seq == 1: if not util.is_corrupt(msg) and util.valid_seq( msg, self.expect_seq): data = util.extract(msg) self.receiver_pack = util.make_pack_with_header( config.MSG_TYPE_ACK, 1) self.msg_handler(data) self.network_layer.send(self.receiver_pack) self.expect_seq = 0 elif util.is_corrupt(msg) or not util.valid_seq( msg, self.expect_seq): self.network_layer.send(self.receiver_pack)
def getVids(params): param = {'play': 1} content = util.getURL(params['url'], hdr) if content != False: films = util.extractAll(content, '<div class="item">', '<div class="item">') for film in films: param['title'] = makeAscii(util.extract(film, 'title="', '"')) param['url'] = util.extract(film, '<a href="', '" title="') param['poster'] = util.extract(film, 'src="', '" title="') param['fanart'] = param['poster'] if param['url'] != None: u = sys.argv[0] + "?url=" + param['url'] + "&play=" + str( 4) + "&name=" + urllib.quote_plus( param['title']) + "&poster=" + param['poster'] liz = xbmcgui.ListItem(param['title'], iconImage="DefaultVideo.png", thumbnailImage=param['poster']) liz.setInfo(type="Video", infoLabels={ "Title": param['title'], "Plot": "" }) liz.setProperty("Poster_Image", param['poster']) ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=True) next = util.extract(content, '<span class="current">', '</span>') #xbmc.log(">>>>>"+str(next), xbmc.LOGERROR) if next != None: next = int(next) + 1 #xbmc.log('http://www.likuoo.com/new/'+str(next), xbmc.LOGERROR) if 'http://www.likuoo.com/new/' + str(next) in content: util.addDir("Next >", 'http://www.likuoo.com/new/' + str(next), 2, "", "") xbmcplugin.endOfDirectory(int(sysarg))
def liwc_feature(lex, cats_to_feature, docs): row = [] col = [] data = [] for i, doc in enumerate(docs): countings = extract(lex, doc, percentage=True) for item in countings: row.append(i) col.append(cats_to_feature[item]) data.append(countings[item]) if i % 5000 == 0: print(i) result = csr_matrix((data, (row, col))) return result
def install(): if not toolchain.get('tarball', False): print "Please setup your selected toolchain" sys.exit(1) if not have_tarball(): if not toolchain.get('url', False): print 'Please place "%s" in "%s"' % (toolchain['tarball'], downloads_dir) sys.exit(1) download("%s/%s" % (toolchain['url'], toolchain['tarball'])) tarball_path = os.path.join(downloads_dir, toolchain['tarball']) if toolchain.get('md5', None): check_md5(tarball_path, toolchain['md5']) if toolchain.get('sha1', None): check_sha1(tarball_path, toolchain['sha1']) extract(tarball_path, build_tools_dir) if not installed(): raise Exception('Toolchain installation failed')
def main(filename, udeb=False, debug=False): """ Information about a particular ISO. """ log_level = logging.DEBUG if debug else logging.INFO logging.getLogger('requests').setLevel(logging.WARNING) logging.basicConfig(stream=sys.stdout, format='%(message)s', level=log_level) folder = extract(filename) extension = 'udeb' if udeb else 'deb' manifest('%s/**/*.%s' % (os.path.join(folder, 'pool'), extension)) cleanup(folder)
def extract_arch_packages(data): """ Extract package metadata from an arch linux tarfile """ from packages.utils import find_evr extracted = BytesIO(extract(data, 'gz')) tf = tarfile.open(fileobj=extracted, mode='r:*') packages = set() plen = len(tf.getnames()) if plen > 0: ptext = 'Extracting packages: ' progress_info_s.send(sender=None, ptext=ptext, plen=plen) for i, tarinfo in enumerate(tf): progress_update_s.send(sender=None, index=i + 1) if tarinfo.isfile(): name_sec = ver_sec = arch_sec = False t = tf.extractfile(tarinfo).read() for line in t.decode('utf-8').splitlines(): if line.startswith('%NAME%'): name_sec = True continue if name_sec: name_sec = False name = line continue if line.startswith('%VERSION%'): ver_sec = True continue if ver_sec: ver_sec = False epoch, version, release = find_evr(line) continue if line.startswith('%ARCH%'): arch_sec = True continue if arch_sec: arch_sec = False arch = line continue package = PackageString(name=name.lower(), epoch=epoch, version=version, release=release, arch=arch, packagetype='A') packages.add(package) else: info_message.send(sender=None, text='No packages found in repo') return packages
def eval_hc_test(hc, features, labels, print_err=False, decoder='hc'): """ evaluate in the train set :param hc: :param labels: :return: """ tp = 0 fp = 0 fn = 0 dirname = "testa" input = [] for file in os.listdir(dirname): # print file if file.endswith(".txt"): f = open(os.path.join(dirname, file)) l = list(f) input.extend(l) f.close() # return input sentences = util.extract(input, features, labels, keep_word = True) # return sentences for sen in sentences: if True: # if not has_oov(sen): #predicted = hc.decode(util.get_obs(sen)) predicted = get_tag(hc, sen, features, decoder) (x, y, z) = eval_ner(util.get_lab(sen), predicted, labels) tp += x fp += y fn += z if print_err: if y + z > 0: print "sen: ", util.get_words(sen, features) + " OOV = " + str(has_oov(sen)) print "true labels: ", util.get_lab_name(util.get_lab(sen), labels) print "predicted: ", util.get_lab_name(predicted, labels) try: pre = tp * 1.0 / (tp + fp) rec = tp * 1.0 / (tp + fn) f = 2.0 * pre * rec / (pre + rec) print pre, rec, f except ZeroDivisionError: print "DIV BY 0 ", tp, fp, fn
def get_metalink_urls(url): """ Parses a metalink and returns a list of mirrors """ res = get_url(url) if response_is_valid(res): if 'content-type' in res.headers and \ res.headers['content-type'] == 'application/metalink+xml': data = download_url(res, 'Downloading repo info:') ns = 'http://www.metalinker.org/' try: context = etree.parse(BytesIO(data), etree.XMLParser()) except etree.XMLSyntaxError: context = etree.parse(BytesIO(extract(data, 'gz')), etree.XMLParser()) xpath = "//ns:files/ns:file[@name='repomd.xml']/ns:resources/ns:url[@protocol='https']" # noqa metalink_urls = context.xpath(xpath, namespaces={'ns': ns}) return [x.text for x in metalink_urls]
def extract_yum_packages(data, url): """ Extract package metadata from a yum primary.xml file """ extracted = extract(data, url) ns = 'http://linux.duke.edu/metadata/common' m_context = etree.iterparse(BytesIO(extracted), tag='{{{0!s}}}metadata'.format(ns)) plen = int(next(m_context)[1].get('packages')) p_context = etree.iterparse(BytesIO(extracted), tag='{{{0!s}}}package'.format(ns)) packages = set() if plen > 0: ptext = 'Extracting packages: ' progress_info_s.send(sender=None, ptext=ptext, plen=plen) for i, p_data in enumerate(p_context): elem = p_data[1] progress_update_s.send(sender=None, index=i + 1) name = elem.xpath('//ns:name', namespaces={'ns': ns})[0].text.lower() arch = elem.xpath('//ns:arch', namespaces={'ns': ns})[0].text fullversion = elem.xpath('//ns:version', namespaces={'ns': ns})[0] epoch = fullversion.get('epoch') version = fullversion.get('ver') release = fullversion.get('rel') elem.clear() while elem.getprevious() is not None: del elem.getparent()[0] if name != '' and version != '' and arch != '': if epoch == '0': epoch = '' package = PackageString(name=name, epoch=epoch, version=version, release=release, arch=arch, packagetype='R') packages.add(package) else: info_message.send(sender=None, text='No packages found in repo') return packages
def handle_arrival_msg(self): msg = self.network_layer.recv() # TODO: impl protocol to handle arrived packet from network layer. # call self.msg_handler() to deliver to application layer. if msg and util.is_sender(msg): if(not util.is_corrupt(msg)): self.base = util.get_seq(msg) + 1 if self.base == self.next_seq: self.stop_time() else: self.start_timer() elif msg and not util.is_sender(msg): if not util.is_corrupt(msg) and util.valid_seq(msg, self.expect_seq): data = util.extract(msg) self.msg_handler(data) self.sendpkt = util.make_pack_with_header(config.MSG_TYPE_ACK, self.expect_seq) self.expect_seq += 1 self.network_layer.send(self.sendpkt)
def buildPlay(inputParams): url = WEB_PAGE_BASE + inputParams['link'] response = urllib2.urlopen(url) if response and response.getcode() == 200: content = response.read() links = util.extract(content, 'a href="#">«', 'href="#">»') extractLinks = util.extractAll(links,'a href="','"') for link in extractLinks: params = {'key':'makePlaymakePlay'} params['title'] = util.extractTitle(link) params['link'] = link params['image'] = inputParams['image'] link = util.makeLink(params) util.addMenuItem(params['title'], link, params['image'], params['image'], False) util.endListing() xbmc.executebuiltin("Container.SetViewMode(500)") else: util.showError(ADDON_ID, 'Could not open URL PLAY %s to create menu' %(url))
def onPlayBackStarted(self): __setting__ = xbmcaddon.Addon('script.tv.promos').getSetting("StreamUrl") varYoutubeSI = xbmcaddon.Addon('script.tv.promos').getSetting("YoutubeVideo") if __setting__ == 'Youtube': #START YOUTUBE CODE if xbmc.getInfoLabel("VideoPlayer.TVShowTitle") == '': self.varHasPlayed = "Yes" else: self.varHasPlayed = "No" EpisodeTmp = xbmc.getInfoLabel("VideoPlayer.Episode") EpisodeNumber = int(EpisodeTmp) + int(1) varSearchString = xbmc.getInfoLabel("VideoPlayer.TVShowTitle") + " " + xbmc.getInfoLabel("VideoPlayer.Season") + "x" + str(EpisodeNumber) + " promo" # Set Headers headers = { 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3', } # Get the feed r = requests.get("http://gdata.youtube.com/feeds/api/videos?q=" + varSearchString + "&start-index=" + varYoutubeSI + "&max-results=1&v=2&alt=jsonc", headers=headers) r.text # Convert it to a Python dictionary data = json.loads(r.text) # Loop through the result. for item in data['data']['items']: self.varVideoID = item['id'] xbmc.sleep(1000) #END YOUTUBE CODE if __setting__ == 'Tv Rage': if xbmc.getInfoLabel("VideoPlayer.TVShowTitle") == '': self.varHasPlayed = "Yes" else: self.varHasPlayed = "No" self.varShowName = xbmc.getInfoLabel("VideoPlayer.TVShowTitle") varEpisodeTmp = xbmc.getInfoLabel("VideoPlayer.Episode") varEpisodeNumber = int(varEpisodeTmp) + int(1) varEpisode = xbmc.getInfoLabel("VideoPlayer.Season") + "x" + str(varEpisodeNumber) varShowInfo = requests.get("http://services.tvrage.com/tools/quickinfo.php?show=" + self.varShowName + "&ep=" + varEpisode + "") varShowInfo.text varEpisodeURL = util.extract(varShowInfo.text, "Episode URL@", "Latest") varEpisodePage = requests.get(varEpisodeURL) varEpisodePage.text self.varEpisodeVideo = util.extract(varEpisodePage.text, "},{ url: 'http", ".flv") if self.varEpisodeVideo == None: pass else: varStreamDown = xbmcaddon.Addon('script.tv.promos').getSetting("TVRageStream") if varStreamDown == 'Download': self.varStreamLocation = xbmcaddon.Addon('script.tv.promos').getSetting("TVRageLocation") if self.varStreamLocation == '': util.notify("Please check settings, TVRage Download Location") else: varVid = requests.get('http' + self.varEpisodeVideo + '.flv') with open(self.varStreamLocation + self.varShowName + ".flv", "wb") as code: code.write(varVid.content) else: pass
def playVideo(params): content=util.getURL(params['url'], hdr) xbmc.log("0", xbmc.LOGERROR) if content!=False: video=util.extract(content, '<div id="post_in">', '</div>') url=util.extract(video, '<iframe src="', '"') xbmc.log("0.5 URL > "+url, xbmc.LOGERROR) content2=util.getURL(url, hdr) xbmc.log("1", xbmc.LOGERROR) if content2!=False: if '<iframe src="' in content2 : url=util.extract(content2, '<iframe src="', '"') xbmc.log("2", xbmc.LOGERROR) content3=util.getURL(url, hdr) if content3!=False: if '<iframe src="' in content3 : url=util.extract(content3, '<iframe src="', '"') xbmc.log("3", xbmc.LOGERROR) content4=util.getURL(url, hdr) if content4!=False: xbmc.log("4", xbmc.LOGERROR) url=util.extract(content4, "script.setAttribute('src', '", "'") content5=util.getURL(url.decode('string_escape'), hdr) if content5!=False: mp4_240=util.extract(content5, '"mp4_240":"', '"') mp4_360=util.extract(content5, '"mp4_360":"', '"') mp4_720=util.extract(content5, '"mp4_720":"', '"') mp4_1080=util.extract(content5, '"mp4_1080":"', '"') if mp4_1080!=None: url=mp4_1080.replace("\\", "") elif mp4_720!=None: url=mp4_720.replace("\\", "") elif mp4_360!=None: url=mp4_360.replace("\\", "") elif mp4_240!=None: url=mp4_240.replace("\\", "") xbmc.log("FINAL: "+makeAscii(url), xbmc.LOGERROR) else: xbmc.log("1.5", xbmc.LOGERROR) if '<source src="' in content2: url=util.extract(content2, '<source src="', '"') elif "file: '" in content2: url=util.extract(content2, "file: '", "'") else: url=util.extract(content2, '<source src="', '"') util.playMedia(params['name'], params['poster'], url, "Video")