File size: 5,672 Bytes
e26fba6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace MovieTube.Client.Scraper
{
public class MoviePage
{
public MoviePage()
{
Videos = new List<Movie>();
Links = new List<PagingLink>();
}
public List<Movie> Videos { get; set; }
public List<PagingLink> Links { get; set; }
}
public class Movie
{
private List<MovieLink> links;
public Movie()
{
RelatedVideos = new List<Movie>();
}
public string Url { get; set; }
public string Title { get; set; }
public string ImageUrl { get; set; }
public TimeSpan Duration { get; set; }
public string PlayUrl { get; set; }
public int Quality { get; set; }
public List<Movie> RelatedVideos { get; set; }
public List<MovieLink> Links {
get
{
if(links == null)
links = MovieTube.Viewer.Data.ClientDataService.Single.ReadMovieLinks(this);
return links;
}
}
public bool FullyLoaded { get; set; }
public int ID { get; set; }
public string Name { get; set; }
public System.DateTime ReleaseDate { get; set; }
public int ReleaseYear { get { return ReleaseDate.Year; } }
public string LanguageCode { get; set; }
public string LanguageText
{
get
{
try
{
return Language.Languages.Find(x => x.Id == LanguageCode).Name;
}
catch { }
return "Unknown";
}
}
public string Description { get; set; }
public System.DateTime CreatedDate { get; set; }
public Nullable<System.DateTime> ModifiedDate { get; set; }
public int Version { get; set; }
// public int VersionChange { get; set; }
public string UniqueID { get; set; }
}
public class MovieLink : IComparable<MovieLink>
{
public event EventHandler<EventArgs> ScrappingStatusChanged;
private LinkScrapState scrapState;
private string downloadUrl;
public int ID { get; set; }
public int MovieID { get; set; }
public string SiteTitle { get; set; }
public string DownloadSiteID { get; set; }
public string PageUrl { get; set; }
public string PageSiteID { get; set; }
public string DowloadUrl
{
get { return this.downloadUrl; }
set
{
Provider = VideoScraperBase.GetScraper(value);
if (Provider == null)
throw new Exception("Provider is not available");
this.downloadUrl = value;
}
}
public string LinkTitle { get; set; }
public string PlayUrl { get; set; }
public virtual Movie Parent { get; set; }
public LinkScrapState ScrapState
{
get
{
if (scrapState == LinkScrapState.FullyLoaded && RetrievedTime.AddHours(2) < DateTime.Now)
scrapState = LinkScrapState.Idle;
return scrapState;
}
set
{
if (this.scrapState != value)
{
this.scrapState = value;
if (ScrappingStatusChanged != null)
ScrappingStatusChanged(this, new EventArgs());
}
}
}
public double LastPosition { get; set; }
public VideoScraperBase Provider { get; private set; }
public int CompareTo(MovieLink other)
{
var r = 0;
if ((int)this.Provider.Rank > 1 && (int)other.Provider.Rank > 1)
{
r = other.Version.CompareTo(this.Version);
if (r != 0)
return r;
}
r = this.Provider.Rank.CompareTo(other.Provider.Rank);
if (r != 0)
return r;
return this.ID.CompareTo(other.ID);
}
public int Version { get; set; }
public DateTime RetrievedTime { get; set; }
}
public enum LinkScrapState
{
Idle,
FullyLoaded,
Scraping,
VideoDoesNotExists
}
public class PagingLink
{
public string Url { get; set; }
public string Text { get; set; }
public bool IsSelected { get; set; }
}
public enum VideoSortby
{
Relevance,
Date,
Rating
}
public enum VideoPeriod
{
Anytime,
Today,
ThisWeek,
ThisMonth
}
public enum VideoDuration
{
All,
Short,
Medium,
Long
}
public interface IScraperServiceCallback
{
void OnScrapVideoCompleted(MoviePage page);
void OnScrapVideoDetailsCompleted(Movie video);
void OnScrapError(Exception ex);
}
public class SearchParameters
{
public string Url { get; set; }
public string Query { get; set; }
public VideoSortby SortBy { get; set; }
public VideoPeriod Period { get; set; }
public VideoDuration Duration { get; set; }
public int Year { get; set; }
public string Language { get; set; }
}
}
|