Пример #1
0
        private async void GetVideoSourceData()
        {
            if (_videoSourceData == null)
            {
                _videoSourceData = new VideoSourceData();
            }

            if (_selecVideo == null || _selecVideo.VideoId == null)
            {
                return;
            }

            GetDanmuData();
            var url = AcFunAPI.GetVideoSrcUrl(_selecVideo.VideoId);
            await _videoSourceData.GetData(url);

            _DicOfvideoSource = _videoSourceData.ListofVideoSourceData;
            if (_DicOfvideoSource == null || _DicOfvideoSource.Count == 0)
            {
                //todo error
                MSGSHOW("视频地址解析失败\r\nSRC:" + _selecVideo.SourceType + "--" + _selecVideo.SourceId + "\r\nACID:" + _selecVideo.VideoId);
            }
            AddDescription(_DicOfvideoSource);
            Player.Play();
        }
Пример #2
0
        private async Task <bool> InitFunc()
        {
            _detailData = new DetailData();
            var url = AcFunAPI.GetContentUrl(_SeleCContent.ContentId);
            await _detailData.GetData(url);

            _SeleCContent    = _detailData.ListOfACContent[0];
            _videoSourceData = new VideoSourceData();
            //url=AcFunAPI.GetVideoSrcUrl(_SeleCContent.DetailVideos[0].)
            //url=AcFunAPI.GetVideoSrcUrl(_SeleCContent.DetailVideos[0].)
            //await _videoSourceData.GetData()
            return(true);
        }
        private void AddEncodingJob(VideoSourceData sourceData, string sourceDirectoryPath, string destinationDirectoryPath)
        {
            // Only add encoding job is file is ready.
            if (CheckFileReady(sourceData.FullPath))
            {
                EncodingJob encodingJob = new EncodingJob()
                {
                    Name                = sourceData.FileName,
                    SourceFullPath      = sourceData.FullPath,
                    DestinationFullPath = sourceData.FullPath.Replace(sourceDirectoryPath, destinationDirectoryPath)
                };

                EncodingJobs.AddEncodingJob(encodingJob);
            }
        }
Пример #4
0
        private async void GetUrl(VideoDetail content)
        {
            var vsd = new VideoSourceData();
            var url = AcFunAPI.GetVideoSrcUrl(content.VideoId);
            await vsd.GetData(url);

            if (vsd.ListofVideoSourceData == null || vsd.ListofVideoSourceData.Count == 0)
            {
                MSGSHOW("下载失败:\r\n  获取视频地址失败!");
            }

            if (vsd.ListofVideoSourceData.Count > 1)
            {
                bool hasSuper = false;

                foreach (var key in vsd.ListofVideoSourceData.Keys)
                {
                    if (key == "超清")
                    {
                        hasSuper = true;
                    }
                }
                if (hasSuper)
                {
                    DoBackgroundDownload(content, vsd.ListofVideoSourceData["超清"]);
                }
                else
                {
                    DoBackgroundDownload(content, vsd.ListofVideoSourceData["高清"]);
                }

                // MSGSHOW(vsd.ListofVideoSourceData);
            }
            else
            {
                foreach (var dic in vsd.ListofVideoSourceData)
                {
                    DoBackgroundDownload(content,
                                         dic.Value);
                    break;
                }
            }
        }
        protected override void ThreadLoop(EncodingJobs encodingJobs, object[] threadObjects)
        {
            Dictionary <string, SearchDirectory> searchDirectories = (Dictionary <string, SearchDirectory>)threadObjects[0];

            while (_shutdown == false)
            {
                try
                {
                    Status = AFWorkerThreadStatus.PROCESSING;
                    if (_directoryUpdate)
                    {
                        UpdateSearchDirectories(searchDirectories);
                    }

                    bool bFoundEncodingJob = false;
                    foreach (KeyValuePair <string, SearchDirectory> entry in searchDirectories)
                    {
                        if (Directory.Exists(entry.Value.Source))
                        {
                            // TV Show structured directories
                            if (entry.Value.TVShowStructure)
                            {
                                List <VideoSourceData> newEncodingJobs = new List <VideoSourceData>();
                                lock (_showSourceFileLock)
                                {
                                    _showSourceFiles[entry.Key] = new List <ShowSourceData>();
                                    List <string> sourceShows      = Directory.GetDirectories(entry.Value.Source).ToList();
                                    List <string> destinationFiles = Directory.GetFiles(entry.Value.Destination, "*.*", SearchOption.AllDirectories).ToList()
                                                                     .Where(file => Config.ServerSettings.VideoFileExtensions.Any(file.ToLower().EndsWith)).Select(file => file = Path.GetFileNameWithoutExtension(file)).ToList();
                                    // Show
                                    foreach (string showPath in sourceShows)
                                    {
                                        string         showName = showPath.Replace(entry.Value.Source, "").RemoveLeadingSlash();
                                        ShowSourceData showData = new ShowSourceData(showName);
                                        List <string>  seasons  = Directory.GetDirectories(showPath).ToList();
                                        // Season
                                        foreach (string seasonPath in seasons)
                                        {
                                            string           season     = seasonPath.Replace(showPath, "").RemoveLeadingSlash();
                                            SeasonSourceData seasonData = new SeasonSourceData(season);
                                            List <string>    episodes   = Directory.GetFiles(seasonPath, "*.*", SearchOption.AllDirectories)
                                                                          .Where(file => Config.ServerSettings.VideoFileExtensions.Any(file.ToLower().EndsWith)).ToList();
                                            // Episode
                                            foreach (string episodePath in episodes)
                                            {
                                                string          episode     = episodePath.Replace(seasonPath, "").RemoveLeadingSlash();
                                                VideoSourceData episodeData = new VideoSourceData()
                                                {
                                                    FileName = episode,
                                                    FullPath = episodePath,
                                                    Encoded  = destinationFiles.Contains(Path.GetFileNameWithoutExtension(episodePath))
                                                };
                                                seasonData.Episodes.Add(episodeData);
                                                if (episodeData.Encoded == false && entry.Value.Automated == true)
                                                {
                                                    bFoundEncodingJob = true;
                                                    newEncodingJobs.Add(episodeData);
                                                }
                                            }
                                            showData.Seasons.Add(seasonData);
                                        }
                                        _showSourceFiles[entry.Key].Add(showData);
                                    }
                                }
                                newEncodingJobs.ForEach(x => AddEncodingJob(x, entry.Value.Source, entry.Value.Destination));
                            }
                            else
                            {
                                List <VideoSourceData> newEncodingJobs = new List <VideoSourceData>();
                                lock (_videoSourceFileLock)
                                {
                                    _videoSourceFiles[entry.Key] = new List <VideoSourceData>();
                                    List <string> sourceFiles = Directory.GetFiles(entry.Value.Source, "*.*", SearchOption.AllDirectories)
                                                                .Where(file => Config.ServerSettings.VideoFileExtensions.Any(file.ToLower().EndsWith)).ToList();
                                    List <string> destinationFiles = Directory.GetFiles(entry.Value.Destination, "*.*", SearchOption.AllDirectories)
                                                                     .Where(file => Config.ServerSettings.VideoFileExtensions.Any(file.ToLower().EndsWith)).Select(file => file = Path.GetFileNameWithoutExtension(file)).ToList();
                                    foreach (string sourceFile in sourceFiles)
                                    {
                                        // Handles files in subdirectories
                                        string filename = sourceFile.Replace(entry.Value.Source, "").RemoveLeadingSlash();

                                        VideoSourceData sourceData = new VideoSourceData()
                                        {
                                            FileName = filename,
                                            FullPath = sourceFile,
                                            Encoded  = destinationFiles.Contains(Path.GetFileNameWithoutExtension(sourceFile))
                                        };
                                        _videoSourceFiles[entry.Key].Add(sourceData);

                                        // If the source file has not been encoded already and it's an automated directory, add to encoding job list
                                        if (sourceData.Encoded == false && entry.Value.Automated == true)
                                        {
                                            bFoundEncodingJob = true;
                                            newEncodingJobs.Add(sourceData);
                                        }
                                    }
                                }

                                newEncodingJobs.ForEach(x => AddEncodingJob(x, entry.Value.Source, entry.Value.Destination));
                            }
                        }
                        else
                        {
                            // TODO Logging
                            Console.WriteLine($"{entry.Value.Source} does not exist.");
                        }
                    }

                    if (bFoundEncodingJob == false)
                    {
                        Sleep();
                    }
                }
                catch (Exception ex)
                {
                    // TODO Logging
                    Debug.WriteLine($"[{ThreadName}] ERROR: {ex.Message}");
                }
            }
        }
Пример #6
0
 /// <summary>Copy Constructor </summary>
 /// <param name="videoSourceData"></param>
 public VideoSourceData(VideoSourceData videoSourceData)
 {
     FileName = videoSourceData.FileName;
     FullPath = videoSourceData.FullPath;
     Encoded  = videoSourceData.Encoded;
 }