Esempio n. 1
0
int MediaPlayers::Check() {
    index = -1;
    bool recognized = CurrentEpisode.anime_id > anime::ID_UNKNOWN;

    // Go through windows, starting with the highest in the Z order
    HWND hwnd = GetWindow(g_hMain, GW_HWNDFIRST);
    while (hwnd != nullptr) {
        for (auto item = items.begin(); item != items.end(); ++item) {
            if (!item->enabled)
                continue;
            if (item->visible && !IsWindowVisible(hwnd))
                continue;
            // Compare window classes
            for (auto c = item->classes.begin(); c != item->classes.end(); ++c) {
                if (*c == GetWindowClass(hwnd)) {
                    // Compare file names
                    for (auto f = item->files.begin(); f != item->files.end(); ++f) {
                        if (IsEqual(*f, GetFileName(GetWindowPath(hwnd)))) {
                            if (item->mode != MEDIA_MODE_WEBBROWSER || !GetWindowTitle(hwnd).empty()) {
                                // Stick with the previously recognized window, if there is one
                                if (!recognized || item->window_handle == hwnd) {
                                    // We have a match!
                                    index = index_old = item - items.begin();
                                    new_title = GetTitle(hwnd, *c, item->mode);
                                    EditTitle(new_title, index);
                                    if (current_title != new_title) title_changed_ = true;
                                    current_title = new_title;
                                    item->window_handle = hwnd;
                                    return index;
                                }
                            }
                        }
                    }
                }
            }
        }
        // Check next window
        hwnd = GetWindow(hwnd, GW_HWNDNEXT);
    }

    // Not found
    return -1;
}
Esempio n. 2
0
wstring MediaPlayers::GetTitleFromBrowser(HWND hwnd) {
    int stream_provider = STREAM_UNKNOWN;
    int web_engine = WEBENGINE_UNKNOWN;

    // Get window title
    wstring title = GetWindowTitle(hwnd);
    EditTitle(title, index);

    // Return current title if the same web page is still open
    if (CurrentEpisode.anime_id > 0)
        if (InStr(title, current_title) > -1)
            return current_title;

    // Delay operation to save some CPU
    static int counter = 0;
    if (counter < 5) {
        counter++;
        return current_title;
    } else {
        counter = 0;
    }

    // Select web browser engine
    if (items.at(index).engine == L"WebKit") {
        web_engine = WEBENGINE_WEBKIT;
    } else if (items.at(index).engine == L"Gecko") {
        web_engine = WEBENGINE_GECKO;
    } else if (items.at(index).engine == L"Trident") {
        web_engine = WEBENGINE_TRIDENT;
    } else if (items.at(index).engine == L"Presto") {
        web_engine = WEBENGINE_PRESTO;
    } else {
        return L"";
    }

    // Build accessibility data
    acc_obj.children.clear();
    if (acc_obj.FromWindow(hwnd) == S_OK) {
        acc_obj.BuildChildren(acc_obj.children, nullptr, web_engine);
        acc_obj.Release();
    }

    // Check other tabs
    if (CurrentEpisode.anime_id > 0) {
        AccessibleChild* child = nullptr;
        switch (web_engine) {
        case WEBENGINE_WEBKIT:
        case WEBENGINE_GECKO:
            child = FindAccessibleChild(acc_obj.children, L"", L"page tab list");
            break;
        case WEBENGINE_TRIDENT:
            child = FindAccessibleChild(acc_obj.children, L"Tab Row", L"");
            break;
        case WEBENGINE_PRESTO:
            child = FindAccessibleChild(acc_obj.children, L"", L"client");
            break;
        }
        if (child) {
            for (auto it = child->children.begin(); it != child->children.end(); ++it) {
                if (InStr(it->name, current_title) > -1) {
                    // Tab is still open, just not active
                    return current_title;
                }
            }
        }
        // Tab is closed
        return L"";
    }

    // Find URL
    AccessibleChild* child = nullptr;
    switch (web_engine) {
    case WEBENGINE_WEBKIT:
        child = FindAccessibleChild(acc_obj.children, L"Address and search bar", L"grouping");
        if (child == nullptr)
            child = FindAccessibleChild(acc_obj.children, L"Address", L"grouping");
        if (child == nullptr)
            child = FindAccessibleChild(acc_obj.children, L"Location", L"grouping");
        if (child == nullptr)
            child = FindAccessibleChild(acc_obj.children, L"Address field", L"editable text");
        break;
    case WEBENGINE_GECKO:
        child = FindAccessibleChild(acc_obj.children, L"Search or enter address", L"editable text");
        if (child == nullptr)
            child = FindAccessibleChild(acc_obj.children, L"Go to a Website", L"editable text");
        if (child == nullptr)
            child = FindAccessibleChild(acc_obj.children, L"Go to a Web Site", L"editable text");
        break;
    case WEBENGINE_TRIDENT:
        child = FindAccessibleChild(acc_obj.children, L"Address and search using Bing", L"editable text");
        if (child == nullptr)
            child = FindAccessibleChild(acc_obj.children, L"Address and search using Google", L"editable text");
        break;
    case WEBENGINE_PRESTO:
        child = FindAccessibleChild(acc_obj.children, L"", L"client");
        if (child && !child->children.empty()) {
            child = FindAccessibleChild(child->children.at(0).children, L"", L"tool bar");
            if (child && !child->children.empty()) {
                child = FindAccessibleChild(child->children, L"", L"combo box");
                if (child && !child->children.empty()) {
                    child = FindAccessibleChild(child->children, L"", L"editable text");
                }
            }
        }
        break;
    }

    // Check URL for known streaming video providers
    if (child) {
        // Anime News Network
        if (Settings.Recognition.Streaming.ann_enabled &&
                InStr(child->value, L"animenewsnetwork.com/video") > -1) {
            stream_provider = STREAM_ANN;
            // Crunchyroll
        } else if (Settings.Recognition.Streaming.crunchyroll_enabled &&
                   InStr(child->value, L"crunchyroll.com/") > -1) {
            stream_provider = STREAM_CRUNCHYROLL;
            // Hulu
            /*
            } else if (InStr(child->value, L"hulu.com/watch") > -1) {
              stream_provider = STREAM_HULU;
            */
            // Veoh
        } else if (Settings.Recognition.Streaming.veoh_enabled &&
                   InStr(child->value, L"veoh.com/watch") > -1) {
            stream_provider = STREAM_VEOH;
            // Viz Anime
        } else if (Settings.Recognition.Streaming.viz_enabled &&
                   InStr(child->value, L"vizanime.com/ep") > -1) {
            stream_provider = STREAM_VIZANIME;
            // YouTube
        } else if (Settings.Recognition.Streaming.youtube_enabled &&
                   InStr(child->value, L"youtube.com/watch") > -1) {
            stream_provider = STREAM_YOUTUBE;
        }
    }

    // Clean-up title
    switch (stream_provider) {
    // Anime News Network
    case STREAM_ANN:
        EraseRight(title, L" - Anime News Network");
        Erase(title, L" (s)");
        Erase(title, L" (d)");
        break;
    // Crunchyroll
    case STREAM_CRUNCHYROLL:
        EraseLeft(title, L"Crunchyroll - Watch ");
        break;
    // Hulu
    case STREAM_HULU:
        EraseLeft(title, L"Watch ");
        EraseRight(title, L" online | Free | Hulu");
        EraseRight(title, L" online | Plus | Hulu");
        break;
    // Veoh
    case STREAM_VEOH:
        EraseLeft(title, L"Watch Videos Online | ");
        EraseRight(title, L" | Veoh.com");
        break;
    // Viz Anime
    case STREAM_VIZANIME:
        EraseRight(title, L" - VIZ ANIME: Free Online Anime - All The Time");
        break;
    // YouTube
    case STREAM_YOUTUBE:
        EraseRight(title, L" - YouTube");
        break;
    // Some other website, or URL is not found
    case STREAM_UNKNOWN:
        title.clear();
        break;
    }

    return title;
}
Esempio n. 3
0
QString MenuCommands::Get(int ind, What w) const
{
    int cur = 0;

    if (cur++ == ind)
        return (w == Key ? FileKey() : (w == Title? FileTitle() : ""));

    if (cur++ == ind)
        return (w == Key ? NewWinKey() : (w == Title? NewWinTitle() : GetStr(NewWinShortcuts())));

    if (cur++ == ind)
        return (w == Key ? OpenFileKey() : (w == Title? OpenFileTitle() : GetStr(OpenFileShortcuts())));

    if (cur++ == ind)
        return (w == Key ? OpenLocKey() : (w == Title? OpenLocTitle() : GetStr(OpenLocShortcuts())));

    if (cur++ == ind)
        return (w == Key ? SaveAsKey() : (w == Title? SaveAsTitle() : GetStr(SaveAsShortcuts())));

    if (cur++ == ind)
        return (w == Key ? SavePdfKey() : (w == Title? SavePdfTitle() : GetStr(SavePdfShortcuts())));

    if (cur++ == ind)
        return (w == Key ? ImportKey() : (w == Title? ImportTitle() : ""));

    if (cur++ == ind)
        return (w == Key ? ImportIEKey() : (w == Title? ImportIETitle() : GetStr(ImportIEShortcuts())));

    if (cur++ == ind)
        return (w == Key ? ImportFFKey() : (w == Title? ImportFFTitle() : GetStr(ImportFFShortcuts())));

    if (cur++ == ind)
        return (w == Key ? ImportHtmlKey() : (w == Title? ImportHtmlTitle() : GetStr(ImportHtmlShortcuts())));

    if (cur++ == ind)
        return (w == Key ? ImportXmlKey() : (w == Title? ImportXmlTitle() : GetStr(ImportXmlShortcuts())));

    if (cur++ == ind)
        return (w == Key ? ExportKey() : (w == Title? ExportTitle() : GetStr(ExportShortcuts())));

    if (cur++ == ind)
        return (w == Key ? PrintKey() : (w == Title? PrintTitle() : GetStr(PrintShortcuts())));

    if (cur++ == ind)
        return (w == Key ? PreviewKey() : (w == Title? PreviewTitle() : GetStr(PreviewShortcuts())));

    if (cur++ == ind)
        return (w == Key ? QuitKey() : (w == Title? QuitTitle() : GetStr(QuitShortcuts())));

    if (cur++ == ind)
        return (w == Key ? EditKey() : (w == Title? EditTitle() : ""));

    if (cur++ == ind)
        return (w == Key ? UndoKey() : (w == Title? UndoTitle() : GetStr(UndoShortcuts())));

    if (cur++ == ind)
        return (w == Key ? RedoKey() : (w == Title? RedoTitle() : GetStr(RedoShortcuts())));

    if (cur++ == ind)
        return (w == Key ? CutKey() : (w == Title? CutTitle() : GetStr(CutShortcuts())));

    if (cur++ == ind)
        return (w == Key ? CopyKey() : (w == Title? CopyTitle() : GetStr(CopyShortcuts())));

    if (cur++ == ind)
        return (w == Key ? PasteKey() : (w == Title? PasteTitle() : GetStr(PasteShortcuts())));

    if (cur++ == ind)
        return (w == Key ? FindKey() : (w == Title? FindTitle() : GetStr(FindShortcuts())));

    if (cur++ == ind)
        return (w == Key ? NextKey() : (w == Title? NextTitle() : GetStr(NextShortcuts())));

    if (cur++ == ind)
        return (w == Key ? PrevKey() : (w == Title? PrevTitle() : GetStr(PrevShortcuts())));

    if (cur++ == ind)
        return (w == Key ? PrefsKey() : (w == Title? PrefsTitle() : GetStr(PrefsShortcuts())));

    if (cur++ == ind)
        return (w == Key ? ViewKey() : (w == Title? ViewTitle() : ""));

    if (cur++ == ind)
        return (w == Key ? AppStylesKey() : (w == Title? AppStylesTitle() : ""));

    if (cur++ == ind)
        return (w == Key ? StatusKey() : (w == Title? StatusTitle() : GetStr(StatusShortcuts())));

    if (cur++ == ind)
        return (w == Key ? MenuKey() : (w == Title? MenuTitle() : GetStr(MenuShortcuts())));

    if (cur++ == ind)
        return (w == Key ? TabKey() : (w == Title? TabTitle() : GetStr(TabShortcuts())));

    if (cur++ == ind)
        return (w == Key ? NavKey() : (w == Title? NavTitle() : GetStr(NavShortcuts())));

    if (cur++ == ind)
        return (w == Key ? BooksKey() : (w == Title? BooksTitle() : GetStr(BooksShortcuts())));

//  if (cur++ == ind)
//      return (w == Key ? Key() : (w == Title? Title() : GetStr(Shortcuts())));

    if (cur++ == ind)
        return (w == Key ? StopKey() : (w == Title? StopTitle() : GetStr(StopShortcuts())));

    if (cur++ == ind)
        return (w == Key ? ReloadKey() : (w == Title? ReloadTitle() : GetStr(ReloadShortcuts())));

    if (cur++ == ind)
        return (w == Key ? LargerKey() : (w == Title? LargerTitle() : GetStr(LargerShortcuts())));

    if (cur++ == ind)
        return (w == Key ? NormalKey() : (w == Title? NormalTitle() : GetStr(NormalShortcuts())));

    if (cur++ == ind)
        return (w == Key ? SmallerKey() : (w == Title? SmallerTitle() : GetStr(SmallerShortcuts())));

    if (cur++ == ind)
        return (w == Key ? TextOnlyKey() : (w == Title? TextOnlyTitle() : GetStr(TextOnlyShortcuts())));

    if (cur++ == ind)
        return (w == Key ? EncodeKey() : (w == Title? EncodeTitle() : ""));

    if (cur++ == ind)
        return (w == Key ? SourceKey() : (w == Title? SourceTitle() : GetStr(SourceShortcuts())));

    if (cur++ == ind)
        return (w == Key ? FullKey() : (w == Title? FullTitle() : GetStr(FullShortcuts())));

    if (cur++ == ind)
        return (w == Key ? HistoryKey() : (w == Title? HistoryTitle() : ""));

    if (cur++ == ind)
        return (w == Key ? BackKey() : (w == Title? BackTitle() : GetStr(BackShortcuts())));

    if (cur++ == ind)
        return (w == Key ? ForwKey() : (w == Title? ForwTitle() : GetStr(ForwShortcuts())));

    if (cur++ == ind)
        return (w == Key ? HomeKey() : (w == Title? HomeTitle() : GetStr(HomeShortcuts())));

    if (cur++ == ind)
        return (w == Key ? LastTabKey() : (w == Title? LastTabTitle() : GetStr(LastTabShortcuts())));

    if (cur++ == ind)
        return (w == Key ? LastTabsKey() : (w == Title? LastTabsTitle() : GetStr(LastTabsShortcuts())));

    if (cur++ == ind)
        return (w == Key ? SessionKey() : (w == Title? SessionTitle() : GetStr(SessionShortcuts())));

    if (cur++ == ind)
        return (w == Key ? AllHistKey() : (w == Title? AllHistTitle() : GetStr(AllHistShortcuts())));

    if (cur++ == ind)
        return (w == Key ? ClearKey() : (w == Title? ClearTitle() : GetStr(ClearShortcuts())));

    if (cur++ == ind)
        return (w == Key ? BookmarksKey() : (w == Title? BookmarksTitle() : ""));

    if (cur++ == ind)
        return (w == Key ? AllBooksKey() : (w == Title? AllBooksTitle() : GetStr(AllBooksShortcuts())));

    if (cur++ == ind)
        return (w == Key ? AddBookKey() : (w == Title? AddBookTitle() : GetStr(AddBookShortcuts())));
    
    if (cur++ == ind)
        return (w == Key ? PrivacyKey() : (w == Title? PrivacyTitle() : ""));
    
    if (cur++ == ind)
        return (w == Key ? PrivateKey() : (w == Title? PrivateTitle() : GetStr(PrivateShortcuts())));
    
    if (cur++ == ind)
        return (w == Key ? JavaScriptKey() : (w == Title? JavaScriptTitle() : GetStr(JavaScriptShortcuts())));
    
    if (cur++ == ind)
        return (w == Key ? ImagesKey() : (w == Title? ImagesTitle() : GetStr(ImagesShortcuts())));
    
    if (cur++ == ind)
        return (w == Key ? CookiesKey() : (w == Title? CookiesTitle() : GetStr(CookiesShortcuts())));
    
    if (cur++ == ind)
        return (w == Key ? PlugInsKey() : (w == Title? PlugInsTitle() : GetStr(PlugInsShortcuts())));
    
    if (cur++ == ind)
        return (w == Key ? AgentKey() : (w == Title? AgentTitle() : GetStr(AgentShortcuts())));
    
    if (cur++ == ind)
        return (w == Key ? PopUpsKey() : (w == Title? PopUpsTitle() : GetStr(PopUpsShortcuts())));

    if (cur++ == ind)
        return (w == Key ? ProxyKey() : (w == Title? ProxyTitle() : GetStr(ProxyShortcuts())));

    if (cur++ == ind)
        return (w == Key ? EmptyKey() : (w == Title? EmptyTitle() : GetStr(EmptyShortcuts())));

    if (cur++ == ind)
        return (w == Key ? ResetKey() : (w == Title? ResetTitle() : GetStr(ResetShortcuts())));

    if (cur++ == ind)
        return (w == Key ? FullResetKey() : (w == Title? FullResetTitle() : GetStr(FullResetShortcuts())));

    if (cur++ == ind)
        return (w == Key ? ToolsKey() : (w == Title? ToolsTitle() : ""));

    if (cur++ == ind)
        return (w == Key ? CompatKey() : (w == Title? CompatTitle() : ""));

    if (cur++ == ind)
        return (w == Key ? SearchKey() : (w == Title? SearchTitle() : GetStr(SearchShortcuts())));

    if (cur++ == ind)
        return (w == Key ? KeyboardKey() : (w == Title? KeyboardTitle() : GetStr(KeyboardShortcuts())));

    if (cur++ == ind)
        return (w == Key ? InspectorKey() : (w == Title? InspectorTitle() : GetStr(InspectorShortcuts())));

    if (cur++ == ind)
        return (w == Key ? InspectKey() : (w == Title? InspectTitle() : GetStr(InspectShortcuts())));

    if (cur++ == ind)
        return (w == Key ? OptionsKey() : (w == Title? OptionsTitle() : GetStr(OptionsShortcuts())));

    if (cur++ == ind)
        return (w == Key ? WindowKey() : (w == Title? WindowTitle() : ""));

    if (cur++ == ind)
        return (w == Key ? NextTabKey() : (w == Title? NextTabTitle() : GetStr(NextTabShortcuts())));

    if (cur++ == ind)
        return (w == Key ? PrevTabKey() : (w == Title? PrevTabTitle() : GetStr(PrevTabShortcuts())));

    if (cur++ == ind)
        return (w == Key ? NewTabKey() : (w == Title? NewTabTitle() : GetStr(NewTabShortcuts())));

    if (cur++ == ind)
        return (w == Key ? CloseTabKey() : (w == Title? CloseTabTitle() : GetStr(CloseTabShortcuts())));

    if (cur++ == ind)
        return (w == Key ? CloseOtherKey() : (w == Title? CloseOtherTitle() : GetStr(CloseOtherShortcuts())));

    if (cur++ == ind)
        return (w == Key ? CloneTabKey() : (w == Title? CloneTabTitle() : GetStr(CloneTabShortcuts())));

    if (cur++ == ind)
        return (w == Key ? ReloadTabKey() : (w == Title? ReloadTabTitle() : GetStr(ReloadTabShortcuts())));

    if (cur++ == ind)
        return (w == Key ? ReloadAllKey() : (w == Title? ReloadAllTitle() : GetStr(ReloadAllShortcuts())));

    if (cur++ == ind)
        return (w == Key ? OpenNewTabKey() : (w == Title? OpenNewTabTitle() : GetStr(OpenNewTabShortcuts())));

    if (cur++ == ind)
        return (w == Key ? OpenAdBlockKey() : (w == Title? OpenAdBlockTitle() : GetStr(OpenAdBlockShortcuts())));

    if (cur++ == ind)
        return (w == Key ? SwapFocusKey() : (w == Title? SwapFocusTitle() : GetStr(SwapFocusShortcuts())));

    if (cur++ == ind)
        return (w == Key ? CopyAddrKey() : (w == Title? CopyAddrTitle() : ""));

    if (cur++ == ind)
        return (w == Key ? DownsKey() : (w == Title? DownsTitle() : GetStr(DownsShortcuts())));

    if (cur++ == ind)
        return (w == Key ? TorrentsKey() : (w == Title? TorrentsTitle() : GetStr(TorrentsShortcuts())));

    if (cur++ == ind)
        return (w == Key ? HelpKey() : (w == Title? HelpTitle() : GetStr(HelpShortcuts())));

    if (cur++ == ind)
        return (w == Key ? OnlineKey() : (w == Title? OnlineTitle() : GetStr(OnlineShortcuts())));

    if (cur++ == ind)
        return (w == Key ? UpdatesKey() : (w == Title? UpdatesTitle() : GetStr(UpdatesShortcuts())));

    if (cur++ == ind)
        return (w == Key ? AboutKey() : (w == Title? AboutTitle() : GetStr(AboutShortcuts())));

    return "";
}