sim0n00ps / OF-DL

C# console app to download all of the media from Onlyfans accounts with DRM video downloading support
562 stars 54 forks source link

Exception when downloading DRM content #363

Closed aetnaeus closed 1 month ago

aetnaeus commented 1 month ago

I get this same exception every time i try to download a DRM protected post/content.

`Exception caught: Response status code does not indicate success: 405 (METHOD NOT ALLOWED).

StackTrace:    at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at OF_DL.Helpers.APIHelper.GetDecryptionKey(Dictionary 2 drmHeaders, String licenceURL, String pssh, Auth auth)
Exception caught: Object reference not set to an instance of an object.

StackTrace:    at OF_DL.Helpers.DownloadHelper.DownloadDrmMedia(String user_agent, String policy, String signature, String kvp, String sess, String url, String decryptionKey, String folder, DateTime lastModified, Int64 media_id, ProgressTask task, String customFileName, String filename, String path, Boolean showScrapeSize, Config config)
user_agent, String policy, String signature, String kvp, String sess, String url, String decryptionKey, String folder, DateTim
nameFormat, SinglePost postInfo, Medium postMedia, Author author, Dictionary 2 users, Config config, Boolean showScrapeSize)`
melithine commented 1 month ago

Are you using CDRM or your own Wildvine keys?

sketchone commented 1 month ago

im having the same problem and im using the cdrm

BouncyB0uncy commented 1 month ago

Same issue here, i don't know if it is related but chrome started blocking the Cookies yesterday. So they probs have clued onto how to block the downloader. Chrome Notification below

Reading cookie in cross-site context will be blocked in future Chrome versions Cookies with the SameSite=None; Secure and not Partitioned attributes that operate in cross-site contexts are third-party cookies. In future Chrome versions, reading third-party cookies will be blocked. This behavior protects user data from cross-site tracking. Please refer to the article linked to learn more about preparing your site to avoid potential breakage.

melithine commented 1 month ago

I don't think that's related at all. Try the browser extension for auth.json. and try to get your own keys if you're using CDRM.

sim0n00ps commented 1 month ago

cdrm-project has changed the site so I need to adjust the code to work with the new site which I will do later today

kibitzz commented 1 month ago

already fixed problem with cdrm-project, here modified function, already tested;)

public async Task<string> GetDecryptionKey(Dictionary<string, string> drmHeaders, string licenceURL, string pssh, Auth auth)
    {
        try
        {
            string dcValue = string.Empty;        

            StringBuilder sb = new();
            sb.Append("{\n");
            sb.AppendFormat("  \"License URL\": \"{0}\",\n", licenceURL);         
            sb.Append("  \"Headers\": \"{");
            foreach (KeyValuePair<string, string> header in drmHeaders)
            {
                if (header.Key == "time" || header.Key == "user-id")
                {
                    sb.AppendFormat("\\\"{0}\\\": \\\"{1}\\\",", header.Key, header.Value);
                }
                else
                {
                    sb.AppendFormat("\\\"{0}\\\": \\\"{1}\\\",", header.Key, header.Value);
                }
            }
            sb.Remove(sb.Length - 1, 1);
            sb.Append("}\",\n");
            sb.AppendFormat("  \"PSSH\": \"{0}\"\n", pssh);
            sb.Append(",\"JSON\":\"\",\"Cookies\":\"\",\"Data\":\"\"");        
            sb.Append('}');
            string json = sb.ToString();
            HttpClient client = new();

            HttpRequestMessage request = new(HttpMethod.Post, "https://cdrm-project.com/")
            {              
                Content = new StringContent(json, Encoding.UTF8, "application/json")                                           
            };          

            using var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            var body = await response.Content.ReadAsStringAsync();

            var doc = JsonDocument.Parse(body);

            dcValue = doc.RootElement.GetProperty("Message").GetString().Trim();           

            return dcValue;
        }
        catch (Exception ex)
        {
            Console.WriteLine("Exception caught: {0}\n\nStackTrace: {1}", ex.Message, ex.StackTrace);
            Log.Error("Exception caught: {0}\n\nStackTrace: {1}", ex.Message, ex.StackTrace);
            if (ex.InnerException != null)
            {
                Console.WriteLine("\nInner Exception:");
                Console.WriteLine("Exception caught: {0}\n\nStackTrace: {1}", ex.InnerException.Message, ex.InnerException.StackTrace);
                Log.Error("Inner Exception: {0}\n\nStackTrace: {1}", ex.InnerException.Message, ex.InnerException.StackTrace);
            }
        }
        return null;
    }
sketchone commented 1 month ago

ok i dont know how to add this code, is it in the updated file of something ?

kibitzz commented 1 month ago

ok i dont know how to add this code, is it in the updated file of something ?

file \OF-DL-master\OF DL\Helpers\APIHelper.cs find function GetDecryptionKey and replace it with modified one i posted previously

happyjo1 commented 1 month ago

ok i dont know how to add this code, is it in the updated file of something ?

file \OF-DL-master\OF DL\Helpers\APIHelper.cs find function GetDecryptionKey and replace it with modified one i posted previously

Seems like this only works if run with docker, but not the .exe? any idea to solve this for .exe runs?

kibitzz commented 1 month ago

ok i dont know how to add this code, is it in the updated file of something ?

file \OF-DL-master\OF DL\Helpers\APIHelper.cs find function GetDecryptionKey and replace it with modified one i posted previously

Seems like this only works if run with docker, but not the .exe? any idea to solve this for .exe runs?

windows search -> type "PowerShell" -> in results you should see app "Windows PowerShell" -> open context menu on this app and choose "Run as administrator"

in PowerShell paste a command dotnet build "[path on your machine to source code]\OF-DL-master\OF DL.sln"

newly compiled OF DL.exe appear in OF-DL-master\OF DL\bin\ subfolder Debug or Release

jamesltyler9 commented 1 month ago

ok i dont know how to add this code, is it in the updated file of something ?

file \OF-DL-master\OF DL\Helpers\APIHelper.cs find function GetDecryptionKey and replace it with modified one i posted previously

Seems like this only works if run with docker, but not the .exe? any idea to solve this for .exe runs?

windows search -> type "PowerShell" -> in results you should see app "Windows PowerShell" -> open context menu on this app and choose "Run as administrator"

in PowerShell paste a command dotnet build "[path on your machine to source code]\OF-DL-master\OF DL.sln"

newly compiled OF DL.exe appear in OF-DL-master\OF DL\bin\ subfolder Debug or Release

How would you find the path to source code?

kibitzz commented 1 month ago

:) download this project as zip file and unpack it - directory with unpacked files will be [path on your machine to source code]

jamesltyler9 commented 1 month ago

:) download this project as zip file and unpack it - directory with unpacked files will be [path on your machine to source code]

When building I get this error

\OF-DL-OFDLV1.7.56\OF DL\Helpers\APIHelper.cs(25,26): error CS0738: 'APIHelper' does not implement interface member 'IAPIHelper.GetDecryptionKey(Dictionary<string, string>, string, string, Auth)'. 'APIHelper.GetDecryptionKey(Dictionary<string, string>, string, string, Auth)' cannot implement 'IAPIHelper.GetDecryptionKey(Dictionary<string, string>, string, string, Auth)' beca use it does not have the matching return type of 'Task'

kibitzz commented 1 month ago

:) download this project as zip file and unpack it - directory with unpacked files will be [path on your machine to source code]

When building I get this error

\OF-DL-OFDLV1.7.56\OF DL\Helpers\APIHelper.cs(25,26): error CS0738: 'APIHelper' does not implement interface member 'IAPIHelper.GetDecryptionKey(Dictionary<string, string>, string, string, Auth)'. 'APIHelper.GetDecryptionKey(Dictionary<string, string>, string, string, Auth)' cannot implement 'IAPIHelper.GetDecryptionKey(Dictionary<string, string>, string, string, Auth)' beca use it does not have the matching return type of 'Task'

probably you edited file APIHelper.cs but copied only the part of function, i updated comment - now it's markup is correct, replace function code in original APIHelper.cs again

CokeBear2 commented 1 month ago

ok i dont know how to add this code, is it in the updated file of something ?

file \OF-DL-master\OF DL\Helpers\APIHelper.cs find function GetDecryptionKey and replace it with modified one i posted previously

Seems like this only works if run with docker, but not the .exe? any idea to solve this for .exe runs?

windows search -> type "PowerShell" -> in results you should see app "Windows PowerShell" -> open context menu on this app and choose "Run as administrator"

in PowerShell paste a command dotnet build "[path on your machine to source code]\OF-DL-master\OF DL.sln"

newly compiled OF DL.exe appear in OF-DL-master\OF DL\bin\ subfolder Debug or Release

When building I get this error

path on your machine to source code\OF DL\Helpers\APIHelper.cs(2384,23): error CS0103: The name 'JsonDocument' does not exist in the current context. [path on your machine to source code\OF-DL-master\OF DL\OF DL.csproj] 803 warnings 1 error

divakar123 commented 1 month ago

ok i dont know how to add this code, is it in the updated file of something ?

file \OF-DL-master\OF DL\Helpers\APIHelper.cs find function GetDecryptionKey and replace it with modified one i posted previously

Seems like this only works if run with docker, but not the .exe? any idea to solve this for .exe runs?

windows search -> type "PowerShell" -> in results you should see app "Windows PowerShell" -> open context menu on this app and choose "Run as administrator" in PowerShell paste a command dotnet build "[path on your machine to source code]\OF-DL-master\OF DL.sln" newly compiled OF DL.exe appear in OF-DL-master\OF DL\bin\ subfolder Debug or Release

When building I get this error

path on your machine to source code\OF DL\Helpers\APIHelper.cs(2384,23): error CS0103: The name 'JsonDocument' does not exist in the current context. [path on your machine to source code\OF-DL-master\OF DL\OF DL.csproj] 803 warnings 1 error

same

letepl commented 1 month ago

I could build it adding System.Text.Json. to the line with the name JsonDocument:

    var doc = System.Text.Json.JsonDocument.Parse(body);

But I still get an error when it tries to download a DRM video:

Exception caught: Response status code does not indicate success: 500 (INTERNAL SERVER ERROR). StackTrace: at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()

kibitzz commented 1 month ago

sorry, code that use JsonDocument will not build without using System.Text.Json;

today something changed again on "https://cdrm-project.com/ i also geting 500 (INTERNAL SERVER ERROR). working on it

kibitzz commented 1 month ago

function that work today)

add on top of the file APIHelper.cs using System.Text.Json;

and replace function GetDecryptionKey

public async Task<string> GetDecryptionKey(Dictionary<string, string> drmHeaders, string licenceURL, string pssh, Auth auth)
    {
        try
        {
            string dcValue = string.Empty;

            StringBuilder sb = new();
            sb.Append("{\n");
            sb.AppendFormat("  \"License URL\": \"{0}\",\n", licenceURL);
            sb.Append("  \"Headers\": \"{");
            foreach (KeyValuePair<string, string> header in drmHeaders)
            {
                if (header.Key == "time" || header.Key == "user-id")
                {
                    sb.AppendFormat("\\\"{0}\\\": \\\"{1}\\\",", header.Key, header.Value);
                }
                else
                {
                    sb.AppendFormat("\\\"{0}\\\": \\\"{1}\\\",", header.Key, header.Value);
                }
            }
            sb.Remove(sb.Length - 1, 1);
            sb.Append("}\",\n");
            sb.AppendFormat("  \"PSSH\": \"{0}\"\n", pssh);
            sb.Append(",\"JSON\":\"\",\"Cookies\":\"\",\"Data\":\"\",\"Proxy\":\"\"");
            sb.Append('}');
            string json = sb.ToString();
            HttpClient client = new();

            HttpRequestMessage request = new(HttpMethod.Post, "https://cdrm-project.com/")
            {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            };

            using var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            var body = await response.Content.ReadAsStringAsync();

            var doc = JsonDocument.Parse(body);

            dcValue = doc.RootElement.GetProperty("Message").GetString().Trim();

            return dcValue;
        }
        catch (Exception ex)
        {
            Console.WriteLine("Exception caught: {0}\n\nStackTrace: {1}", ex.Message, ex.StackTrace);
            Log.Error("Exception caught: {0}\n\nStackTrace: {1}", ex.Message, ex.StackTrace);
            if (ex.InnerException != null)
            {
                Console.WriteLine("\nInner Exception:");
                Console.WriteLine("Exception caught: {0}\n\nStackTrace: {1}", ex.InnerException.Message, ex.InnerException.StackTrace);
                Log.Error("Inner Exception: {0}\n\nStackTrace: {1}", ex.InnerException.Message, ex.InnerException.StackTrace);
            }
        }
        return null;
    }

you can simply use exe that i build now OF DL.zip

divakar123 commented 1 month ago

function that work today)

add on top of the file APIHelper.cs using System.Text.Json;

and replace function GetDecryptionKey

public async Task<string> GetDecryptionKey(Dictionary<string, string> drmHeaders, string licenceURL, string pssh, Auth auth)
    {
        try
        {
            string dcValue = string.Empty;

            StringBuilder sb = new();
            sb.Append("{\n");
            sb.AppendFormat("  \"License URL\": \"{0}\",\n", licenceURL);
            sb.Append("  \"Headers\": \"{");
            foreach (KeyValuePair<string, string> header in drmHeaders)
            {
                if (header.Key == "time" || header.Key == "user-id")
                {
                    sb.AppendFormat("\\\"{0}\\\": \\\"{1}\\\",", header.Key, header.Value);
                }
                else
                {
                    sb.AppendFormat("\\\"{0}\\\": \\\"{1}\\\",", header.Key, header.Value);
                }
            }
            sb.Remove(sb.Length - 1, 1);
            sb.Append("}\",\n");
            sb.AppendFormat("  \"PSSH\": \"{0}\"\n", pssh);
            sb.Append(",\"JSON\":\"\",\"Cookies\":\"\",\"Data\":\"\",\"Proxy\":\"\"");
            sb.Append('}');
            string json = sb.ToString();
            HttpClient client = new();

            HttpRequestMessage request = new(HttpMethod.Post, "https://cdrm-project.com/")
            {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            };

            using var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();
            var body = await response.Content.ReadAsStringAsync();

            var doc = JsonDocument.Parse(body);

            dcValue = doc.RootElement.GetProperty("Message").GetString().Trim();

            return dcValue;
        }
        catch (Exception ex)
        {
            Console.WriteLine("Exception caught: {0}\n\nStackTrace: {1}", ex.Message, ex.StackTrace);
            Log.Error("Exception caught: {0}\n\nStackTrace: {1}", ex.Message, ex.StackTrace);
            if (ex.InnerException != null)
            {
                Console.WriteLine("\nInner Exception:");
                Console.WriteLine("Exception caught: {0}\n\nStackTrace: {1}", ex.InnerException.Message, ex.InnerException.StackTrace);
                Log.Error("Inner Exception: {0}\n\nStackTrace: {1}", ex.InnerException.Message, ex.InnerException.StackTrace);
            }
        }
        return null;
    }

you can simply use exe that i build now OF DL.zip

Where to put this exe file?

kibitzz commented 1 month ago

also added some tweaks for myself:

if you consider this features useful please let me know - i'll create pr for this

OF DL.zip can be used to fix already installed app, or you can get official release and replace 'OF DL.exe'

Ollem123 commented 1 month ago

also added some tweaks for myself:

  • filter for Posts, you can download only those you added to bookmarks. for this add parameter to config.json "DownloadOnlyAddedToBookmarks": true,
  • download only short videos (like tiktoks) for example Asian_sexdoll have awesome short videos, but not so awesome long. for this add parameter to config.json "DownloadOnlyVideosShorterThan": 100,

if you consider this features useful please let me know - i'll create pr for this

OF DL.zip can be used to fix already installed app, or you can get official release and replace 'OF DL.exe'

I cannot run exe when using one i compiled or one from your zip, it doesnt open

kibitzz commented 1 month ago

build finished successfully? what error you get when open my exe?

CashulCwasha commented 1 month ago

If it's the same as me - nothing. I acquired the newest version and replaced the exe with yours. No error, no window popup, nada - nothing happens.

Ollem123 commented 1 month ago

yes nothing happens, when i use the compiled exe or you exe.

Ollem123 commented 1 month ago

the compiled exe is only 156 KB, the original exe is 67 000KB

kibitzz commented 1 month ago

you can see why app fail here eventvwr.exe (windows) i tried to reproduce your case and found log event

Description: A .NET application failed. Application: OF DL.exe Path: C:\Users\38050\Downloads\OF.DL.V1.7.56\OF DL.exe Message: The application to execute does not exist: 'C:\Users\38050\Downloads\OF.DL.V1.7.56\OF DL.dll'.

now I see - published app is just one big exe file 65 mb without dll files when you build locally you get small 'OF DL.exe' and bunch of dll so you need to put all those files to your working directory

Screenshot 2024-05-29 224517

Ollem123 commented 1 month ago

still dont work

kibitzz commented 1 month ago

have you tried to run app from build directory?

Ollem123 commented 1 month ago

yes, also doesnt open

kibitzz commented 1 month ago

send screen of your build directory

kibitzz commented 1 month ago

run eventvwr.exe from cmd to view log find last error event after you try to run app (windows logs -> application) looks like this https://cdn.mos.cms.futurecdn.net/YzCNiF9cxQEbHRCsExioW8-1200-80.jpg

Ollem123 commented 1 month ago

ah ty, it works now. I did not have .net7, only .net8. I installed 7 and now its ok.

CashulCwasha commented 1 month ago

Aye, cheers kibitzz. Followed your instructions to create my own exe file, slapped it with the rest of the build files, and now everything is groovy.