def Search( item ):
  search_data = []
  try:
    search_data = OSDBServer().searchsubtitles(item)
  except:
    log( __name__, "failed to connect to service for subtitle search")
    xbmc.executebuiltin((u'Notification(%s,%s)' % (__scriptname__ , __language__(32001))).encode('utf-8'))
    return

  if search_data != None:
    search_data.sort(key=lambda x: [not x['MatchedBy'] == 'moviehash',x['LanguageName']])
    for item_data in search_data:
      listitem = xbmcgui.ListItem(label          = item_data["LanguageName"],
                                  label2         = item_data["SubFileName"],
                                  iconImage      = str(int(round(float(item_data["SubRating"])/2))),
                                  thumbnailImage = item_data["ISO639"]
                                  )

      listitem.setProperty( "sync", ("false", "true")[str(item_data["MatchedBy"]) == "moviehash"] )
      listitem.setProperty( "hearing_imp", ("false", "true")[int(item_data["SubHearingImpaired"]) != 0] )
      url = "plugin://%s/?action=download&link=%s&ID=%s&filename=%s&format=%s" % (__scriptid__,
                                                                        item_data["ZipDownloadLink"],
                                                                        item_data["IDSubtitleFile"],
                                                                        item_data["SubFileName"],
                                                                        item_data["SubFormat"]
                                                                        )

      xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=listitem,isFolder=False)
示例#2
0
文件: service.py 项目: roeiba/xbmc
def Search( item ):
  search_data = []
  try:
    search_data = OSDBServer().searchsubtitles(item)
  except:
    log( __name__, "failed to connect to service for subtitle search")
    xbmc.executebuiltin((u'Notification(%s,%s)' % (__scriptname__ , __language__(32001))).encode('utf-8'))
    return

  if search_data != None:
    search_data.sort(key=lambda x: [not x['MatchedBy'] == 'moviehash',x['LanguageName']])
    for item_data in search_data:
      listitem = xbmcgui.ListItem(label          = item_data["LanguageName"],
                                  label2         = item_data["SubFileName"],
                                  iconImage      = str(int(round(float(item_data["SubRating"])/2))),
                                  thumbnailImage = item_data["ISO639"]
                                  )

      listitem.setProperty( "sync", ("false", "true")[str(item_data["MatchedBy"]) == "moviehash"] )
      listitem.setProperty( "hearing_imp", ("false", "true")[int(item_data["SubHearingImpaired"]) != 0] )
      url = "plugin://%s/?action=download&link=%s&ID=%s&filename=%s&format=%s" % (__scriptid__,
                                                                        item_data["ZipDownloadLink"],
                                                                        item_data["IDSubtitleFile"],
                                                                        item_data["SubFileName"],
                                                                        item_data["SubFormat"]
                                                                        )

      xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=listitem,isFolder=False)
示例#3
0
def Search( item ):
  search_data = []
  try:
    search_data = OSDBServer().searchsubtitles(item)
  except:
    log( __name__, "failed to connect to service for subtitle search")
    xbmc.executebuiltin((u'Notification(%s,%s)' % (__scriptname__ , __language__(32001))).encode('utf-8'))
    return

  if search_data != None:
    search_data.sort(key=lambda x: [not x['MatchedBy'] == 'moviehash',
				     not os.path.splitext(x['SubFileName'])[0] == os.path.splitext(os.path.basename(urllib.unquote(xbmc.Player().getPlayingFile().decode('utf-8'))))[0],
				     not normalizeString(xbmc.getInfoLabel("VideoPlayer.OriginalTitle")).lower() in x['SubFileName'].replace('.',' ').lower(),
				     not x['LanguageName'] == PreferredSub])
    for item_data in search_data:
      ## hack to work around issue where Brazilian is not found as language in XBMC
      if item_data["LanguageName"] == "Brazilian":
        item_data["LanguageName"] = "Portuguese (Brazil)"
      listitem = xbmcgui.ListItem(label          = item_data["LanguageName"],
                                  label2         = item_data["SubFileName"],
                                  iconImage      = str(int(round(float(item_data["SubRating"])/2))),
                                  thumbnailImage = item_data["ISO639"]
                                  )

      listitem.setProperty( "sync", ("false", "true")[str(item_data["MatchedBy"]) == "moviehash"] )
      listitem.setProperty( "hearing_imp", ("false", "true")[int(item_data["SubHearingImpaired"]) != 0] )
      url = "plugin://%s/?action=download&link=%s&ID=%s&filename=%s&format=%s" % (__scriptid__,
                                                                        item_data["ZipDownloadLink"],
                                                                        item_data["IDSubtitleFile"],
                                                                        item_data["SubFileName"],
                                                                        item_data["SubFormat"]
                                                                        )

      xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=listitem,isFolder=False)
示例#4
0
def Search(item):
    search_data = []
    try:
        search_data = OSDBServer().searchsubtitles(item)
    except:
        log(__name__, "failed to connect to service for subtitle search")
        xbmc.executebuiltin(
            (u'Notification(%s,%s)' %
             (__scriptname__, __language__(32001))).encode('utf-8'))
        return

    if search_data != None:
        if isinstance(search_data, dict):
            log(__name__, "received data has a new format, convert it to list")
            search_data = [v for v in search_data.values()]
        search_data.sort(key=lambda x: [
            not x['MatchedBy'] == 'moviehash', not os.path.
            splitext(x['SubFileName'])[0] == os.path.splitext(
                os.path.basename(urllib.unquote(item['file_original_path'])))[
                    0], not normalizeString(
                        xbmc.getInfoLabel("VideoPlayer.OriginalTitle")).lower(
                        ) in x['SubFileName'].replace('.', ' ').lower(), not x[
                            'LanguageName'] == PreferredSub
        ])
        for item_data in search_data:
            ## hack to work around issue where Brazilian is not found as language in XBMC
            if item_data["LanguageName"] == "Brazilian":
                item_data["LanguageName"] = "Portuguese (Brazil)"

            if ((item['season'] == item_data['SeriesSeason']
                 and item['episode'] == item_data['SeriesEpisode'])
                    or (item['season'] == "" and item['episode'] == ""
                        )  ## for file search, season and episode == ""
                ):
                listitem = xbmcgui.ListItem(
                    label=item_data["LanguageName"],
                    label2=item_data["SubFileName"],
                    iconImage=str(int(round(float(item_data["SubRating"]) /
                                            2))),
                    thumbnailImage=item_data["ISO639"])

                listitem.setProperty(
                    "sync",
                    ("false",
                     "true")[str(item_data["MatchedBy"]) == "moviehash"])
                listitem.setProperty(
                    "hearing_imp",
                    ("false",
                     "true")[int(item_data["SubHearingImpaired"]) != 0])
                url = "plugin://%s/?action=download&link=%s&ID=%s&filename=%s&format=%s" % (
                    __scriptid__, item_data["ZipDownloadLink"],
                    item_data["IDSubtitleFile"], item_data["SubFileName"],
                    item_data["SubFormat"])

                xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                            url=url,
                                            listitem=listitem,
                                            isFolder=False)
示例#5
0
def Download(id, url, format, stack=False):
    subtitle_list = []
    exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass"]
    if stack:  ## we only want XMLRPC download if movie is not in stack,
        ## you can only retreive multiple subs in zip
        result = False
    else:
        subtitle = os.path.join(__temp__,
                                "%s.%s" % (str(uuid.uuid4()), format))
        try:
            result = OSDBServer().download(id, subtitle)
        except:
            log(__name__, "failed to connect to service for subtitle download")
            return subtitle_list
    if not result:
        log(__name__, "Download Using HTTP")
        zip = os.path.join(__temp__, "OpenSubtitles.zip")
        f = urllib.urlopen(url)
        with open(zip, "wb") as subFile:
            subFile.write(f.read())
        subFile.close()
        xbmc.sleep(500)
        xbmc.executebuiltin(('XBMC.Extract("%s","%s")' % (
            zip,
            __temp__,
        )).encode('utf-8'), True)
        for file in xbmcvfs.listdir(zip)[1]:
            file = os.path.join(__temp__, file)
            if (os.path.splitext(file)[1] in exts):
                subtitle_list.append(file)
    else:
        subtitle_list.append(subtitle)

    if xbmcvfs.exists(subtitle_list[0]):
        return subtitle_list
示例#6
0
def Search(item):
    search_data = []
    try:
        search_data = OSDBServer().searchsubtitles(item)
    except:
        log(__name__, "failed to connect to service for subtitle search")
        xbmc.executebuiltin((u'Notification(%s,%s)' % (__scriptname__, __language__(32001))).encode('utf-8'))
        return
    if search_data != None:
        for item_data in search_data:
            listitem = xbmcgui.ListItem(label=item_data["LanguageName"],
                                        label2=item_data["SubFileName"],
                                        iconImage=item_data["SubRating"],
                                        thumbnailImage=item_data["ISO639"]
                                        )

            listitem.setProperty("sync", ("false", "true")[str(item_data["MatchedBy"]) == "moviehash"])
            listitem.setProperty("hearing_imp", ("false", "true")[int(item_data["SubHearingImpaired"]) != 0])
            url = "plugin://%s/?action=download&link=%s&filename=%s&format=%s&traducator=%s" % (__scriptid__,
                                                                                                item_data["ZipDownloadLink"],
                                                                                                item_data["SubFileName"],
                                                                                                item_data["referer"],
                                                                                                item_data["Traducator"]
                                                                                                )
            #f = open( '/storage/.kodi/temp/files2.py', 'w' )
            #f.write( 'url = ' + repr(url) + '\n' )
            #f.close()
            xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=listitem, isFolder=False)
def Search(item):
    try:
        search_data = OSDBServer().searchsubtitles(item)
    except:
        log(__name__, "failed to connect to service for subtitle search")
        xbmc.executebuiltin(
            (u'Notification(%s,%s)' %
             (__scriptname__, __language__(32001))).encode('utf-8'))
        return
    subtitles_list = []

    if search_data != None:
        for item_data in search_data:
            if item_data["ISO639"]:
                lang_index = 0
                for user_lang_id in item['3let_language']:
                    if user_lang_id == item_data["ISO639"]:
                        break
                    lang_index += 1
            if str(item_data["MatchedBy"]) == "moviehash":
                sync = True
            else:
                sync = False

            subtitles_list.append({
                'lang_index':
                lang_index,
                'filename':
                item_data["SubFileName"],
                'link':
                item_data["ZipDownloadLink"],
                'language_name':
                item_data["LanguageName"],
                'language_flag':
                item_data["ISO639"],
                'language_id':
                item_data["SubLanguageID"],
                'ID':
                item_data["IDSubtitleFile"],
                'rating':
                str(int(round(float(item_data["SubRating"]) / 2))),
                'format':
                item_data["SubFormat"],
                'sync':
                sync,
                'hearing_imp':
                int(item_data["SubHearingImpaired"]) != 0
            })

        subtitles_list.sort(key=lambda x: [not x['sync'], x['language_name']])

    if subtitles_list:
        for it in subtitles_list:
            listitem = xbmcgui.ListItem(label=it["language_name"],
                                        label2=it["filename"],
                                        iconImage=it["rating"],
                                        thumbnailImage=it["language_flag"])
            if it["sync"]:
                listitem.setProperty("sync", "true")
            else:
                listitem.setProperty("sync", "false")

            if it.get("hearing_imp", False):
                listitem.setProperty("hearing_imp", "true")
            else:
                listitem.setProperty("hearing_imp", "false")

            url = "plugin://%s/?action=download&link=%s&ID=%s&filename=%s" % (
                __scriptid__, it["link"], it["ID"], it["filename"])

            xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                        url=url,
                                        listitem=listitem,
                                        isFolder=False)
def Search(item):
    search_data = []
    try:
        search_data = OSDBServer().searchsubtitles(item)
    except:
        log(__name__, "failed to connect to service for subtitle search")
        xbmc.executebuiltin(
            (u'Notification(%s,%s)' %
             (__scriptname__, __language__(32001))).encode('utf-8'))
        return

    if search_data != None:
        search_data.sort(key=lambda x: [
            not x['MatchedBy'] == 'moviehash', not os.path.
            splitext(x['SubFileName'])[0] == os.path.splitext(
                os.path.basename(urllib.unquote(item['file_original_path'])))[
                    0], not normalizeString(
                        xbmc.getInfoLabel("VideoPlayer.OriginalTitle")).lower(
                        ) in x['SubFileName'].replace('.', ' ').lower(), not x[
                            'LanguageName'] == PreferredSub
        ])
        listitems = []
        for item_data in search_data:
            ## hack to work around issue where Brazilian is not found as language in XBMC
            if item_data["LanguageName"] == "Brazilian":
                item_data["LanguageName"] = "Portuguese (Brazil)"

            if ((item['season'] == item_data['SeriesSeason']
                 and item['episode'] == item_data['SeriesEpisode'])
                    or (item['season'] == "" and item['episode'] == ""
                        )  ## for file search, season and episode == ""
                ):
                listitem = xbmcgui.ListItem(
                    label=item_data["LanguageName"],
                    label2=item_data["SubFileName"],
                    iconImage=str(int(round(float(item_data["SubRating"]) /
                                            2))),
                    thumbnailImage=item_data["ISO639"])
                listitem.setProperty(
                    "sync",
                    ("false",
                     "true")[str(item_data["MatchedBy"]) == "moviehash"])
                listitem.setProperty(
                    "hearing_imp",
                    ("false",
                     "true")[int(item_data["SubHearingImpaired"]) != 0])
                url = "plugin://%s/?action=download&link=%s&ID=%s&filename=%s&format=%s" % (
                    __scriptid__, item_data["ZipDownloadLink"],
                    item_data["IDSubtitleFile"], item_data["SubFileName"],
                    item_data["SubFormat"])
                listitems.append(listitem)
                if (__addon__.getSetting('dualsub_enable') != 'true'):
                    xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                                url=url,
                                                listitem=listitem,
                                                isFolder=False)
        if (__addon__.getSetting('dualsub_enable') == 'true'):
            dialog = xbmcgui.Dialog()
            ret = dialog.multiselect("Choose a subtitle",
                                     [i for i in listitems],
                                     useDetails=True)
            if ret and len(ret) > 0:
                subs = []
                for sub in ret:
                    subs.append({
                        'ID': search_data[sub]['IDSubtitleFile'],
                        'link': search_data[sub]['ZipDownloadLink'],
                        'filename': search_data[sub]['SubFileName'],
                        'format': search_data[sub]['SubFormat']
                    })
                payload = json.dumps(subs[:2])
                payload = urllib.quote(payload)
                listitem = xbmcgui.ListItem(label2=__language__(32019))
                url = "plugin://%s/?action=download&payload=%s" % (
                    __scriptid__, payload)
                xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                            url=url,
                                            listitem=listitem,
                                            isFolder=False)