def retrieveVideoInfo(video_id): video_info = VideoInfo() video_info.set_video_hosting_info(getVideoHostingInfo()) video_info.set_video_id(video_id) try: html = HttpUtils.HttpClient().getHtmlContent(url='http://vimeo.com/' + str(video_id)) referrerObj = re.compile('"timestamp":(.+?),"signature":"(.+?)"').findall(html)[0] req_sig_exp = referrerObj[0] req_sig = referrerObj[1] img_link = re.compile('itemprop="thumbnailUrl" content="(.+?)"').findall(html)[0] video_title = re.compile('"title":"(.+?)"').findall(html)[0] qual = 'sd' video_link = "http://player.vimeo.com/play_redirect?clip_id=%s&sig=%s&time=%s&quality=%s&codecs=H264,VP8,VP6&type=moogaloop_local&embed_location=" % (video_id, req_sig, req_sig_exp, qual) video_info.add_video_link(VIDEO_QUAL_SD, video_link) if(re.search('"hd":1', html)): qual = 'hd' video_link = "http://player.vimeo.com/play_redirect?clip_id=%s&sig=%s&time=%s&quality=%s&codecs=H264,VP8,VP6&type=moogaloop_local&embed_location=" % (video_id, req_sig, req_sig_exp, qual) video_info.add_video_link(VIDEO_QUAL_HD_720, video_link) video_info.set_video_stopped(False) video_info.set_video_image(img_link) video_info.set_video_name(video_title) except Exception, e: Logger.logError(e) video_info.set_video_stopped(True)
def retrieveVideoInfo(video_id): video_info = VideoInfo() video_info.set_video_hosting_info(getVideoHostingInfo()) video_info.set_video_id(video_id) try: video_info_link = 'http://movzap.com/' + str(video_id) html = HttpUtils.HttpClient().getHtmlContent(url=video_info_link) paramSet = re.compile("return p\}\(\'(.+?)\',(\d\d),(\d\d),\'(.+?)\'").findall(html) if len(paramSet) > 0: video_info_link = AddonUtils.parsePackedValue(paramSet[0][0], int(paramSet[0][1]), int(paramSet[0][2]), paramSet[0][3].split('|')).replace('\\', '').replace('"', '\'') img_data = re.compile(r"image:\'(.+?)\'").findall(video_info_link) if len(img_data) == 1: video_info.set_video_image(img_data[0]) video_link = re.compile(r"file:\'(.+?)\'").findall(video_info_link)[0] else: video_link = re.compile("'file': '(.+?)'").findall(html)[0] video_info.set_video_stopped(False) video_info.add_video_link(VIDEO_QUAL_SD, video_link) except Exception, e: Logger.logError(e) video_info.set_video_stopped(True)
def __send_request_to_google_analytics(self, utm_url): ua = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3' import urllib2 try: if self.addon_context.addon.getSetting('ga_enabled') == 'true': #default is disabled req = urllib2.Request(utm_url, None, {'User-Agent':ua}) response = urllib2.urlopen(req) print response.read() response.close() except Exception, e: Logger.logError(e) Logger.logDebug ("GA fail: %s" % utm_url)
def GA(self, group, name): try: from random import randint from urllib import quote VISITOR = self.addon_context.addon.getSetting('ga_visitor') utm_gif_location = "http://www.google-analytics.com/__utm.gif" if not group == "None": utm_track = utm_gif_location + "?" + \ "utmwv=" + self.addon_version + \ "&utmn=" + str(randint(0, 0x7fffffff)) + \ "&utmt=" + "event" + \ "&utme=" + quote("5(" + self.addon_name + "*" + group + "*" + name + ")") + \ "&utmp=" + quote(self.addon_name) + \ "&utmac=" + self.ua_track + \ "&utmcc=__utma=%s" % ".".join(["1", VISITOR, VISITOR, VISITOR, VISITOR, "2"]) try: Logger.logDebug( "============================ POSTING TRACK EVENT ============================" ) self.__send_request_to_google_analytics(utm_track) except Exception, e: Logger.logError(e) Logger.logDebug( "============================ CANNOT POST TRACK EVENT ============================" ) if name == "None": utm_url = utm_gif_location + "?" + \ "utmwv=" + self.addon_version + \ "&utmn=" + str(randint(0, 0x7fffffff)) + \ "&utmp=" + quote(self.addon_name) + \ "&utmac=" + self.ua_track + \ "&utmcc=__utma=%s" % ".".join(["1", VISITOR, VISITOR, VISITOR, VISITOR, "2"]) else: if group == "None": utm_url = utm_gif_location + "?" + \ "utmwv=" + self.addon_version + \ "&utmn=" + str(randint(0, 0x7fffffff)) + \ "&utmp=" + quote(self.addon_name + "/" + name) + \ "&utmac=" + self.ua_track + \ "&utmcc=__utma=%s" % ".".join(["1", VISITOR, VISITOR, VISITOR, VISITOR, "2"]) else: utm_url = utm_gif_location + "?" + \ "utmwv=" + self.addon_version + \ "&utmn=" + str(randint(0, 0x7fffffff)) + \ "&utmp=" + quote(self.addon_name + "/" + group + "/" + name) + \ "&utmac=" + self.ua_track + \ "&utmcc=__utma=%s" % ".".join(["1", VISITOR, VISITOR, VISITOR, VISITOR, "2"]) Logger.logDebug( "============================ POSTING ANALYTICS ============================" ) self.__send_request_to_google_analytics(utm_url)
def __send_request_to_google_analytics(self, utm_url): ua = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3' import urllib2 try: if self.addon_context.addon.getSetting( 'ga_enabled') == 'true': #default is disabled req = urllib2.Request(utm_url, None, {'User-Agent': ua}) response = urllib2.urlopen(req) print response.read() response.close() except Exception, e: Logger.logError(e) Logger.logDebug("GA fail: %s" % utm_url)
def addFavouriteTVShow(request_obj, response_obj): addonContext = Container().getAddonContext() filepath = AddonUtils.getCompleteFilePath(baseDirPath=addonContext.addonProfile, extraDirPath=AddonUtils.ADDON_SRC_DATA_FOLDER, filename=FAV_TV_SHOWS_JSON_FILE, makeDirs=True) favTVShowsJsonObj = {} if AddonUtils.doesFileExist(filepath): try: favTVShowsJsonObj = AddonUtils.getJsonFileObj(filepath) except ValueError: AddonUtils.deleteFile(filepath) Logger.logError('CORRUPT FILE DELETED = ' + filepath) favTVShowsJsonObj[request_obj.get_data()['tvShowName']] = {"tvShowName":request_obj.get_data()['tvShowName'] , "tvShowUrl": request_obj.get_data()['tvShowUrl']} AddonUtils.saveObjToJsonFile(filepath, favTVShowsJsonObj) d = xbmcgui.Dialog() d.ok('TV Show favourite added successfully.', 'ENJOY!')
def __check_media_url(video_url): try: request = urllib2.Request(video_url, headers=HttpUtils.HEADERS) request.get_method = lambda : 'HEAD' response = urllib2.urlopen(request) content_type = response.info().gettype() try: if(APPLICATION_MEDIA_TYPES.index(content_type) >= 0): return 'application' except ValueError: if re.search('audio/', content_type): return 'audio' elif re.search('video/', content_type): return 'video' except urllib2.HTTPError, he: Logger.logError(he)
def removeFavouriteTVShow(request_obj, response_obj): addonContext = Container().getAddonContext() filepath = AddonUtils.getCompleteFilePath(baseDirPath=addonContext.addonProfile, extraDirPath=AddonUtils.ADDON_SRC_DATA_FOLDER, filename=FAV_TV_SHOWS_JSON_FILE, makeDirs=True) favTVShowsJsonObj = {} if AddonUtils.doesFileExist(filepath): try: favTVShowsJsonObj = AddonUtils.getJsonFileObj(filepath) del favTVShowsJsonObj[request_obj.get_data()['tvShowName']] AddonUtils.saveObjToJsonFile(filepath, favTVShowsJsonObj) d = xbmcgui.Dialog() d.ok('TV Show removed favourite successfully.', 'You can add this TV Show again using same way.', 'ENJOY!') xbmc.executebuiltin("Container.Refresh()") except ValueError: AddonUtils.deleteFile(filepath) Logger.logError('CORRUPT FILE DELETED = ' + filepath) d = xbmcgui.Dialog() d.ok('Failed to remove TV Show favourite.', 'Please try again.')
def GA(self, group, name): try: from random import randint from urllib import quote VISITOR = self.addon_context.addon.getSetting('ga_visitor') utm_gif_location = "http://www.google-analytics.com/__utm.gif" if not group == "None": utm_track = utm_gif_location + "?" + \ "utmwv=" + self.addon_version + \ "&utmn=" + str(randint(0, 0x7fffffff)) + \ "&utmt=" + "event" + \ "&utme=" + quote("5(" + self.addon_name + "*" + group + "*" + name + ")") + \ "&utmp=" + quote(self.addon_name) + \ "&utmac=" + self.ua_track + \ "&utmcc=__utma=%s" % ".".join(["1", VISITOR, VISITOR, VISITOR, VISITOR, "2"]) try: Logger.logDebug("============================ POSTING TRACK EVENT ============================") self.__send_request_to_google_analytics(utm_track) except Exception, e: Logger.logError(e) Logger.logDebug("============================ CANNOT POST TRACK EVENT ============================") if name == "None": utm_url = utm_gif_location + "?" + \ "utmwv=" + self.addon_version + \ "&utmn=" + str(randint(0, 0x7fffffff)) + \ "&utmp=" + quote(self.addon_name) + \ "&utmac=" + self.ua_track + \ "&utmcc=__utma=%s" % ".".join(["1", VISITOR, VISITOR, VISITOR, VISITOR, "2"]) else: if group == "None": utm_url = utm_gif_location + "?" + \ "utmwv=" + self.addon_version + \ "&utmn=" + str(randint(0, 0x7fffffff)) + \ "&utmp=" + quote(self.addon_name + "/" + name) + \ "&utmac=" + self.ua_track + \ "&utmcc=__utma=%s" % ".".join(["1", VISITOR, VISITOR, VISITOR, VISITOR, "2"]) else: utm_url = utm_gif_location + "?" + \ "utmwv=" + self.addon_version + \ "&utmn=" + str(randint(0, 0x7fffffff)) + \ "&utmp=" + quote(self.addon_name + "/" + group + "/" + name) + \ "&utmac=" + self.ua_track + \ "&utmcc=__utma=%s" % ".".join(["1", VISITOR, VISITOR, VISITOR, VISITOR, "2"]) Logger.logDebug("============================ POSTING ANALYTICS ============================") self.__send_request_to_google_analytics(utm_url)
def start(addon_id, service_name, context_root, default_port, allowed_port_range): server = None try: sys.argv = None # To handle the situations where some library expects system arguments. Main change made for t0mm0 urlresolver library. global __addon_id__ global __registered_services__ global __context_root__ global __port__ global __port_range__ global __service_name__ __addon_id__ = addon_id __context_root__ = context_root __port__ = default_port __port_range__ = allowed_port_range __service_name__ = service_name containerObj = Container(addon_id=addon_id) iconimage = AddonUtils.getCompleteFilePath(baseDirPath=containerObj.getAddonContext().addonPath, filename='icon.png') serviceport = int(containerObj.getAddonContext().addon.getSetting('serviceport')) XBMCInterfaceUtils.setSuppressDialogMsg(True) if serviceport < __port_range__[0] or serviceport > __port_range__[1] : containerObj.getAddonContext().addon.setSetting('serviceport', str(__port__)) serviceport = __port__ XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service: Port updated', 'Service port set to default value 8181', iconimage=iconimage) server = JSONRPCServer(context_root=__context_root__, server_port=serviceport) server.registerService('serviceName', serviceMethod) defined_services = containerObj.getAddonContext().getTurtleServices() if len(defined_services) == 0: Logger.logError(__service_name__ + ' Service :: There are no services defined for registration, end this service program now.') return for service in defined_services: server.registerService(service.get_service_name(), serviceMethod) __registered_services__[service.get_service_name()] = service.get_action_id() Logger.logInfo(__service_name__ + ' Service :: service registered = %s @ %s' % (service.get_service_name(), __context_root__)) server.start() # XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service has started', 'Use web browser PlayIt extension to play video.', iconimage=iconimage) while not xbmc.abortRequested: time.sleep(1) Logger.logInfo(__service_name__ + ' Service :: ABORT request received from XBMC. PlayIt service will stop now.') except Exception, e: Logger.logFatal(__service_name__ + ' Service :: ERROR OCCURRED: ' + str(e)) ExceptionHandler.handle(e)
def retrieveVideoInfo(video_id): video_info = VideoInfo() video_info.set_video_hosting_info(getVideoHostingInfo()) video_info.set_video_id(video_id) try: video_info_link = 'http://embed.tune.pk/play/' + str( video_id) + '?autoplay=no' html = HttpUtils.HttpClient().getHtmlContent(url=video_info_link) image = re.compile("preview_img = '(.+?)';").findall(html) if image is not None and len(image) == 1: video_info.set_video_image(str(image[0])) html = html.replace('\n\r', '').replace('\r', '').replace('\n', '') sources = re.compile("{(.+?)}").findall( re.compile("sources:(.+?)]").findall(html)[0]) for source in sources: video_link = str(re.compile('file[: ]*"(.+?)"').findall(source)[0]) Logger.logDebug(video_link) label_text = re.compile('label[: ]*"(.+?)"').findall(source) if label_text is not None and len(label_text) == 1: label = str(label_text[0]) Logger.logDebug(label) if label == '240p': video_info.add_video_link(VIDEO_QUAL_LOW, video_link) elif label == '360p' and video_info.get_video_link( VIDEO_QUAL_SD) is None: video_info.add_video_link(VIDEO_QUAL_SD, video_link) elif label == '480p' or label == 'SD': video_info.add_video_link(VIDEO_QUAL_SD, video_link) elif label == '720p' or label == 'HD': video_info.add_video_link(VIDEO_QUAL_HD_720, video_link) elif label == '1080p': video_info.add_video_link(VIDEO_QUAL_HD_1080, video_link) else: video_info.add_video_link(VIDEO_QUAL_SD, video_link) else: video_info.add_video_link(VIDEO_QUAL_SD, video_link) video_info.set_video_stopped(False) except Exception, e: Logger.logError(e) video_info.set_video_stopped(True)
def retrieveVideoInfo(video_id): video_info = VideoInfo() video_info.set_video_hosting_info(getVideoHostingInfo()) video_info.set_video_id(video_id) try: video_link = 'http://www.dailymotion.com/embed/video/' + str(video_id) html = HttpUtils.HttpClient().getHtmlContent(url=video_link) HttpUtils.HttpClient().disableCookies() matchFullHD = re.compile('"stream_h264_hd1080_url":"(.+?)"', re.DOTALL).findall(html) matchHD = re.compile('"stream_h264_hd_url":"(.+?)"', re.DOTALL).findall(html) matchHQ = re.compile('"stream_h264_hq_url":"(.+?)"', re.DOTALL).findall(html) matchSD = re.compile('"stream_h264_url":"(.+?)"', re.DOTALL).findall(html) matchLD = re.compile('"stream_h264_ld_url":"(.+?)"', re.DOTALL).findall(html) dm_LD = None dm_SD = None dm_720 = None dm_1080 = None if matchFullHD: dm_1080 = urllib.unquote_plus(matchFullHD[0]).replace("\\", "") if matchHD: dm_720 = urllib.unquote_plus(matchHD[0]).replace("\\", "") if dm_720 is None and matchHQ: dm_720 = urllib.unquote_plus(matchHQ[0]).replace("\\", "") if matchSD: dm_SD = urllib.unquote_plus(matchSD[0]).replace("\\", "") if matchLD: dm_LD = urllib.unquote_plus(matchLD[0]).replace("\\", "") if dm_LD is not None: video_info.add_video_link(VIDEO_QUAL_LOW, dm_LD, addReferer=True, refererUrl=video_link) if dm_SD is not None: video_info.add_video_link(VIDEO_QUAL_SD, dm_SD, addReferer=True, refererUrl=video_link) if dm_720 is not None: video_info.add_video_link(VIDEO_QUAL_HD_720, dm_720, addReferer=True, refererUrl=video_link) if dm_1080 is not None: video_info.add_video_link(VIDEO_QUAL_HD_1080, dm_1080, addReferer=True, refererUrl=video_link) video_info.set_video_stopped(False) except Exception, e: Logger.logError(e) video_info.set_video_stopped(True)
def serviceMethod(name, **params): actionId = __registered_services__[name] data = {'data':AddonUtils.encodeData(params)} service_response_obj = None containerObj = Container(addon_id=__addon_id__, addon_ver=__addon_ver__) try: iconimage = AddonUtils.getCompleteFilePath(baseDirPath=containerObj.getAddonContext().addonPath, filename='icon.png') XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service', 'Processing received request...', iconimage=iconimage) containerObj.reloadTurtleRequest(data) containerObj.performAction(actionId) service_response_obj = containerObj.getTurtleResponse().get_service_response_obj() except Exception, e: Logger.logError(__service_name__ + ' Service :: UNEXPECTED ERROR OCCURRED') Logger.logError(e) ExceptionHandler.handle(e) service_response_obj = {"status":"exception", "message":"an unexpected error occurred, please check your input"} XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service', 'Error while processing your request', time='5000')
def retrieveVideoInfo(video_id): video_info = VideoInfo() video_info.set_video_hosting_info(getVideoHostingInfo()) video_info.set_video_id(video_id) try: video_url = 'https://www.youtube.com/watch?v=' + video_id yd_video_info = YDStreamExtractor.getVideoInfo(video_url, quality=1) if yd_video_info is not None: video_info.set_video_name(yd_video_info.title) video_info.set_video_image(yd_video_info.thumbnail) video_info.add_video_link(VIDEO_QUAL_HD_720, yd_video_info.streamURL()) video_info.set_video_stopped(False) else: video_info.set_video_stopped(True) except Exception, e: Logger.logError(e) video_info.set_video_stopped(True)
def retrieveVideoInfo(video_id): video_info = VideoInfo() video_info.set_video_hosting_info(getVideoHostingInfo()) video_info.set_video_id(video_id) try: video_info_link = 'http://embed.tune.pk/play/' + str(video_id) + '?autoplay=no' html = HttpUtils.HttpClient().getHtmlContent(url=video_info_link) image = re.compile("preview_img = '(.+?)';").findall(html) if image is not None and len(image) == 1: video_info.set_video_image(str(image[0])) html = html.replace('\n\r', '').replace('\r', '').replace('\n', '') sources = re.compile("{(.+?)}").findall(re.compile("sources:(.+?)]").findall(html)[0]) for source in sources: video_link = str(re.compile('file[: ]*"(.+?)"').findall(source)[0]) Logger.logDebug(video_link) label_text = re.compile('label[: ]*"(.+?)"').findall(source) if label_text is not None and len(label_text) == 1: label = str(label_text[0]) Logger.logDebug(label) if label == '240p': video_info.add_video_link(VIDEO_QUAL_LOW, video_link) elif label == '360p' and video_info.get_video_link(VIDEO_QUAL_SD) is None: video_info.add_video_link(VIDEO_QUAL_SD, video_link) elif label == '480p' or label == 'SD': video_info.add_video_link(VIDEO_QUAL_SD, video_link) elif label == '720p' or label == 'HD': video_info.add_video_link(VIDEO_QUAL_HD_720, video_link) elif label == '1080p': video_info.add_video_link(VIDEO_QUAL_HD_1080, video_link) else: video_info.add_video_link(VIDEO_QUAL_SD, video_link) else: video_info.add_video_link(VIDEO_QUAL_SD, video_link) video_info.set_video_stopped(False) except Exception, e: Logger.logError(e) video_info.set_video_stopped(True)
def playHostedVideo(request_obj, response_obj): pbType = int(Container().getAddonContext().addon.getSetting('playbacktype')) Container().getAddonContext().addon.setSetting('ga_video_title', 'false') if pbType == 2 and XBMCInterfaceUtils.isPlaying(): response_obj.addServiceResponseParam("status", "error") response_obj.addServiceResponseParam("title", "XBMC is already playing.") response_obj.addServiceResponseParam("message", "Check PlayIt Service add-on settings. Your this request is ignored.") item = ListItem() item.set_next_action_name('respond') response_obj.addListItem(item) else: if pbType == 0: XBMCInterfaceUtils.stopPlayer() video_url = request_obj.get_data()['videoLink'] if video_url.startswith('http://goo.gl/'): Logger.logDebug('Found google short URL = ' + video_url) video_url = HttpUtils.getRedirectedUrl(video_url) Logger.logDebug('After finding out redirected URL = ' + video_url) request_obj.get_data()['videoLink'] = video_url if __is_valid_url(video_url): contentType = __check_media_url(video_url) if contentType is not None: if contentType == 'audio': response_obj.set_redirect_action_name('play_direct_audio') request_obj.get_data()['track_title'] = '' request_obj.get_data()['track_link'] = video_url request_obj.get_data()['track_artwork_url'] = '' else: response_obj.set_redirect_action_name('play_direct_video') else: if XBMCInterfaceUtils.isPlayingAudio(): response_obj.addServiceResponseParam("status", "error") response_obj.addServiceResponseParam("title", "Stop active music!") response_obj.addServiceResponseParam("message", "Note: XBMC cannot play video when audio playback is in progress.") item = ListItem() item.set_next_action_name('respond') response_obj.addListItem(item) else: video_hosting_info = SnapVideo.findVideoHostingInfo(video_url) if video_hosting_info is None: response_obj.addServiceResponseParam("status", "error") response_obj.addServiceResponseParam("title", "URL not supported") response_obj.addServiceResponseParam("message", "Video URL is currently not supported by PlayIt. Please check if URL selected is correct.") item = ListItem() item.set_next_action_name('respond') response_obj.addListItem(item) else: Container().ga_client.reportContentUsage('hostedvideo', video_hosting_info.get_video_hosting_name()) response_obj.addServiceResponseParam("status", "success") if not XBMCInterfaceUtils.isPlaying(): XBMCInterfaceUtils.clearPlayList(list_type="video") response_obj.addServiceResponseParam("message", "Enjoy your video!") else: response_obj.addServiceResponseParam("title", "Request Enqueued!") response_obj.addServiceResponseParam("message", "Your request has been added to player queue.") response_obj.set_redirect_action_name('play_it') request_obj.get_data()['videoTitle'] = 'PlayIt Video' else: Logger.logError('video_url = ' + str(video_url)) response_obj.addServiceResponseParam("status", "error") response_obj.addServiceResponseParam("title", "Invalid URL") response_obj.addServiceResponseParam("message", "Video URL is not valid one! Please check and try again.") item = ListItem() item.set_next_action_name('respond') response_obj.addListItem(item)
def APP_LAUNCH(self): versionNumber = int(xbmc.getInfoLabel("System.BuildVersion")[0:2]) if versionNumber < 12: if xbmc.getCondVisibility("system.platform.osx"): if xbmc.getCondVisibility("system.platform.atv2"): log_path = "/var/mobile/Library/Preferences" else: log_path = os.path.join(os.path.expanduser("~"), "Library/Logs") elif xbmc.getCondVisibility("system.platform.ios"): log_path = "/var/mobile/Library/Preferences" elif xbmc.getCondVisibility("system.platform.windows"): log_path = xbmc.translatePath("special://home") log = os.path.join(log_path, "xbmc.log") logfile = open(log, "r").read() elif xbmc.getCondVisibility("system.platform.linux"): log_path = xbmc.translatePath("special://home/temp") else: log_path = xbmc.translatePath("special://logpath") log = os.path.join(log_path, "xbmc.log") logfile = open(log, "r").read() match = re.compile("Starting XBMC \((.+?) Git:.+?Platform: (.+?)\. Built.+?").findall(logfile) elif versionNumber > 11: Logger.logDebug("======================= more than ====================") log_path = xbmc.translatePath("special://logpath") log = os.path.join(log_path, "xbmc.log") logfile = open(log, "r").read() match = re.compile("Starting XBMC \((.+?) Git:.+?Platform: (.+?)\. Built.+?").findall(logfile) else: logfile = "Starting XBMC (Unknown Git:.+?Platform: Unknown. Built.+?" match = re.compile("Starting XBMC \((.+?) Git:.+?Platform: (.+?)\. Built.+?").findall(logfile) Logger.logDebug( "========================== " + self.addon_name + " " + self.addon_version + " ==========================" ) from random import randint from urllib import quote VISITOR = self.addon_context.addon.getSetting("ga_visitor") for build, PLATFORM in match: if re.search("12", build[0:2], re.IGNORECASE): build = "Frodo" if re.search("11", build[0:2], re.IGNORECASE): build = "Eden" if re.search("13", build[0:2], re.IGNORECASE): build = "Gotham" Logger.logDebug(build) Logger.logDebug(PLATFORM) utm_gif_location = "http://www.google-analytics.com/__utm.gif" utm_track = ( utm_gif_location + "?" + "utmwv=" + self.addon_version + "&utmn=" + str(randint(0, 0x7FFFFFFF)) + "&utmt=" + "event" + "&utme=" + quote("5(APP LAUNCH*" + build + "*" + PLATFORM + ")") + "&utmp=" + quote(self.addon_name) + "&utmac=" + self.ua_track + "&utmcc=__utma=%s" % ".".join(["1", VISITOR, VISITOR, VISITOR, VISITOR, "2"]) ) try: Logger.logDebug( "============================ POSTING APP LAUNCH TRACK EVENT ============================" ) self.__send_request_to_google_analytics(utm_track) except Exception, e: Logger.logError(e) Logger.logDebug( "============================ CANNOT POST APP LAUNCH TRACK EVENT ============================" )
"&utmcc=__utma=%s" % ".".join(["1", VISITOR, VISITOR, VISITOR, VISITOR, "2"]) else: utm_url = utm_gif_location + "?" + \ "utmwv=" + self.addon_version + \ "&utmn=" + str(randint(0, 0x7fffffff)) + \ "&utmp=" + quote(self.addon_name + "/" + group + "/" + name) + \ "&utmac=" + self.ua_track + \ "&utmcc=__utma=%s" % ".".join(["1", VISITOR, VISITOR, VISITOR, VISITOR, "2"]) Logger.logDebug( "============================ POSTING ANALYTICS ============================" ) self.__send_request_to_google_analytics(utm_url) except Exception, e: Logger.logError(e) Logger.logDebug( "================ CANNOT POST TO ANALYTICS ================") def APP_LAUNCH(self): versionNumber = int(xbmc.getInfoLabel("System.BuildVersion")[0:2]) ''' if versionNumber < 12: if xbmc.getCondVisibility('system.platform.osx'): if xbmc.getCondVisibility('system.platform.atv2'): log_path = '/var/mobile/Library/Preferences' else: log_path = os.path.join(os.path.expanduser('~'), 'Library/Logs') elif xbmc.getCondVisibility('system.platform.ios'): log_path = '/var/mobile/Library/Preferences' elif xbmc.getCondVisibility('system.platform.windows'):
qual = formatQual url = HttpUtils.HttpClient().addHttpCookiesToUrl(formatUrl, addHeaders=False,addCookies=False, extraExtraHeaders={'Referer':'https://www.youtube.com/watch?v=' + video_id}) streams[int(qual)] = url Logger.logDebug(streams) for qual in STREAMS_QUAL_MAP: for key in STREAMS_QUAL_MAP[qual]: if streams.has_key(key): url = streams[key] video_info.add_video_link(qual, url) break video_info.set_video_stopped(False) except Exception, e: Logger.logError(e) video_info.set_video_stopped(True) return video_info def swap(a , b): c = a[0] a[0] = a[b % len(a)] a[b] = c return a def parseSignature(s): ''' use decryption solution by Youtube-DL project ''' if len(s) == 93: return s[86:29:-1] + s[88] + s[28:5:-1] elif len(s) == 92:
def APP_LAUNCH(self): versionNumber = int(xbmc.getInfoLabel("System.BuildVersion")[0:2]) if versionNumber < 12: if xbmc.getCondVisibility('system.platform.osx'): if xbmc.getCondVisibility('system.platform.atv2'): log_path = '/var/mobile/Library/Preferences' else: log_path = os.path.join(os.path.expanduser('~'), 'Library/Logs') elif xbmc.getCondVisibility('system.platform.ios'): log_path = '/var/mobile/Library/Preferences' elif xbmc.getCondVisibility('system.platform.windows'): log_path = xbmc.translatePath('special://home') log = os.path.join(log_path, 'xbmc.log') logfile = open(log, 'r').read() elif xbmc.getCondVisibility('system.platform.linux'): log_path = xbmc.translatePath('special://home/temp') else: log_path = xbmc.translatePath('special://logpath') log = os.path.join(log_path, 'xbmc.log') logfile = open(log, 'r').read() match = re.compile( 'Starting XBMC \((.+?) Git:.+?Platform: (.+?)\. Built.+?' ).findall(logfile) elif versionNumber > 11: Logger.logDebug( '======================= more than ====================') log_path = xbmc.translatePath('special://logpath') log = os.path.join(log_path, 'xbmc.log') logfile = open(log, 'r').read() match = re.compile( 'Starting XBMC \((.+?) Git:.+?Platform: (.+?)\. Built.+?' ).findall(logfile) else: logfile = 'Starting XBMC (Unknown Git:.+?Platform: Unknown. Built.+?' match = re.compile( 'Starting XBMC \((.+?) Git:.+?Platform: (.+?)\. Built.+?' ).findall(logfile) Logger.logDebug('========================== ' + self.addon_name + ' ' + self.addon_version + ' ==========================') from random import randint from urllib import quote VISITOR = self.addon_context.addon.getSetting('ga_visitor') for build, PLATFORM in match: if re.search('12', build[0:2], re.IGNORECASE): build = "Frodo" if re.search('11', build[0:2], re.IGNORECASE): build = "Eden" if re.search('13', build[0:2], re.IGNORECASE): build = "Gotham" Logger.logDebug(build) Logger.logDebug(PLATFORM) utm_gif_location = "http://www.google-analytics.com/__utm.gif" utm_track = utm_gif_location + "?" + \ "utmwv=" + self.addon_version + \ "&utmn=" + str(randint(0, 0x7fffffff)) + \ "&utmt=" + "event" + \ "&utme=" + quote("5(APP LAUNCH*" + build + "*" + PLATFORM + ")") + \ "&utmp=" + quote(self.addon_name) + \ "&utmac=" + self.ua_track + \ "&utmcc=__utma=%s" % ".".join(["1", VISITOR, VISITOR, VISITOR, VISITOR, "2"]) try: Logger.logDebug( "============================ POSTING APP LAUNCH TRACK EVENT ============================" ) self.__send_request_to_google_analytics(utm_track) except Exception, e: Logger.logError(e) Logger.logDebug( "============================ CANNOT POST APP LAUNCH TRACK EVENT ============================" )