/// <summary> /// Scans a library folder and returns a list of all audiobooks found. /// </summary> /// <param name="libraryPath">path of the library folder</param> /// <returns>list of all found audiobooks</returns> public ICollection <Audiobook> ScanLibrary(string libraryPath) { if (!Directory.Exists(libraryPath)) { throw new FileNotFoundException("library folder does not exist"); } ICollection <string> audiobookFolders = GetAudiobookFolders(libraryPath); ICollection <Audiobook> audiobooks = new List <Audiobook>(); foreach (string path in audiobookFolders) { ICollection <Chapter> chapters = ScanAudiobookFolder(path); Audiobook audiobook = AudiobookManager.Instance.CreateAudiobook(); audiobook.SetChapters(chapters); audiobook.Metadata.Path = path; audiobook.Metadata.Title = Path.GetFileNameWithoutExtension(audiobook.Metadata.Path); UpdateAudiobookInfo(audiobook); audiobooks.Add(audiobook); } return(audiobooks); }
public async Task GetAudiobook(Audiobook audiobook, Stream stream) { logger.Log("Получаем идентификатор аудиокниги для скачивания."); // Получаем идентификатор книги, по которому будет произведено обращение на скачивание int id = await GetAudiobookId(audiobook); logger.Log($"Формируем ссылку для загрузки аудиокниги: {audiobook.Title}."); logger.Log($"Полученная ссылка: {$"{baseUrl}/download/{id}"}."); // Обновим состояние прокси т.к возможно были изменения в конфиг файле RefreshProxyState(); // Формируем запрос на скачивание, если необходимо используем скачивание через proxy сервер HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"{baseUrl}/download/{id}"); if (isUseProxy) { request.Proxy = new WebProxy(proxy.Ip, proxy.Port); } logger.Log($"Скачиваем аудиокнигу {audiobook.Title}."); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); // Скачиваем аудиокнигу await responseStream.CopyToAsync(stream); }
public ActionResult DeleteConfirmed(int id) { Audiobook audiobook = db.Audiobooks.Find(id); db.Audiobooks.Remove(audiobook); db.SaveChanges(); return(RedirectToAction("Index")); }
public void SwitchToEditLibraryPage(Audiobook audiobook) { EditLibraryViewModel editLibraryViewModel = ViewModelLocator.Instance.EditLibraryViewModel; editLibraryViewModel.Audiobook = audiobook; MainWindow.SwitchPage(new PageItem(MainWindow.btnEditLibrary)); }
public async Task SaveUploadAudiobook(Audiobook audiobook) { var context = new Context(); if (!IsUploadAudiobook(audiobook)) { context.UploadAudiobook.Add(new UploadAudiobook { Audiobook = audiobook }); await context.SaveChangesAsync(); } }
public ActionResult Edit([Bind(Include = "Id,Title,Description,Price,Cost,Running_time,Abridged,Language,Release_date,Image,Author_Id,Genre_Id,Narrator_Id,Publisher_Id")] Audiobook audiobook) { if (ModelState.IsValid) { db.Entry(audiobook).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Author_Id = new SelectList(db.Authors, "Id", "Author1", audiobook.Author_Id); ViewBag.Genre_Id = new SelectList(db.Genres, "Id", "Genre1", audiobook.Genre_Id); ViewBag.Narrator_Id = new SelectList(db.Narrators, "Id", "Narrator1", audiobook.Narrator_Id); ViewBag.Publisher_Id = new SelectList(db.Publishers, "Id", "Publisher1", audiobook.Publisher_Id); return(View(audiobook)); }
// GET: Audiobooks/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Audiobook audiobook = db.Audiobooks.Find(id); if (audiobook == null) { return(HttpNotFound()); } return(View(audiobook)); }
public async Task <int> GetAudiobookId(Audiobook audiobook) { // Получаем html разметку сайта Abooks c определенной аудиокнигой string html = await GetHtml(audiobook.Url); // Получаем объектно - ориентированное представление html документа var parseResult = htmlParser.Parse(html); // Получаем значение идентификатора указанной книги string uri = parseResult.GetElementsByClassName("button button_js button_orange")[0].GetAttribute("href"); Int32.TryParse(HttpUtility.ParseQueryString(new Uri(uri).Query).Get("book_id"), out int id); return(id); }
public Guid GetOwnerRecid(Audiobook audiobook) { using (var context = new Context()) { if (context.UploadAudiofile.Count() > 0) { var dbItem = context.UploadAudiofile.Select(m => m.File).Where(m => m.AudiobookUrl == audiobook.Url).FirstOrDefault(); if (dbItem != null) { return(Guid.Parse(dbItem.OwnerRecid)); } } return(Guid.NewGuid()); } }
public bool IsDownloadAudiobook(Audiobook audiobook) { using (var context = new Context()) { if (context.DownloadAudiobook.Count() > 0) { var dbItem = context.DownloadAudiobook.Select(m => m.Audiobook).Where(m => m.Title == audiobook.Title && m.Url == audiobook.Url ).FirstOrDefault(); return(dbItem != null); } return(false); } }
// GET: Audiobooks/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Audiobook audiobook = db.Audiobooks.Find(id); if (audiobook == null) { return(HttpNotFound()); } ViewBag.Author_Id = new SelectList(db.Authors, "Id", "Author1", audiobook.Author_Id); ViewBag.Genre_Id = new SelectList(db.Genres, "Id", "Genre1", audiobook.Genre_Id); ViewBag.Narrator_Id = new SelectList(db.Narrators, "Id", "Narrator1", audiobook.Narrator_Id); ViewBag.Publisher_Id = new SelectList(db.Publishers, "Id", "Publisher1", audiobook.Publisher_Id); return(View(audiobook)); }
public ActionResult AddAudiobook(int?AudiobookId, bool?confirmation) { Audiobook audiobook; if (AudiobookId.HasValue) { ViewBag.EditMode = true; audiobook = db.Audiobooks.Find(AudiobookId); } else { ViewBag.EditMode = false; audiobook = new Audiobook(); } var result = new EditAudiobookViewModel(); result.Categories = db.Categories.ToList(); result.Audiobook = audiobook; result.Confirmation = confirmation; return(View(result)); }
public bool CreateAudiobook(AudiobookCreate model) { var audiobookToCreate = new Audiobook() { Title = model.Title, SeriesTitle = model.SeriesTitle, AuthorId = model.AuthorId, Isbn = model.Isbn, Rating = model.Rating, Genre = model.Genre, Language = model.Language, Publisher = model.Publisher, NarratorName = model.NarratorName, AudioFormat = model.AudioFormat, IsAbridged = model.IsAbridged }; using (var ctx = new ApplicationDbContext()) { ctx.Audiobooks.Add(audiobookToCreate); return(ctx.SaveChanges() == 1); } }
protected override void UpdateAudiobookInfo(Audiobook audiobook) { audiobook.Metadata.Title = "Makker " + audiobook.Metadata.Title; }
/// <summary> /// Change relevant information of the audiobook. Path and title are set /// by default. Title is the name of the audio file without extension. /// </summary> /// <param name="audiobook">audiobook to be modified</param> protected abstract void UpdateAudiobookInfo(Audiobook audiobook);
public static void OpenAudiobookEpisodesPage(Audiobook audiobook) { Navigate("/Pages/Browse/Audiobooks/AudiobookEpisodesPage.xaml?databaseID={0}&groupID={1}", audiobook.Database.ID, audiobook.ID); }
private List <IOffer> ParseOffers( IElement parent, List <Category> categories, List <Currency> currencies, int localDeliveryCost) { List <IOffer> offers = new List <IOffer>(); IOffer offer; foreach (var off in parent.QuerySelectorAll("offer")) { switch (off.GetAttribute("type")) { case "vendor.model": offer = new VendorModel(); (offer as VendorModel).TypePrefix = off.QuerySelector("typePrefix").TextContent; (offer as VendorModel).Vendor = off.QuerySelector("vendor").TextContent; (offer as VendorModel).VendorCode = off.QuerySelector("vendorCode").TextContent; (offer as VendorModel).Model = off.QuerySelector("model").TextContent; (offer as VendorModel).ManufacturerWarranty = bool.Parse(off.QuerySelector("manufacturer_warranty").TextContent); (offer as VendorModel).CountryOfOrigin = off.QuerySelector("country_of_origin").TextContent; break; case "book": offer = new Book(); (offer as Book).Author = off.QuerySelector("author").TextContent; (offer as Book).Name = off.QuerySelector("name").TextContent; (offer as Book).Publisher = off.QuerySelector("publisher").TextContent; (offer as Book).Series = off.QuerySelector("series").TextContent; (offer as Book).Year = Int32.Parse(off.QuerySelector("year").TextContent); (offer as Book).ISBN = off.QuerySelector("ISBN").TextContent; (offer as Book).Volume = Int32.Parse(off.QuerySelector("volume").TextContent); (offer as Book).Part = Int32.Parse(off.QuerySelector("part").TextContent); (offer as Book).Language = off.QuerySelector("language").TextContent; (offer as Book).Binding = off.QuerySelector("binding").TextContent; (offer as Book).PageExtent = Int32.Parse(off.QuerySelector("page_extent").TextContent); (offer as Book).Delivery = bool.Parse(off.QuerySelector("delivery").TextContent); (offer as Book).LocalDeliveryCost = Int32.Parse(off.QuerySelector("local_delivery_cost")?.TextContent); break; case "audiobook": offer = new Audiobook(); (offer as Audiobook).Author = off.QuerySelector("author").TextContent; (offer as Audiobook).Name = off.QuerySelector("name").TextContent; (offer as Audiobook).Publisher = off.QuerySelector("publisher").TextContent; (offer as Audiobook).Year = Int32.Parse(off.QuerySelector("year").TextContent); (offer as Audiobook).ISBN = off.QuerySelector("ISBN").TextContent; (offer as Audiobook).Language = off.QuerySelector("language").TextContent; (offer as Audiobook).PerformedBy = off.QuerySelector("performed_by").TextContent; (offer as Audiobook).PerformanceType = off.QuerySelector("performance_type").TextContent; (offer as Audiobook).Storage = off.QuerySelector("storage").TextContent; (offer as Audiobook).Format = off.QuerySelector("format").TextContent; // Formats for parse string[] formats = new string[] { "h'h'm'm's's'", "m'm's's'" }; (offer as Audiobook).RecordingLength = TimeSpan.ParseExact(off.QuerySelector("recording_length").TextContent, formats, CultureInfo.InvariantCulture); break; case "artist.title": offer = new ArtistTitle(); (offer as ArtistTitle).Title = off.QuerySelector("title").TextContent; (offer as ArtistTitle).Year = Int32.Parse(off.QuerySelector("year").TextContent); (offer as ArtistTitle).Media = off.QuerySelector("media").TextContent; (offer as ArtistTitle).Artist = off.QuerySelector("artist")?.TextContent; (offer as ArtistTitle).Starring = off.QuerySelector("starring")?.TextContent?.Split(','); (offer as ArtistTitle).Director = off.QuerySelector("director")?.TextContent; (offer as ArtistTitle).OriginalName = off.QuerySelector("originalName")?.TextContent; (offer as ArtistTitle).Country = off.QuerySelector("country")?.TextContent; break; case "tour": offer = new Tour(); (offer as Tour).WorldRegion = off.QuerySelector("worldRegion").TextContent; (offer as Tour).Country = off.QuerySelector("country").TextContent; (offer as Tour).Region = off.QuerySelector("region").TextContent; (offer as Tour).Days = Int32.Parse(off.QuerySelector("days").TextContent); (offer as Tour).DataTourStart = DateTime.Parse(off.QuerySelectorAll("dataTour")[0].TextContent, CultureInfo.InvariantCulture); (offer as Tour).DataTourEnd = DateTime.Parse(off.QuerySelectorAll("dataTour")[1].TextContent, CultureInfo.InvariantCulture); (offer as Tour).Name = off.QuerySelector("name").TextContent; (offer as Tour).HotelStars = Int32.Parse(off.QuerySelector("hotel_stars").TextContent.Replace("*", string.Empty)); (offer as Tour).Room = off.QuerySelector("room").TextContent; (offer as Tour).Meal = off.QuerySelector("meal").TextContent; (offer as Tour).Included = off.QuerySelector("included").TextContent.Split(','); (offer as Tour).Transport = off.QuerySelector("transport").TextContent; break; case "event-ticket": offer = new EventTicket(); (offer as EventTicket).Name = off.QuerySelector("name").TextContent; (offer as EventTicket).Place = off.QuerySelector("place").TextContent; (offer as EventTicket).Hall = off.QuerySelector("hall").TextContent; (offer as EventTicket).HallPart = off.QuerySelector("hall_part").TextContent; (offer as EventTicket).Date = DateTime.Parse(off.QuerySelector("date").TextContent, CultureInfo.InvariantCulture); (offer as EventTicket).IsPremiere = Convert.ToBoolean(Int32.Parse(off.QuerySelector("is_premiere").TextContent)); (offer as EventTicket).IsPremiere = Convert.ToBoolean(Int32.Parse(off.QuerySelector("is_kids").TextContent)); break; default: offer = new BaseOffer(); break; } ParseBaseOffer(off, offer, categories, currencies, localDeliveryCost); offers.Add(offer); } return(offers); }
public void AddAudioBook(AudioBookInputModel book) { if (!CheckIsbn(book.Isbns)) { CheckAuthor(book.Authors); CheckNarrator(book.Narrators); var audio = new Audiobook { Price = book.Price, Name = book.Name, Image = book.Image, Description = book.Description, Length = book.Length, Size = book.Size, ReleaseDate = book.ReleaseDate, Publisher = book.Publisher, Isbn = book.Isbns, }; audio.BookAgeGroups = new List <BookAgeGroup>(); foreach (var ageGroup in book.AgeGroups) { audio.BookAgeGroups.Add(new BookAgeGroup { Book = audio, AgeGroup = ageGroup }); } ; audio.BookAuthors = new List <BookAuthor>(); foreach (var author in book.Authors) { audio.BookAuthors.Add(new BookAuthor { Book = audio, Author = author }); } ; audio.BookGenres = new List <BookGenre>(); foreach (var genre in book.Genres) { audio.BookGenres.Add(new BookGenre { Book = audio, Genre = genre }); } ; audio.BookLanguages = new List <BookLanguage>(); foreach (var language in book.Languages) { audio.BookLanguages.Add(new BookLanguage { Book = audio, Language = language }); } ; audio.AudiobookNarrators = new List <AudiobookNarrator>(); foreach (var narrator in book.Narrators) { audio.AudiobookNarrators.Add(new AudiobookNarrator { Book = audio, Narrator = narrator }); } ; _db.AudioBooks.AddRange(audio); _db.SaveChanges(); } }
private void EditSelected(Audiobook audiobook) { ViewModelLocator.Instance.MainViewModel.SwitchToEditLibraryPage(audiobook); }
protected override void UpdateAudiobookInfo(Audiobook audiobook) { // NOP }