How to remove inactive links

Status
Not open for further replies.
11 comments
Is your site a wordpress based one? Either way, to remove that many links you'll probably best editing the database tables directly with some sort of python script.
 
I'm actually in the process of working this out, but in reverse at the moment (automating adding links to mvoies/tv). It would'nt be too difficult to workout.

I'll see if i can do it at the same time,

If you need to grab the broken link reports from the tables too then I can't help with that at the mo, little bit more a detour from what i'm doing at the minute.
 
If you want to remove every single video source from every single video then that's just a delete statement in the mysql console.

SQL:
DELETE FROM wp_postmeta WHERE meta_key = "repeatable_fields"

This will remove All Video sources from All movies and tv though, not sure if that's what you're after.

If you wanted to remove the Links too ("Download links") then you'd have to use

SQL:
DELETE FROM wp_posts WHERE post_type = "dt_links";
DELETE FROM wp_postmeta WHERE meta_key like "_dool_%";

But i'll say again, removes ALL LINKS and ALL SOURCES.

guess it's good if you wanted to clear out a site where everything is borked.
 
Last edited:
This should be what you want. Dunno if you'd want someone else to look over it but it worked for me on a couple test records.

Python:
import mysql.connector, phpserialize
deadhosts =  ["clipwatching", "aparat", "playtube", "gounlimited"]

con = mysql.connector.connect(
        host='localhost',
        user='wordpress',
        passwd='<YourPass>',
        database='wordpress',
        auth_plugin='mysql_native_password'
)

cur = con.cursor()
sqlupdate = "UPDATE wp_postmeta SET meta_value = %s WHERE meta_id = %s"
sqlfetch = "SELECT meta_id,meta_value from wp_postmeta where meta_key = \'repeatable_fields\' and meta_value REGEXP \'vid|src\'"
cur.execute(sqlfetch)
deadlinks = cur.fetchall()

removedLinks = 0
tested = 0
for dead in list(deadlinks):
    tested += 1
    output = phpserialize.unserialize(dead[1].encode())
    startLen = len(output)
    for src in list(output):
        if any(x in output[src][b'url'].decode() for x in deadhosts):
            removedLinks += 1
            del output[src]
    if len(output) != startLen:
        nuoutput = dict()
        nulinkidx = 0
        for src in output:
            nuoutput[nulinkidx] = output[src]
            nulinkidx += 1
        vals = (phpserialize.serialize(nuoutput).decode(),dead[0])
        cur.execute(sqlupdate,vals)
        con.commit()
        
print(removedLinks," dead links removed")

if you do use this the only output you'll get is the number of removed links/sources.

you'll need to install phpserialize python module

Code:
pip3 install phpserialize

you'll need to change the mysql database settings at the beginning to match that of the server and you'll need to change the table prefix in the 2 queries if you chose a different table prefix when installing.

save the code in a file ending .py and run with command python3 <whatever>.py
Post automatically merged:

you'll need to install mysql-connector too
Code:
 pip3 install mysql-connector
Post automatically merged:

need to make a couple change, if anyone sees it change and repost. can't do it right now
Post automatically merged:

Python:
import mysql.connector, phpserialize

deadhosts =  ["clipwatching", "aparat", "playtube", "gounlimited"]


con = mysql.connector.connect(

        host='localhost',

        user='wordpress',

        passwd='yourpass',

      

        database='wordpress',

        auth_plugin='mysql_native_password'

)


cur = con.cursor()



sqlfetch = "SELECT meta_id,meta_value from wp_postmeta where meta_key = \'repeatable_fields\' and meta_value REGEXP %s"

val = ("|".join(deadhosts),)

cur.execute(sqlfetch,val)

deadlinks = cur.fetchall()


sqldel = "DELETE FROM wp_postmeta WHERE meta_id = %s"

sqlupdate = "UPDATE wp_postmeta SET meta_value = %s WHERE meta_id = %s"


removedLinks = 0

tested = 0

for dead in list(deadlinks):

    tested += 1

    output = phpserialize.unserialize(dead[1].encode())

    startLen = len(output)

    for src in list(output):

        if any(x in output[src][b'url'].decode() for x in deadhosts):

            removedLinks += 1

            del output[src]

    if len(output) < startLen:

        if len(output) != 0:

            nuoutput = dict()

            nulinkidx = 0

            for src in output:

                nuoutput[nulinkidx] = output[src]

                nulinkidx += 1

            vals = (phpserialize.serialize(nuoutput).decode(),dead[0])

            cur.execute(sqlupdate,vals)

            con.commit()

        else:

            val = (dead[0],)

            cur.execute(sqldel,val)

            con.commit()

        

print(removedLinks," dead links removed")
 
Last edited:
Hello to everyone, i want to ask if someone can help me to integrate a system to delete all streamlinks dead by checking daily with a cron job or something like that, example, a system to check urls and if url displays a text like Error 404 or video deleted or something similar automate it to delete that streamlink (not player) dt_links, thanks!
 
Status
Not open for further replies.
Back
Top