Пример #1
0
        public override void ProcessCommand()
        {
            logger.Info("Processing File: {0}", VideoLocalID);


            try
            {
                VideoLocalRepository repVids = new VideoLocalRepository();
                vlocal = repVids.GetByID(VideoLocalID);
                if (vlocal == null)
                {
                    return;
                }

                //now that we have all the has info, we can get the AniDB Info
                ProcessFile_AniDB(vlocal);
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_ProcessFile: {0} - {1}", VideoLocalID, ex.ToString());
                return;
            }

            // TODO update stats for group and series

            // TODO check for TvDB
        }
        private System.IO.Stream InternalGetFile(int userid, string Id)
        {
            int id;

            if (!int.TryParse(Id, out id))
            {
                return(new MemoryStream());
            }
            KodiObject ret = new KodiObject(KodiHelper.NewMediaContainer("Unsort", true));

            if (!ret.Init())
            {
                return(new MemoryStream());
            }
            List <Video> dirs = new List <Video>();
            Video        v    = new Video();

            dirs.Add(v);
            VideoLocalRepository repVids = new VideoLocalRepository();
            VideoLocal           vi      = repVids.GetByID(id);

            if (vi == null)
            {
                return(new MemoryStream());
            }
            KodiHelper.PopulateVideo(v, vi, JMMType.File, userid);
            ret.Childrens          = dirs;
            ret.MediaContainer.Art = v.Art;
            return(ret.GetStream());
        }
        public override void ProcessCommand()
        {
            try
            {
                VideoLocalRepository repVids = new VideoLocalRepository();
                VideoLocal           vlocal  = repVids.GetByID(VideoLocalID);
                if (vlocal == null)
                {
                    return;
                }

                XMLService.Send_FileHash(vlocal);
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_WebCacheSendFileHash: {0} - {1}", VideoLocalID, ex.ToString());
                return;
            }
        }
        private System.IO.Stream InternalGetFile(int userid, string Id, HistoryInfo info)
        {
            int id;

            if (!int.TryParse(Id, out id))
            {
                return(new MemoryStream());
            }
            VideoLocalRepository repVids = new VideoLocalRepository();
            PlexObject           ret     = new PlexObject(PlexHelper.NewMediaContainer(MediaContainerTypes.File, info, true));
            VideoLocal           vi      = repVids.GetByID(id);

            if (vi == null)
            {
                return(new MemoryStream());
            }
            List <Video> dirs = new List <Video>();
            Video        v2   = new Video();

            PlexHelper.PopulateVideo(v2, vi, JMMType.File, userid);
            dirs.Add(v2, info);
            ret.MediaContainer.Childrens = dirs;
            return(ret.GetStream());
        }
Пример #5
0
        public override void ProcessCommand()
        {
            logger.Info("Get AniDB file info: {0}", VideoLocalID);


            try
            {
                AniDB_FileRepository repAniFile = new AniDB_FileRepository();
                VideoLocalRepository repVids    = new VideoLocalRepository();
                vlocal = repVids.GetByID(VideoLocalID);
                if (vlocal == null)
                {
                    return;
                }

                AniDB_File aniFile = repAniFile.GetByHashAndFileSize(vlocal.Hash, vlocal.FileSize);

                /*// get anidb file info from web cache
                 * if (aniFile == null && ServerSettings.WebCache_AniDB_File_Get)
                 * {
                 *      AniDB_FileRequest fr = XMLService.Get_AniDB_File(vlocal.Hash, vlocal.FileSize);
                 *      if (fr != null)
                 *      {
                 *              aniFile = new AniDB_File();
                 *              aniFile.Populate(fr);
                 *
                 *              //overwrite with local file name
                 *              string localFileName = Path.GetFileName(vlocal.FilePath);
                 *              aniFile.FileName = localFileName;
                 *
                 *              repAniFile.Save(aniFile, false);
                 *              aniFile.CreateLanguages();
                 *              aniFile.CreateCrossEpisodes(localFileName);
                 *
                 *              StatsCache.Instance.UpdateUsingAniDBFile(vlocal.Hash);
                 *      }
                 * }*/

                Raw_AniDB_File fileInfo = null;
                if (aniFile == null || ForceAniDB)
                {
                    fileInfo = JMMService.AnidbProcessor.GetFileInfo(vlocal);
                }

                if (fileInfo != null)
                {
                    // save to the database
                    if (aniFile == null)
                    {
                        aniFile = new AniDB_File();
                    }

                    aniFile.Populate(fileInfo);

                    //overwrite with local file name
                    string localFileName = Path.GetFileName(vlocal.FilePath);
                    aniFile.FileName = localFileName;

                    repAniFile.Save(aniFile, false);
                    aniFile.CreateLanguages();
                    aniFile.CreateCrossEpisodes(localFileName);

                    if (!string.IsNullOrEmpty(fileInfo.OtherEpisodesRAW))
                    {
                        string[] epIDs = fileInfo.OtherEpisodesRAW.Split(',');
                        foreach (string epid in epIDs)
                        {
                            int id = 0;
                            if (int.TryParse(epid, out id))
                            {
                                CommandRequest_GetEpisode cmdEp = new CommandRequest_GetEpisode(id);
                                cmdEp.Save();
                            }
                        }
                    }

                    StatsCache.Instance.UpdateUsingAniDBFile(vlocal.Hash);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_GetFile: {0} - {1}", VideoLocalID, ex.ToString());
                return;
            }
        }
Пример #6
0
        private void Process(System.Net.HttpListenerContext obj)
        {
            Stream org = null;

            try
            {
                bool     fname = false;
                string[] dta   = obj.Request.RawUrl.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                if (dta.Length < 4)
                {
                    return;
                }
                string cmd  = dta[0].ToLower();
                string user = dta[1];
                string aw   = dta[2];
                string arg  = dta[3];
                string fullname;
                int    userid    = 0;
                int    autowatch = 0;
                int.TryParse(user, out userid);
                int.TryParse(aw, out autowatch);
                VideoLocal loc = null;
                if (cmd == "videolocal")
                {
                    int sid = 0;
                    int.TryParse(arg, out sid);
                    if (sid == 0)
                    {
                        obj.Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                        obj.Response.StatusDescription = "Stream Id missing.";
                        return;
                    }
                    VideoLocalRepository rep = new VideoLocalRepository();
                    loc = rep.GetByID(sid);
                    if (loc == null)
                    {
                        obj.Response.StatusCode        = (int)HttpStatusCode.NotFound;
                        obj.Response.StatusDescription = "Stream Id not found.";
                        return;
                    }
                    fullname = loc.FullServerPath;
                }
                else if (cmd == "file")
                {
                    fullname = Base64DecodeUrl(arg);
                }
                else
                {
                    obj.Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                    obj.Response.StatusDescription = "Not know command";
                    return;
                }

                bool range = false;

                try
                {
                    if (!File.Exists(fullname))
                    {
                        obj.Response.StatusCode        = (int)HttpStatusCode.NotFound;
                        obj.Response.StatusDescription = "File '" + fullname + "' not found.";
                        return;
                    }
                }
                catch (Exception)
                {
                    obj.Response.StatusCode        = (int)HttpStatusCode.InternalServerError;
                    obj.Response.StatusDescription = "Unable to access File '" + fullname + "'.";
                    return;
                }
                obj.Response.ContentType = GetMime(fullname);
                obj.Response.AddHeader("Accept-Ranges", "bytes");
                obj.Response.AddHeader("X-Plex-Protocol", "1.0");
                if (obj.Request.HttpMethod == "OPTIONS")
                {
                    obj.Response.AddHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT, HEAD");
                    obj.Response.AddHeader("Access-Control-Max-Age", "1209600");
                    obj.Response.AddHeader("Access-Control-Allow-Headers",
                                           "accept, x-plex-token, x-plex-client-identifier, x-plex-username, x-plex-product, x-plex-device, x-plex-platform, x-plex-platform-version, x-plex-version, x-plex-device-name");
                    obj.Response.AddHeader("Cache-Control", "no-cache");
                    obj.Response.ContentType = "text/plain";
                    return;
                }
                string rangevalue = null;
                if (obj.Request.Headers.AllKeys.Contains("Range"))
                {
                    rangevalue = obj.Request.Headers["Range"].Replace("bytes=", string.Empty).Trim();
                }
                if (obj.Request.Headers.AllKeys.Contains("range"))
                {
                    rangevalue = obj.Request.Headers["range"].Replace("bytes=", string.Empty).Trim();
                }

                if (obj.Request.HttpMethod != "HEAD")
                {
                    org = new FileStream(fullname, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    long totalsize = org.Length;
                    long start     = 0;
                    long end       = 0;
                    if (!string.IsNullOrEmpty(rangevalue))
                    {
                        range = true;
                        string[] split = rangevalue.Split('-');
                        if (split.Length == 2)
                        {
                            if (string.IsNullOrEmpty(split[0]) && !string.IsNullOrEmpty(split[1]))
                            {
                                long e = long.Parse(split[1]);
                                start = totalsize - e;
                                end   = totalsize - 1;
                            }
                            else if (!string.IsNullOrEmpty(split[0]) && string.IsNullOrEmpty(split[1]))
                            {
                                start = long.Parse(split[0]);
                                end   = totalsize - 1;
                            }
                            else if (!string.IsNullOrEmpty(split[0]) && !string.IsNullOrEmpty(split[1]))
                            {
                                start = long.Parse(split[0]);
                                end   = long.Parse(split[1]);
                                if (start > totalsize - 1)
                                {
                                    start = totalsize - 1;
                                }
                                if (end > totalsize - 1)
                                {
                                    end = totalsize - 1;
                                }
                            }
                            else
                            {
                                start = 0;
                                end   = totalsize - 1;
                            }
                        }
                    }
                    SubStream outstream;
                    if (range)
                    {
                        obj.Response.StatusCode = (int)HttpStatusCode.PartialContent;
                        obj.Response.AddHeader("Content-Range", "bytes " + start + "-" + end + "/" + totalsize);
                        outstream = new SubStream(org, start, end - start + 1);
                        obj.Response.ContentLength64 = end - start + 1;
                    }
                    else
                    {
                        outstream = new SubStream(org, 0, totalsize);
                        obj.Response.ContentLength64 = totalsize;
                        obj.Response.StatusCode      = (int)HttpStatusCode.OK;
                    }
                    if ((userid != 0) && (loc != null) && autowatch == 1)
                    {
                        outstream.CrossPosition         = (long)((double)totalsize * WatchedThreshold);
                        outstream.CrossPositionCrossed +=
                            (a) =>
                        {
                            Task.Factory.StartNew(() => { loc.ToggleWatchedStatus(true, userid); },
                                                  new CancellationToken(),
                                                  TaskCreationOptions.LongRunning, TaskScheduler.Default);
                        };
                    }
                    obj.Response.SendChunked = false;
                    outstream.CopyTo(obj.Response.OutputStream);
                    obj.Response.OutputStream.Close();
                    outstream.Close();
                }
                else
                {
                    obj.Response.SendChunked     = false;
                    obj.Response.StatusCode      = (int)HttpStatusCode.OK;
                    obj.Response.ContentLength64 = new FileInfo(fullname).Length;
                    obj.Response.KeepAlive       = false;
                    obj.Response.OutputStream.Close();
                }
            }
            catch (HttpListenerException e)
            {
            }
            catch (Exception e)
            {
                logger.Error(e.ToString);
            }
            finally
            {
                if (org != null)
                {
                    org.Close();
                }
                if ((obj != null) && (obj.Response != null) && (obj.Response.OutputStream != null))
                {
                    obj.Response.OutputStream.Close();
                }
            }
        }
        public override void ProcessCommand()
        {
            logger.Info("Reading Media Info for File: {0}", VideoLocalID);


            try
            {
                VideoLocalRepository repVids = new VideoLocalRepository();
                VideoLocal           vlocal  = repVids.GetByID(VideoLocalID);
                if (vlocal == null)
                {
                    logger.Error("Cound not find Video: {0}", VideoLocalID);
                    return;
                }

                if (!File.Exists(vlocal.FullServerPath))
                {
                    logger.Error("Cound not find physical file: {0}", vlocal.FullServerPath);
                    return;
                }

                int nshareID = -1;

                VideoInfoRepository repVidInfo = new VideoInfoRepository();
                VideoInfo           vinfo      = repVidInfo.GetByHash(vlocal.Hash);

                ImportFolderRepository repNS  = new ImportFolderRepository();
                List <ImportFolder>    shares = repNS.GetAll();

                string fileName = vlocal.FullServerPath;
                string filePath = "";
                DataAccessHelper.GetShareAndPath(fileName, shares, ref nshareID, ref filePath);

                FileInfo fi = new FileInfo(fileName);

                if (vinfo == null)
                {
                    vinfo      = new VideoInfo();
                    vinfo.Hash = vlocal.Hash;

                    vinfo.Duration        = 0;
                    vinfo.FileSize        = fi.Length;
                    vinfo.DateTimeUpdated = DateTime.Now;
                    vinfo.FileName        = filePath;

                    vinfo.AudioBitrate    = "";
                    vinfo.AudioCodec      = "";
                    vinfo.VideoBitrate    = "";
                    vinfo.VideoBitDepth   = "";
                    vinfo.VideoCodec      = "";
                    vinfo.VideoFrameRate  = "";
                    vinfo.VideoResolution = "";
                }


                logger.Trace("Getting media info for: {0}", fileName);
                MediaInfoResult mInfo = FileHashHelper.GetMediaInfo(fileName, true);

                vinfo.AudioBitrate = string.IsNullOrEmpty(mInfo.AudioBitrate) ? "" : mInfo.AudioBitrate;
                vinfo.AudioCodec   = string.IsNullOrEmpty(mInfo.AudioCodec) ? "" : mInfo.AudioCodec;

                vinfo.DateTimeUpdated = vlocal.DateTimeUpdated;
                vinfo.Duration        = mInfo.Duration;
                vinfo.FileName        = filePath;
                vinfo.FileSize        = fi.Length;

                vinfo.VideoBitrate    = string.IsNullOrEmpty(mInfo.VideoBitrate) ? "" : mInfo.VideoBitrate;
                vinfo.VideoBitDepth   = string.IsNullOrEmpty(mInfo.VideoBitDepth) ? "" : mInfo.VideoBitDepth;
                vinfo.VideoCodec      = string.IsNullOrEmpty(mInfo.VideoCodec) ? "" : mInfo.VideoCodec;
                vinfo.VideoFrameRate  = string.IsNullOrEmpty(mInfo.VideoFrameRate) ? "" : mInfo.VideoFrameRate;
                vinfo.VideoResolution = string.IsNullOrEmpty(mInfo.VideoResolution) ? "" : mInfo.VideoResolution;
                vinfo.FullInfo        = string.IsNullOrEmpty(mInfo.FullInfo) ? "" : mInfo.FullInfo;
                repVidInfo.Save(vinfo);
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_ReadMediaInfo: {0} - {1}", VideoLocalID, ex.ToString());
                return;
            }
        }