public bool AddFavoriteVideo(VideoInfo foVideo, string titleFromUtil, string siteName)
        {
			DatabaseUtility.RemoveInvalidChars(ref siteName);
            string title = string.IsNullOrEmpty(titleFromUtil) ? "" : DatabaseUtility.RemoveInvalidChars(titleFromUtil);
            string desc = string.IsNullOrEmpty(foVideo.Description) ? "" : DatabaseUtility.RemoveInvalidChars(foVideo.Description);
            string thumb = string.IsNullOrEmpty(foVideo.Thumb) ? "" : DatabaseUtility.RemoveInvalidChars(foVideo.Thumb);
            string url = string.IsNullOrEmpty(foVideo.VideoUrl) ? "" : DatabaseUtility.RemoveInvalidChars(foVideo.VideoUrl);
            string length = string.IsNullOrEmpty(foVideo.Length) ? "" : DatabaseUtility.RemoveInvalidChars(foVideo.Length);
            string airdate = string.IsNullOrEmpty(foVideo.Airdate) ? "" : DatabaseUtility.RemoveInvalidChars(foVideo.Airdate);
            string other = DatabaseUtility.RemoveInvalidChars(foVideo.GetOtherAsString());

            Log.Instance.Info("inserting favorite on site '{4}' with title: '{0}', desc: '{1}', thumb: '{2}', url: '{3}'", title, desc, thumb, url, siteName);

            //check if the video is already in the favorite list
            string lsSQL = string.Format("select VDO_ID from FAVORITE_VIDEOS where VDO_SITE_ID='{0}' AND VDO_URL='{1}' and VDO_OTHER_NFO='{2}'", siteName, url, other);
            if (m_db.Execute(lsSQL).Rows.Count > 0)
            {
                Log.Instance.Info("Favorite Video '{0}' already in database", title);
                return false;
            }

            lsSQL =
                string.Format(
                    "insert into FAVORITE_VIDEOS(VDO_NM,VDO_URL,VDO_DESC,VDO_TAGS,VDO_LENGTH,VDO_OTHER_NFO,VDO_IMG_URL,VDO_SITE_ID)VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')",
                    title, url, desc, airdate, length, other, thumb, siteName);
            m_db.Execute(lsSQL);
            if (m_db.ChangedRows() > 0)
            {
                Log.Instance.Info("Favorite '{0}' inserted successfully into database", foVideo.Title);
                return true;
            }
            else
            {
                Log.Instance.Warn("Favorite '{0}' failed to insert into database", foVideo.Title);
                return false;
            }
        }
Example #2
0
 public override string GetVideoUrl(VideoInfo video)
 {
     bool isArchive = video.GetOtherAsString() == cArchiveCategory;
     string archiveUrl = "";
     if (isArchive)
     {
         Regex archiveRgx = new Regex(@".*(?<prefix>\d-)(?<id>\d*)");
         Match archiveMatch = archiveRgx.Match(video.VideoUrl);
         if (archiveMatch.Success)
         {
             Regex mediakantaIdRegex = new Regex(@"""mediakantaId"":""(?<id>[^""]*)");
             string id = archiveMatch.Groups["id"].Value;
             Match mediakantaIdMatch = mediakantaIdRegex.Match(GetWebData(string.Format(cUrlArchiveEmbedFormat, id, id)));
             if (mediakantaIdMatch.Success)
             {
                 archiveUrl = archiveMatch.Groups["prefix"].Value + mediakantaIdMatch.Groups["id"].Value;
             }
         }
     }
     string url = string.Format(cUrlHdsFormat, isArchive ? archiveUrl : video.VideoUrl);
     JObject json = GetWebData<JObject>(url, cache: false);
     JToken hdsStream = json["data"]["media"]["HDS"].FirstOrDefault(h => h["subtitles"] != null && h["subtitles"].Count() > 0);
     if (hdsStream == null)
     {
         hdsStream = json["data"]["media"]["HDS"].First;
     }
     else
     {
         JToken subtitle = hdsStream["subtitles"].FirstOrDefault(s => s["lang"].Value<string>() == ApiLanguage);
         if (subtitle == null) subtitle = hdsStream["subtitles"].FirstOrDefault(s => s["lang"].Value<string>() == ApiOtherLanguage);
         if (subtitle != null && subtitle["uri"] != null) video.SubtitleUrl = subtitle["uri"].Value<string>();
     }
     string data = hdsStream["url"].Value<string>();
     byte[] bytes = Convert.FromBase64String(data);
     RijndaelManaged rijndael = new RijndaelManaged();
     byte[] iv = new byte[16];
     Array.Copy(bytes, iv, 16);
     rijndael.IV = iv;
     rijndael.Key = Encoding.ASCII.GetBytes("yjuap4n5ok9wzg43");
     rijndael.Mode = CipherMode.CFB;
     rijndael.Padding = PaddingMode.Zeros;
     ICryptoTransform decryptor = rijndael.CreateDecryptor(rijndael.Key, rijndael.IV);
     int padLen = 16 - bytes.Length % 16;
     byte[] newbytes = new byte[bytes.Length - 16 + padLen];
     Array.Copy(bytes, 16, newbytes, 0, bytes.Length - 16);
     Array.Clear(newbytes, newbytes.Length - padLen, padLen);
     string result = null;
     using (MemoryStream msDecrypt = new MemoryStream(newbytes))
     {
         using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
         {
             using (StreamReader srDecrypt = new StreamReader(csDecrypt))
             {
                 result = srDecrypt.ReadToEnd();
             }
         }
     }
     Regex r;
     if (video.GetOtherAsString() == cApiContentTypeTvLive)
         r = new Regex(@"(?<url>.*\.f4m)");
     else
         r = new Regex(@"(?<url>.*hmac=[a-z0-9]*)");
     Match m = r.Match(result);
     if (m.Success)
     {
         result = m.Groups["url"].Value;
     }
     if (video.GetOtherAsString() == cApiContentTypeTvLive)
     {
         result += "?g=" + HelperUtils.GetRandomChars(12) + "&hdcore=3.3.0&plugin=flowplayer-3.3.0.0";
         MPUrlSourceFilter.AfhsManifestUrl f4mUrl = new MPUrlSourceFilter.AfhsManifestUrl(result)
         {
             LiveStream = true
         };
         result = f4mUrl.ToString();
     }
     else
     {
         result += "&g=" + HelperUtils.GetRandomChars(12) + "&hdcore=3.3.0&plugin=flowplayer-3.3.0.0";
     }
     return result;
 }
 public override ContextMenuExecutionResult ExecuteContextMenuEntry(Category selectedCategory, VideoInfo selectedItem, ContextMenuEntry choice)
 {
     if (selectedItem != null && choice.DisplayText.Contains("watchlist"))
     {
         ContextMenuExecutionResult result = new ContextMenuExecutionResult();
         string other = selectedItem.GetOtherAsString();
         JObject json = (JObject)JsonConvert.DeserializeObject(other);
         bool isSaved = json["saved"].Value<bool>();
         string guid = json["guid"].Value<string>();
         bool success;
         if (isSaved)
         {
             success = UnsaveVideo(guid);
         }
         else
         {
             success = SaveVideo(guid);
         }
         result.RefreshCurrentItems = success;
         result.ExecutionResultMessage = (success ? "OK: " : "ERROR: ") + choice.DisplayText + " (" + selectedItem.Title + ")";
         return result;
     }
     return base.ExecuteContextMenuEntry(selectedCategory, selectedItem, choice);
 }
 public override List<ContextMenuEntry> GetContextMenuEntries(Category selectedCategory, VideoInfo selectedItem)
 {
     List<ContextMenuEntry> entries = new List<ContextMenuEntry>();
     if (selectedItem != null)
     {
         ContextMenuEntry entry = new ContextMenuEntry();
         string other = selectedItem.GetOtherAsString();
         JObject json = (JObject)JsonConvert.DeserializeObject(other);
         bool isSaved = json["saved"].Value<bool>();
         entry.DisplayText = isSaved ? "Remove from watchlist" : "Add to watchlist";
         entries.Add(entry);
     }
     return entries;
 }
 public override string GetVideoUrl(VideoInfo video)
 {
     string other = video.GetOtherAsString();
     JObject json = (JObject)JsonConvert.DeserializeObject(other);
     bool isSaved = json["saved"].Value<bool>();
     if (isSaved)
         if (!UnsaveVideo(json["guid"].Value<string>()))
             throw new OnlineVideosException("Could not play video. Please try agian");
     if (!SaveVideo(json["guid"].Value<string>()))
         throw new OnlineVideosException("Could not play video. Please try agian");
     return WatchlistUrl + "|" + (!isSaved).ToString();
 }
        public override List<String> GetMultipleVideoUrls(VideoInfo video, bool inPlaylist = false)
        {
            JObject data = GetWebData<JObject>(video.GetOtherAsString());
            video.PlaybackOptions.Clear();
            JArray episodes = (JArray)data["episodes"];
            JToken episode = episodes.FirstOrDefault(e => e["id"].ToString() == video.VideoUrl);
            IEnumerable<JToken> hlsStreams = episode["streams"].Where(s => s["format"].Value<string>().ToLower() == "ipad" && !s["drmProtected"].Value<bool>());
            if (hlsStreams == null || hlsStreams.Count() == 0)
                hlsStreams = episode["streams"].Where(s => s["format"].Value<string>().ToLower() == "iphone" && !s["drmProtected"].Value<bool>());
            if (hlsStreams != null && hlsStreams.Count() > 0)
            {
                try
                {
                    string url = hlsStreams.First()["source"].Value<string>();
                    string m3u8 = GetWebData(url);
                    Regex rgx = new Regex(@"WIDTH=(?<bitrate>\d+)[^c]*(?<url>[^\.]*\.m3u8)");
                    foreach (Match m in rgx.Matches(m3u8))
                    {
                        video.PlaybackOptions.Add(m.Groups["bitrate"].Value.ToString(), Regex.Replace(url, @"([^/]*?.m3u8)", delegate(Match match)
                        {
                            return m.Groups["url"].Value;
                        }));
                    }
                    video.PlaybackOptions = video.PlaybackOptions.OrderByDescending(p => int.Parse(p.Key)).ToDictionary(kvp => ((int.Parse(kvp.Key) /1000) + " kbps (HLS)"), kvp => kvp.Value);
                }
                catch { }
            }
            IEnumerable<JToken> streams = episode["streams"].Where(s => s["format"].Value<string>().ToLower() == "flash" && !s["drmProtected"].Value<bool>());
            string streamBaseUrl = (string)episode["streamBaseUrl"];
            Dictionary<string, string> rtmpD = new Dictionary<string, string>();
            if (streamBaseUrl != null && streams != null && streams.Count() > 0)
            {
                foreach (JToken stream in streams)
                {
                    MPUrlSourceFilter.RtmpUrl url = new MPUrlSourceFilter.RtmpUrl(streamBaseUrl)
                    {
                        SwfUrl = swfPlayer,
                        SwfVerify = true,
                        PlayPath = (string)stream["source"]
                    };
                    rtmpD.Add(((int)stream["bitrate"] / 1000).ToString(), url.ToString());
                }
                rtmpD = rtmpD.OrderByDescending(p => int.Parse(p.Key)).ToDictionary(kvp => (kvp.Key + " kbps (RTMP)"), kvp => kvp.Value);
                video.PlaybackOptions = video.PlaybackOptions.Concat(rtmpD).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                if (retrieveSubtitles && (bool)episode["hasSubtitle"])
                {
                    string subData = GetWebData(string.Format("{0}/subtitles/{1}", apiBaseUrl, episode["id"].ToString()));
                    JArray subtitleJson = (JArray)JsonConvert.DeserializeObject(subData);
                    video.SubtitleText = formatSubtitle(subtitleJson);

                }
            }
            string firsturl = video.PlaybackOptions.First().Value;
            if (inPlaylist)
                video.PlaybackOptions.Clear();
            return new List<string>() { firsturl };
        }