예제 #1
0
 public void ScanCollection(VideoCollection collection)
 {
     switch (collection.Type)
     {
         case VideoCollectionType.show:
             ScanTVCollection(collection);
             break;
         case VideoCollectionType.movie:
             ScanMovieCollection(collection);
             break;
     }
 }
예제 #2
0
파일: Manage.cs 프로젝트: spol/Splice
        private PlexResponse AddCollection(PlexRequest Request)
        {
            if (Request.Headers["Expect"] != null)
            {
                throw new Exception("Received Expect Header");
            }
            if (Request.Method != "POST")
            {
                return XmlResponse.MethodNotAllowed();
            }

            if (Request.PostData["Name"] == null || Request.PostData["Name"].DataAsString.Length == 0 ||
                Request.PostData["Type"] == null)
            {
                // not all required fields provided.
                return XmlResponse.BadRequest();
            }
            else
            {
                VideoCollection Collection = new VideoCollection();

                Collection.Title = Request.PostData["Name"].DataAsString;

                try
                {
                    Collection.Type = (VideoCollectionType)Enum.Parse(typeof(VideoCollectionType), Request.PostData["Type"].DataAsString);
                }
                catch (ArgumentException)
                {
                    return XmlResponse.BadRequest();
                }

                Collection.Locations.AddRange(Request.PostData["Paths"].DataAsString.Split(',').ToList<String>());

                Collection = DataAccess.SaveCollection(Collection);

                // TODO: Handle artwork.
                string SavePath = CacheManager.GetCachePath(Collection.Id, ArtworkType.Fanart);
                FileStream FS = new FileStream(SavePath + "Artwork.jpg", FileMode.Create);
                BinaryWriter Writer = new BinaryWriter(FS);

                Writer.Write(Request.PostData["Artwork"].Data);
                Writer.Close();

                // TODO: Return correct response.
                return XmlResponse.Created();
            }
        }
예제 #3
0
 private void ScanMovieCollection(VideoCollection collection)
 {
     throw new NotImplementedException();
 }
예제 #4
0
        private void ScanTVCollection(VideoCollection Collection)
        {
            foreach (String Path in Collection.Locations)
            {
                DirectoryInfo dirInfo = new DirectoryInfo(Path);

                if (!dirInfo.Exists)
                {
                    throw new IOException(String.Format("Collection location doesn't exist. ({0})", Path));
                }

                DirectoryInfo[] showDirectories = dirInfo.GetDirectories();

                foreach (DirectoryInfo showDir in showDirectories)
                {
                    TVShow show = DataAccess.GetTVShowFromPath(showDir.FullName);
                    if (show == null)
                    {
                        // New Show.
                        TvdbSeries series = LookupShow(showDir.Name);
                        Reporting.Log("Matched: " + series.SeriesName);
                        show = new TVShow();
                        show.Collection = Collection.Id;
                        show.ContentRating = series.ContentRating;
                        show.Duration = Convert.ToInt32(series.Runtime);
                        show.LastUpdated = DateTime.Now.Timestamp();
                        show.LeafCount = 0;
                        show.Location = showDir.FullName;
                        show.AirDate = series.FirstAired;
                        show.Rating = series.Rating;
                        show.Studio = series.Network;
                        show.Summary = series.Overview;
                        show.Title = series.SeriesName;
                        show.ViewedLeafCount = 0;
                        show.TvdbId = series.Id;

                        show = DataAccess.SaveTVShow(show);

                        show.Thumb = CacheManager.SaveArtwork(show.Id, series.PosterPath, ArtworkType.Poster);
                        show.Art = CacheManager.SaveArtwork(show.Id, series.FanartPath, ArtworkType.Fanart);
                        show.Banner = CacheManager.SaveArtwork(show.Id, series.BannerPath, ArtworkType.Banner);

                        // resave with Artwork
                        show = DataAccess.SaveTVShow(show);
                    }
                    else
                    {
                        // TODO: Check for updates/artwork.
                    }

                    // Show already in DB
                    UpdateShow(show);
                }
            }
        }
예제 #5
0
파일: DataAccess.cs 프로젝트: spol/Splice
        public static VideoCollection SaveCollection(VideoCollection Collection)
        {
            SQLiteCommand Cmd = Connection.CreateCommand();

            if (Collection.Id == 0)
            {
                Collection.Id = GetNewGlobalId("collection");

                Cmd.CommandText = "INSERT INTO Collections (id, title, type, art) VALUES (@Id, @Title, @Type, @Art);";
            }
            else
            {
                Cmd.CommandText = "UPDATE Collections SET title = @Title, type = @Type, art = @Art WHERE id = @id";
            }

            Cmd.Parameters.Add(new SQLiteParameter("@Id", DbType.Int32) { Value = Collection.Id });
            Cmd.Parameters.Add(new SQLiteParameter("@Title", DbType.String) { Value = Collection.Title });
            Cmd.Parameters.Add(new SQLiteParameter("@Type", DbType.String) { Value = Collection.Type.ToString() });
            Cmd.Parameters.Add(new SQLiteParameter("@Art", DbType.String) { Value = Collection.Art });

            Cmd.ExecuteNonQuery();

            // TODO: Save Locations

            // Check for existing collections.
            List<String> CurrentLocations = GetVideoCollectionLocations(Collection.Id);
            List<String> Locations = Collection.Locations;

            List<String> CommonLocations = CurrentLocations.Intersect<String>(Locations).ToList<String>();

            foreach (String Location in CommonLocations)
            {
                Locations.Remove(Location);
                CurrentLocations.Remove(Location);
            }

            // Clear no longer present collections.
            foreach (String RemovedLocation in CurrentLocations)
            {
                RemoveLocation(Collection.Id, RemovedLocation);
            }

            // Add new collections.
            foreach (String AddedLocation in Locations)
            {
                AddLocation(Collection.Id, AddedLocation);
            }

            return Collection;
        }
예제 #6
0
파일: DataAccess.cs 프로젝트: spol/Splice
        public static List<VideoCollection> GetVideoCollections()
        {
            List<VideoCollection> Collections = new List<VideoCollection>();

            using (SQLiteCommand cmd = Connection.CreateCommand())
            {
                cmd.CommandText = @"SELECT * FROM Collections";

                SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);

                DataTable CollectionsTable = new DataTable();
                da.Fill(CollectionsTable);

                foreach (DataRow Row in CollectionsTable.Rows)
                {
                    VideoCollection Collection = new VideoCollection(Row);
                    Collection.Locations.AddRange(GetVideoCollectionLocations(Collection.Id));

                    Collections.Add(Collection);
                }
            }
            return Collections;
        }
예제 #7
0
파일: DataAccess.cs 프로젝트: spol/Splice
        public static VideoCollection GetVideoCollection(int CollectionId)
        {
            using (SQLiteCommand cmd = Connection.CreateCommand())
            {
                cmd.CommandText = String.Format(@"SELECT * FROM Collections WHERE id = {0}", CollectionId);

                SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);

                DataTable CollectionsTable = new DataTable();
                da.Fill(CollectionsTable);

                if (CollectionsTable.Rows.Count == 0)
                {
                    return null;
                }
                else
                {
                    VideoCollection Collection = new VideoCollection(CollectionsTable.Rows[0]);
                    Collection.Locations.AddRange(GetVideoCollectionLocations(Collection.Id));
                    return Collection;
                }
            }
        }
예제 #8
0
파일: Service.cs 프로젝트: spol/Splice
        public static List<VideoCollection> GetCollectionsList()
        {
            HttpWebResponse Response = null;
            try
            {
                HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("http://localhost:32400/manage/collections/list");
                Request.KeepAlive = false;
                Response = (HttpWebResponse)Request.GetResponse();

                XmlTextReader XmlReader = new XmlTextReader(Response.GetResponseStream());

                while (XmlReader.NodeType != XmlNodeType.Element && XmlReader.Name != "Collections" && !XmlReader.EOF)
                {
                    XmlReader.Read();
                }

                List<VideoCollection> Collections = new List<VideoCollection>();
                VideoCollection Collection = null;

                if (!XmlReader.EOF && XmlReader.Name == "Collections")
                {
                    while (!XmlReader.EOF)
                    {
                        XmlReader.Read();
                        if (XmlReader.Name == "Collection" && XmlReader.NodeType == XmlNodeType.Element)
                        {
                            Collection = new VideoCollection();
                            Collection.Title = XmlReader["title"];
                            Collection.Id = Convert.ToInt32(XmlReader["collectionId"]);
                            Collection.Art = XmlReader["art"];
                            Collection.Type = (VideoCollectionType)Enum.Parse(typeof(VideoCollectionType), XmlReader["type"]);

                            if (!XmlReader.IsEmptyElement)
                            {

                                XmlReader.Read();
                                while (XmlReader.NodeType != XmlNodeType.EndElement && XmlReader.Name != "Collection" && XmlReader.EOF)
                                {
                                    if (XmlReader.Name == "Location")
                                    {
                                        Collection.Locations.Add(XmlReader["path"]);
                                    }
                                    XmlReader.Read();
                                }
                            }
                            Collections.Add(Collection);
                            Collection = null;
                        }

                        if (XmlReader.Name == "Collections" && XmlReader.NodeType == XmlNodeType.EndElement)
                        {
                            break;
                        }
                    }
                    Response.Close();
                    return Collections;
                }

                throw new Exception("Collections element not found.");
            }
            catch (WebException)
            {
                // TODO: Handle unable to connect.
            }
            finally
            {
                if (Response != null)
                {
                    Response.Close();
                }
            }
            return new List<VideoCollection>();
        }