Ejemplo n.º 1
0
        private void doUpload()
        {
            try
            {
                UploadItemData.IsBusy   = true;
                UploadItemData.FinalUrl = string.Empty;

                var openSubtitlesXmlRpc = new OpenSubtitlesXmlRpc(UploadItemData.MoviePath);
                var finalUrl            = openSubtitlesXmlRpc.UploadSubtitle(
                    UploadItemData.ImdbId,
                    UploadItemData.SelectedSubtitleLanguage.IdSubLanguage.ToLower(),
                    UploadItemData.SubtitlePath,
                    e => UploadItemData.Progress = e);

                setFinalUrl(finalUrl);
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogExceptionToFile(ex);
                LogWindow.AddMessage(LogType.Error, ex.Message);
            }
            finally
            {
                UploadItemData.IsBusy   = false;
                UploadItemData.Progress = 0;
            }
        }
        private void downloadSelectedFiles()
        {
            if (_downloadSelectedFilesIsBusy)
            {
                return;
            }

            try//it's mandatory for threading
            {
                if (string.IsNullOrWhiteSpace(DownloadOpenSubtitlesGuiData.MoviePath))
                {
                    return;
                }

                _downloadSelectedFilesIsBusy = true;

                var osdb = new OpenSubtitlesXmlRpc(DownloadOpenSubtitlesGuiData.MoviePath);

                foreach (var sub in OsdbItemsData)
                {
                    if (!sub.IsSelected)
                    {
                        continue;
                    }
                    var localSub = sub;
                    osdb.DownloadSubtitle(
                        sub.IDSubtitleFile.ToString(CultureInfo.InvariantCulture),
                        sub.SubFileName,
                        sub.LanguageName,
                        e => localSub.Progress = e
                        );
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogExceptionToFile(ex);
                LogWindow.AddMessage(LogType.Error, ex.Message);
            }
            finally
            {
                _downloadSelectedFilesIsBusy = false;
            }
        }
        private void downloadSelectedItem(object debugMode)
        {
            try//it's mandatory for threading
            {
                if (string.IsNullOrWhiteSpace(DownloadOpenSubtitlesGuiData.MoviePath))
                {
                    return;
                }

                var osdb = new OpenSubtitlesXmlRpc(DownloadOpenSubtitlesGuiData.MoviePath);
                osdb.DownloadSubtitle(
                    DownloadOpenSubtitlesGuiData.SelectedOsdbItem.IDSubtitleFile.ToString(CultureInfo.InvariantCulture),
                    DownloadOpenSubtitlesGuiData.SelectedOsdbItem.SubFileName,
                    DownloadOpenSubtitlesGuiData.SelectedOsdbItem.LanguageName,
                    e => DownloadOpenSubtitlesGuiData.SelectedOsdbItem.Progress = e,
                    (bool)debugMode
                    );
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogExceptionToFile(ex);
                LogWindow.AddMessage(LogType.Error, ex.Message);
            }
        }
        private void searchGetSubsInfo()
        {
            try //it's mandatory for threading
            {
                if (string.IsNullOrWhiteSpace(DownloadOpenSubtitlesGuiData.MoviePath))
                {
                    return;
                }

                DownloadOpenSubtitlesGuiData.IsBusy   = true;
                DownloadOpenSubtitlesGuiData.Progress = 0;

                OsdbItemsData.Clear();
                RaisePropertyChanged("OsdbItemsData");

                var osdb = new OpenSubtitlesXmlRpc(DownloadOpenSubtitlesGuiData.MoviePath);

                var subLanguageId = selectLang();

                var result = osdb.GetListOfAllSubtitles(e => DownloadOpenSubtitlesGuiData.Progress = e, subLanguageId);

                if (result == null || result.data == null || result.data.Length == 0)
                {
                    DownloadOpenSubtitlesGuiData.IsBusy = false;
                    return;
                }

                //sort by LanguageName then by SubAddDate
                var subtitles = result.data.OrderBy(o => o.LanguageName).ThenBy(o => o.SubAddDate).Distinct().ToArray();

                setMovieInfo(result);

                OsdbItemsData.Clear();
                foreach (var item in subtitles)
                {
                    var iso6393166_1 = getIsoCode(item);

                    OsdbItemsData.Add(new OsdbItem
                    {
                        IDSubtitleFile = int.Parse(item.IDSubtitleFile),
                        LanguageName   = item.LanguageName,
                        SubAddDate     = item.SubAddDate,
                        ISO639         = item.ISO639,
                        ISO6393166_1   = iso6393166_1,
                        SubFileName    = item.SubFileName,
                        SubSize        = Info.FormatSize(Convert.ToDouble(item.SubSize))
                    });
                }

                RaisePropertyChanged("OsdbItemsData");
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogExceptionToFile(ex);
                LogWindow.AddMessage(LogType.Error, ex.Message);
            }
            finally
            {
                DownloadOpenSubtitlesGuiData.IsBusy   = false;
                DownloadOpenSubtitlesGuiData.Progress = 0;
            }
        }