예제 #1
0
def patchYoutubeDL():

    # if there is no comment between `ValueError:` and `pass` then we haven't patched this section before
    toBePatched = """
        except ValueError:
            pass
"""

    # The comment between `ValueError:` and `pass` ensures we won't patch it repeatedly
    patch = """
        except ValueError:
            # Start: patched by SendToKodi
            pass
        except TypeError:
            pass
            # End: patched by SendToKodi
"""

    addonPath = xbmcaddon.Addon().getAddonInfo('path')
    youtubeDlPath = addonPath + "/youtube_dl"
    utilsPyPath = youtubeDlPath + '/utils.py'

    # Borrowed from https://forum.kodi.tv/showthread.php?tid=315590
    with closing(File(utilsPyPath, 'r')) as fo:
        fileData = fo.read()

    dataToWrite = fileData.replace(toBePatched, patch)

    with closing(File(utilsPyPath, 'w')) as fo:
        fo.write(dataToWrite)
예제 #2
0
def _parse_file(filename):
    """Extract metatata from file"""
    # Workaround to fix unicode path problem on different OSs
    if sys.platform == 'win32':
        f = open(filename, 'rb')
    else:
        f = File(filename)
    try:
        s = StringIO(f.read(1024 * 64))
        p = guessParser(InputIOStream(s, filename=unicode(filename), tags=[]))
        metadata = extractMetadata(p)
    finally:
        f.close()
    return metadata
예제 #3
0
 def LireM3u(self, CheminxAmAx, F4m=False, cvNom=True):
     print "Liste de chaine M3u"
     dialog = Dialog()
     fn = dialog.browse(1, 'Ouvrir le fichier M3u', 'files', '.m3u|.m3u8',
                        False, False, 'special://home')
     ret = []
     if fn != False and fn != "":
         if exists(fn):
             f = File(fn)
             M3u = f.read()
             f.close()
             if M3u != "":
                 ret = self.TabM3u(M3u, F4m, cvNom)
     return ret
예제 #4
0
def download_subs(link, referer, filename='subtitles.srt'):
    """
    Download subtitles from addic7ed.com

    :param link: relative lint to .srt file
    :type link: str
    :param referer: episode page for referer header
    :type referer: str
    :param filename: file name for subtitles
    :type filename: str
    :raises: ConnectionError if addic7ed.com cannot be opened
    :raises: DailyLimitError if a user exceeded their daily download quota (10 subtitles).
    """
    subtitles = session.download_subs(link, referer=referer)
    if subtitles[:9].lower() != '<!doctype':
        with closing(File(filename, 'w')) as fo:
            fo.write(subtitles)
    else:
        raise DailyLimitError
예제 #5
0
def save_the_file(subtitlefile, filename, playing=False):
    global backupfile
    #save w. edited, save current, save custom, back, exit w/o saving
    choice = xbmcgui.Dialog().contextmenu(
        [_(32038), _(32039), _(32040),
         _(32005), _(32041)])
    if choice == -1 or choice == 3:
        show_dialog(subtitlefile, filename)
    if choice == 4:
        check_player_instances()
        sys.exit()
    if choice == 0:
        new_file_name = filename[:-4] + "_edited.srt"
    if choice == 1:
        new_file_name = filename[:-4] + ".srt"
    if choice == 2:
        # Give new filename
        new_file_name = xbmcgui.Dialog().input(_(32042),
                                               defaultt=filename[:-4] + ".srt")
    with closing(File(new_file_name, 'w')) as fo:
        fo.write("".join(subtitlefile))
    backupfile = copy.deepcopy(subtitlefile)
    if playing:
        xbmc.Player().setSubtitles(new_file_name)
        temp_file = filename[:-4] + "_temp.srt"
        if xbmcvfs.exists(temp_file):
            xbmcvfs.delete(temp_file)
        # succes, file saved to:
        xbmcgui.Dialog().ok(_(32017), _(32123) + str(new_file_name))
        xbmc.Player().pause()
        check_player_instances()
        sys.exit()
    if not playing:
        if xbmcvfs.exists(new_file_name):
            # written to, to use select in kodi sub menu
            xbmcgui.Dialog().ok(_(32043), new_file_name + _(32044))
        else:
            #Error, File not written
            xbmcgui.Dialog().ok(_(32014), _(32045))
        show_dialog(subtitlefile, filename)
def open_file(path, flags='r'):
    """Open a file (using xbmcvfs)"""
    from xbmcvfs import File
    fdesc = File(path, flags)
    yield fdesc
    fdesc.close()
 def get_playing_file_size(self):
     f = File(self.video_file_name)
     s = f.size()
     f.close()
     return s
예제 #8
0
def home_tv_series(count=5):
    xbmc.log("--home_tv_series", level=xbmc.LOGNOTICE)

    tv_series = get_from_tvtime(profile=__profile__)
    ## the following one is for test.
    # try:
    #     with open(__profile__ + 'tvshows_tvtime_status.json', "r") as json_file:
    #         tv_series = json.load(json_file)
    # except Exception as e:
    #     tv_series = []
    #     print(e)
    #     pass

    tv_series_dirs, _ = listdir(smb_home + "tvseries")
    xbmc.log(str(tv_series_dirs), level=xbmc.LOGNOTICE)

    # to consider the "count", use: tv_series[:count]
    for item in tv_series:
        xbmc.log(str(item), level=xbmc.LOGNOTICE)

        # create this tvseries' directory, if it doesn't exist
        item_dir = smb_home + "tvseries/" + item["title"] + "/"
        if not exists(item_dir):
            mkdir(item_dir)

        # create a file in the directory that indicates the episode we have to watch next
        with closing(File(item_dir + "info.txt", "w")) as info_file:
            info_file.write(str(item["episode_to_watch"]))

        season_to_watch = re.search("S\d{2}",
                                    item["episode_to_watch"]).group(0)
        episode_to_watch = re.search("E\d{2}",
                                     item["episode_to_watch"]).group(0)
        season_dir = item_dir + season_to_watch + "/"
        if not exists(season_dir):
            mkdir(season_dir)

        _, files = listdir(season_dir)
        try:
            file_name = [
                file_name for file_name in files
                if episode_to_watch.lower() in file_name.lower()
            ][0]
            file_path = "smb://" + config.SMBNAME + "/public/tvseries/" + item[
                "title"] + "/" + season_to_watch + "/" + file_name
        except Exception as e:
            print(e)
            # file_path = ""
            continue

        xbmc.log(str(file_path), level=xbmc.LOGNOTICE)

        is_folder = False
        list_item = xbmcgui.ListItem(label=item["title"] + " - " +
                                     item["episode_to_watch"])
        list_item.setArt({
            'thumb': item["image"],
            'icon': item["image"],
            'fanart': item["image"]
        })
        list_item.setInfo(
            'video', {
                'title': item["title"],
                'genre': item["remaining_episodes"],
                'mediatype': 'movie',
                'plot': item["remaining_episodes"],
            })
        url = get_url(action='play_local', file_path=file_path)
        xbmc.log(str(url), level=xbmc.LOGNOTICE)
        xbmcplugin.addDirectoryItem(_handle, url, list_item, is_folder)

    ## get not-started-yet data from tvtime too
    is_folder = False
    list_item = xbmcgui.ListItem(label="Get all not-started-yet ...")
    list_item.setInfo(
        'video', {
            'plot': "Get all not-started-yet tv-series data from Tvtime",
        })
    url = get_url(action='get_all_tvtime')
    xbmc.log(str(url), level=xbmc.LOGNOTICE)
    xbmcplugin.addDirectoryItem(_handle, url, list_item, is_folder)

    ## refresh option
    is_folder = False
    list_item = xbmcgui.ListItem(label="Refresh ...")
    list_item.setInfo('video', {
        'plot':
        "Refresh the current list based on updated data on the Tvtime",
    })
    url = get_url(action='refresh_list')
    xbmc.log(str(url), level=xbmc.LOGNOTICE)
    xbmcplugin.addDirectoryItem(_handle, url, list_item, is_folder)

    xbmcplugin.setContent(int(sys.argv[1]), 'Movies')

    xbmcplugin.endOfDirectory(_handle)